test(ad pause): fix test after adding update event emission

This commit is contained in:
Fanch 2024-05-23 07:19:39 +02:00
parent d213408c83
commit bfc731bd96
1 changed files with 10 additions and 1 deletions

View File

@ -2,6 +2,7 @@ import { AD_REPOSITORY } from '@modules/ad/ad.di-tokens';
import { PauseAdCommand } from '@modules/ad/core/application/commands/pause-ad/pause-ad.command';
import { PauseAdService } from '@modules/ad/core/application/commands/pause-ad/pause-ad.service';
import { AdEntity } from '@modules/ad/core/domain/ad.entity';
import { EventEmitter2 } from '@nestjs/event-emitter';
import { Test, TestingModule } from '@nestjs/testing';
import { punctualPassengerCreateAdProps } from './ad.fixtures';
@ -13,6 +14,10 @@ const mockAdRepository = {
update: jest.fn(),
};
const mockEventEmitter = {
emitAsync: jest.fn(),
};
describe('pause-ad.service', () => {
let pauseAdService: PauseAdService;
@ -23,6 +28,10 @@ describe('pause-ad.service', () => {
provide: AD_REPOSITORY,
useValue: mockAdRepository,
},
{
provide: EventEmitter2,
useValue: mockEventEmitter,
},
PauseAdService,
],
}).compile();
@ -37,6 +46,6 @@ describe('pause-ad.service', () => {
it('should trigger the pause logic and pause the ad from the repository', async () => {
await pauseAdService.execute(new PauseAdCommand({ id: ad.id }));
expect(ad.pause).toHaveBeenCalled();
expect(mockAdRepository.update).toHaveBeenCalledWith(ad);
expect(mockAdRepository.update).toHaveBeenCalled();
});
});