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