feat(pause ad): emit update event after pause ad

This commit is contained in:
Fanch
2024-05-16 15:40:03 +02:00
parent 2ce64cd1c4
commit d213408c83
6 changed files with 96 additions and 37 deletions

View File

@@ -0,0 +1,42 @@
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 { Test, TestingModule } from '@nestjs/testing';
import { punctualPassengerCreateAdProps } from './ad.fixtures';
const ad: AdEntity = AdEntity.create(punctualPassengerCreateAdProps());
jest.spyOn(ad, 'pause');
const mockAdRepository = {
findOneById: jest.fn().mockImplementation(() => ad),
update: jest.fn(),
};
describe('pause-ad.service', () => {
let pauseAdService: PauseAdService;
beforeAll(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [
{
provide: AD_REPOSITORY,
useValue: mockAdRepository,
},
PauseAdService,
],
}).compile();
pauseAdService = module.get<PauseAdService>(PauseAdService);
});
it('should be defined', () => {
expect(pauseAdService).toBeDefined();
});
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);
});
});

View File

@@ -0,0 +1,42 @@
import { PauseAdGrpcController } from '@modules/ad/interface/grpc-controllers/pause-ad.grpc.controller';
import { CommandBus } from '@nestjs/cqrs';
import { Test, TestingModule } from '@nestjs/testing';
const mockCommandBus = {
execute: jest.fn(),
};
describe('Pause Ad Grpc Controller', () => {
let pauseAdGrpcController: PauseAdGrpcController;
beforeAll(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [
{
provide: CommandBus,
useValue: mockCommandBus,
},
PauseAdGrpcController,
],
}).compile();
pauseAdGrpcController = module.get<PauseAdGrpcController>(
PauseAdGrpcController,
);
});
afterEach(async () => {
jest.clearAllMocks();
});
it('should be defined', () => {
expect(pauseAdGrpcController).toBeDefined();
});
it('should execute the pause ad command', async () => {
await pauseAdGrpcController.pause({
id: '200d61a8-d878-4378-a609-c19ea71633d2',
});
expect(mockCommandBus.execute).toHaveBeenCalledTimes(1);
});
});