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