From 241647254327c40dedbc83218839b7c8b789078e Mon Sep 17 00:00:00 2001 From: danielailie Date: Mon, 9 Oct 2023 15:06:44 +0300 Subject: [PATCH] Fix campaigns tests --- src/modules/campaigns/campaigns.service.ts | 5 --- .../campaigns/tests/campaigns.service.spec.ts | 35 ++++++++++--------- 2 files changed, 18 insertions(+), 22 deletions(-) diff --git a/src/modules/campaigns/campaigns.service.ts b/src/modules/campaigns/campaigns.service.ts index 48fc0d044..535a48aad 100644 --- a/src/modules/campaigns/campaigns.service.ts +++ b/src/modules/campaigns/campaigns.service.ts @@ -5,17 +5,12 @@ import { CampaignEntity } from 'src/db/campaigns'; import { NftMinterAbiService } from './nft-minter.abi.service'; import { CampaignsFilter } from '../common/filters/filtersTypes'; import { CollectionType } from '../assets/models/Collection.type'; -import { CacheService } from '@multiversx/sdk-nestjs-cache'; -import { Constants } from '@multiversx/sdk-nestjs-common'; -import { CacheInfo } from 'src/common/services/caching/entities/cache.info'; -import { ClientProxy } from '@nestjs/microservices'; import { PersistenceService } from 'src/common/persistence/persistence.service'; import { CampaignsCachingService } from './campaigns-caching.service'; @Injectable() export class CampaignsService { constructor( - @Inject('PUBSUB_SERVICE') private clientProxy: ClientProxy, private nftMinterService: NftMinterAbiService, private persistenceService: PersistenceService, private cacheService: CampaignsCachingService, diff --git a/src/modules/campaigns/tests/campaigns.service.spec.ts b/src/modules/campaigns/tests/campaigns.service.spec.ts index 171688458..856f5aff5 100644 --- a/src/modules/campaigns/tests/campaigns.service.spec.ts +++ b/src/modules/campaigns/tests/campaigns.service.spec.ts @@ -1,7 +1,6 @@ import { Test, TestingModule } from '@nestjs/testing'; import { PersistenceService } from 'src/common/persistence/persistence.service'; import { CampaignsService } from '../campaigns.service'; -import { CacheService } from '@multiversx/sdk-nestjs-cache'; import { NftMinterAbiService } from '../nft-minter.abi.service'; import { ClientProxy } from '@nestjs/microservices'; import { CollectionType } from 'src/modules/assets/models'; @@ -13,6 +12,7 @@ import { getSaveCampaignsExpectedResult, saveCampaignInput, } from './campaigns.testData'; +import { CampaignsCachingService } from '../campaigns-caching.service'; describe('Campaigns Service', () => { let service: CampaignsService; @@ -34,9 +34,10 @@ describe('Campaigns Service', () => { useFactory: () => ({}), }, { - provide: CacheService, + provide: CampaignsCachingService, useValue: { - getOrSet: jest.fn(), + getAllMarketplaces: jest.fn(), + getOrSetNrOfTransactionOnSC: jest.fn(), }, }, { @@ -64,8 +65,8 @@ describe('Campaigns Service', () => { describe('getCampaigns', () => { it('without filters returns full list', async () => { - const cacheService = module.get(CacheService); - jest.spyOn(cacheService, 'getOrSet').mockImplementation(() => + const cacheService = module.get(CampaignsCachingService); + jest.spyOn(cacheService, 'getAllMarketplaces').mockImplementation(() => Promise.resolve( new CollectionType({ items: inputCampaigns, @@ -85,8 +86,8 @@ describe('Campaigns Service', () => { }); it('when filters by campaignId and minterAddress returns list with one item', async () => { - const cacheService = module.get(CacheService); - jest.spyOn(cacheService, 'getOrSet').mockImplementation(() => + const cacheService = module.get(CampaignsCachingService); + jest.spyOn(cacheService, 'getAllMarketplaces').mockImplementation(() => Promise.resolve( new CollectionType({ items: inputCampaigns, @@ -113,8 +114,8 @@ describe('Campaigns Service', () => { }); it('when filters by campaignId list with that campaignId', async () => { - const cacheService = module.get(CacheService); - jest.spyOn(cacheService, 'getOrSet').mockImplementation(() => + const cacheService = module.get(CampaignsCachingService); + jest.spyOn(cacheService, 'getAllMarketplaces').mockImplementation(() => Promise.resolve( new CollectionType({ items: inputCampaigns, @@ -140,8 +141,8 @@ describe('Campaigns Service', () => { }); it('when filters by minterAddress list with that minterAddress', async () => { - const cacheService = module.get(CacheService); - jest.spyOn(cacheService, 'getOrSet').mockImplementation(() => + const cacheService = module.get(CampaignsCachingService); + jest.spyOn(cacheService, 'getAllMarketplaces').mockImplementation(() => Promise.resolve( new CollectionType({ items: inputCampaigns, @@ -170,9 +171,9 @@ describe('Campaigns Service', () => { describe('saveCampaign', () => { it('when no campaign present returns empty list', async () => { const nftMinterService = module.get(NftMinterAbiService); - const cacheService = module.get(CacheService); + const cacheService = module.get(CampaignsCachingService); jest.spyOn(nftMinterService, 'getCampaignsForScAddress').mockImplementation(() => Promise.resolve([])); - jest.spyOn(cacheService, 'getOrSet').mockImplementation(() => Promise.resolve(7)); + jest.spyOn(cacheService, 'getOrSetNrOfTransactionOnSC').mockImplementation(() => Promise.resolve(7)); const expectedResult = []; @@ -184,8 +185,8 @@ describe('Campaigns Service', () => { it('when one campaign present returns list with one item', async () => { const nftMinterService = module.get(NftMinterAbiService); const persistenceService = module.get(PersistenceService); - const cacheService = module.get(CacheService); - jest.spyOn(cacheService, 'getOrSet').mockImplementation(() => Promise.resolve(7)); + const cacheService = module.get(CampaignsCachingService); + jest.spyOn(cacheService, 'getOrSetNrOfTransactionOnSC').mockImplementation(() => Promise.resolve(7)); jest.spyOn(persistenceService, 'saveCampaign').mockImplementation(() => Promise.resolve(saveCampaignInput[0])); jest.spyOn(persistenceService, 'saveTiers').mockImplementation(() => Promise.resolve([])); @@ -201,8 +202,8 @@ describe('Campaigns Service', () => { it('when 2 campaigns present returns list with 2 items', async () => { const nftMinterService = module.get(NftMinterAbiService); const persistenceService = module.get(PersistenceService); - const cacheService = module.get(CacheService); - jest.spyOn(cacheService, 'getOrSet').mockImplementation(() => Promise.resolve(7)); + const cacheService = module.get(CampaignsCachingService); + jest.spyOn(cacheService, 'getOrSetNrOfTransactionOnSC').mockImplementation(() => Promise.resolve(7)); jest .spyOn(persistenceService, 'saveCampaign') .mockReturnValue(Promise.resolve(saveCampaignInput[1]))