37 lines
1.0 KiB
TypeScript
37 lines
1.0 KiB
TypeScript
import { AmqpConnection } from '@golevelup/nestjs-rabbitmq';
|
|
import { Test, TestingModule } from '@nestjs/testing';
|
|
import { TerritoryMessager } from '../../adapters/secondaries/territory.messager';
|
|
|
|
const mockAmqpConnection = {
|
|
publish: jest.fn().mockImplementation(),
|
|
};
|
|
|
|
describe('TerritoryMessager', () => {
|
|
let territoryMessager: TerritoryMessager;
|
|
|
|
beforeAll(async () => {
|
|
const module: TestingModule = await Test.createTestingModule({
|
|
imports: [],
|
|
providers: [
|
|
TerritoryMessager,
|
|
{
|
|
provide: AmqpConnection,
|
|
useValue: mockAmqpConnection,
|
|
},
|
|
],
|
|
}).compile();
|
|
|
|
territoryMessager = module.get<TerritoryMessager>(TerritoryMessager);
|
|
});
|
|
|
|
it('should be defined', () => {
|
|
expect(territoryMessager).toBeDefined();
|
|
});
|
|
|
|
it('should publish a message', async () => {
|
|
jest.spyOn(mockAmqpConnection, 'publish');
|
|
await territoryMessager.publish('territory.create.info', 'my-test');
|
|
expect(mockAmqpConnection.publish).toHaveBeenCalledTimes(1);
|
|
});
|
|
});
|