Handle ad.updated integration events

This commit is contained in:
Romain Thouvenin
2024-05-03 12:46:11 +02:00
parent 3be2d73c60
commit cc9b45c6a1
5 changed files with 87 additions and 1 deletions

View File

@@ -0,0 +1,43 @@
import { AdUpdatedMessageHandler } from '@modules/ad/interface/message-handlers/ad-updated.message-handler';
import { CommandBus } from '@nestjs/cqrs';
import { Test, TestingModule } from '@nestjs/testing';
const adUpdatedMessage =
'{"data": {"id":"4eb6a6af-ecfd-41c3-9118-473a507014d4","driver":"true","passenger":"true","frequency":"PUNCTUAL","fromDate":"2023-08-18","toDate":"2023-08-18","schedule":[{"day":"5","time":"10:00","margin":"900"}],"seatsProposed":"3","seatsRequested":"1","strict":"false","waypoints":[{"position":"0","houseNumber":"5","street":"rue de la monnaie","locality":"Nancy","postalCode":"54000","country":"France","lon":"48.689445","lat":"6.17651"},{"position":"1","locality":"Paris","postalCode":"75000","country":"France","lon":"48.8566","lat":"2.3522"}]}}';
const mockCommandBus = {
execute: jest.fn(),
};
describe('Ad Updated Message Handler', () => {
let adUpdatedMessageHandler: AdUpdatedMessageHandler;
beforeAll(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [
{
provide: CommandBus,
useValue: mockCommandBus,
},
AdUpdatedMessageHandler,
],
}).compile();
adUpdatedMessageHandler = module.get<AdUpdatedMessageHandler>(
AdUpdatedMessageHandler,
);
});
afterEach(async () => {
jest.clearAllMocks();
});
it('should be defined', () => {
expect(adUpdatedMessageHandler).toBeDefined();
});
it('should update an ad', async () => {
await adUpdatedMessageHandler.adUpdated(adUpdatedMessage);
expect(mockCommandBus.execute).toHaveBeenCalledTimes(1);
});
});