From 80bf28662e35d2c0d16706b050d28616c7db42d2 Mon Sep 17 00:00:00 2001 From: danielailie Date: Thu, 12 Oct 2023 13:18:11 +0300 Subject: [PATCH] Add tests --- .../tests/marketplaces.service.spec.ts | 29 ++++++++++++++----- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/src/modules/marketplaces/tests/marketplaces.service.spec.ts b/src/modules/marketplaces/tests/marketplaces.service.spec.ts index 9469219e4..088ad4f8d 100644 --- a/src/modules/marketplaces/tests/marketplaces.service.spec.ts +++ b/src/modules/marketplaces/tests/marketplaces.service.spec.ts @@ -689,12 +689,7 @@ describe('Marketplaces Service', () => { const persistenceService = module.get(PersistenceService); const cacheService = module.get(MarketplacesCachingService); - cacheService.getAllMarketplaces = jest.fn().mockReturnValueOnce( - new CollectionType({ - items: inputMarketplace, - count: inputCount, - }), - ); + cacheService.getMarketplaceByAddressAndCollection = jest.fn().mockReturnValueOnce(null); persistenceService.getMarketplaceByKey = jest.fn().mockReturnValueOnce(inputMarketplace[0]); persistenceService.saveMarketplaceCollection = jest.fn(() => { throw new Error(); @@ -710,7 +705,27 @@ describe('Marketplaces Service', () => { const cacheService = module.get(MarketplacesCachingService); const eventPublisher = module.get(CacheEventsPublisherService); - cacheService.getAllMarketplaces = jest.fn().mockReturnValueOnce( + cacheService.getMarketplaceByAddressAndCollection = jest.fn().mockReturnValueOnce(null); + eventPublisher.publish = jest.fn(); + persistenceService.getMarketplaceByKey = jest.fn().mockReturnValueOnce(inputMarketplace[0]); + + persistenceService.saveMarketplaceCollection = jest.fn().mockReturnValueOnce( + new MarketplaceCollectionEntity({ + collectionIdentifier: 'collection', + marketplaces: [inputMarketplace[0]], + }), + ); + const expectedResult = await service.whitelistCollectionOnMarketplace(new WhitelistCollectionRequest({ marketplaceKey: 'xoxno' })); + + expect(expectedResult).toBeTruthy(); + }); + + it('when marketplace and collection already whitelistedreturns true', async () => { + const persistenceService = module.get(PersistenceService); + const cacheService = module.get(MarketplacesCachingService); + const eventPublisher = module.get(CacheEventsPublisherService); + + cacheService.getMarketplaceByAddressAndCollection = jest.fn().mockReturnValueOnce( new CollectionType({ items: inputMarketplace, count: inputCount,