import { Test, TestingModule } from '@nestjs/testing'; import { MessagePublisher } from '../../../../adapters/secondaries/message-publisher'; import { MESSAGE_BROKER_PUBLISHER } from '../../../../../../app.constants'; const mockMessageBrokerPublisher = { publish: jest.fn().mockImplementation(), }; describe('Messager', () => { let messagePublisher: MessagePublisher; beforeAll(async () => { const module: TestingModule = await Test.createTestingModule({ imports: [], providers: [ MessagePublisher, { provide: MESSAGE_BROKER_PUBLISHER, useValue: mockMessageBrokerPublisher, }, ], }).compile(); messagePublisher = module.get(MessagePublisher); }); it('should be defined', () => { expect(messagePublisher).toBeDefined(); }); it('should publish a message', async () => { jest.spyOn(mockMessageBrokerPublisher, 'publish'); messagePublisher.publish('ad.info', 'my-test'); expect(mockMessageBrokerPublisher.publish).toHaveBeenCalledTimes(1); }); });