Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('should configure RabbitMQ with useExisting explicit provide', async () => {
const spy = jest.spyOn(amqplib, 'connect');
const instance = new RabbitConfig();
app = await Test.createTestingModule({
imports: [
RabbitMQModule.forRootAsync(RabbitMQModule, {
useExisting: {
provide: RabbitConfig,
value: instance,
},
}),
],
}).compile();
expect(spy).toHaveBeenCalledTimes(1);
expect(spy).toHaveBeenCalledWith(uri);
});
beforeAll(async () => {
const moduleFixture = await Test.createTestingModule({
providers: [SubscribeService],
imports: [
RabbitMQModule.forRootAsync(RabbitMQModule, {
useFactory: () => ({
exchanges: [
{
name: exchange,
type: 'topic',
},
],
uri,
}),
}),
],
}).compile();
app = moduleFixture.createNestApplication();
await app.init();
amqpConnection = app.get(AmqpConnection);
import { RabbitMQModule } from '@golevelup/nestjs-rabbitmq';
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { RpcService } from './rpc/rpc.service';
const rabbitHost = process.env.NODE_ENV === 'ci' ? 'rabbit' : 'localhost';
@Module({
imports: [
RabbitMQModule.forRootAsync(RabbitMQModule, {
useFactory: () => ({
exchanges: [
{
name: 'exchange1',
type: 'topic',
},
],
uri: `amqp://rabbitmq:rabbitmq@${rabbitHost}:5672`,
}),
}),
],
controllers: [AppController],
providers: [RpcService],
})
export class AppModule {}