import { NOTIFICATION_RMQ_DLQ, NOTIFICATION_RMQ_QUEUE } from '@app/contracts';
import { assertNotificationTopology, notificationQueueArguments } from './rabbitmq-topology';

describe('RabbitMQ notification adapter', () => {
  it('asserts durable main and dead-letter queues', async () => {
    const channel = {
      assertQueue: jest.fn().mockResolvedValue({}),
      close: jest.fn().mockResolvedValue(undefined),
    };
    const connection = {
      createChannel: jest.fn().mockResolvedValue(channel),
      close: jest.fn().mockResolvedValue(undefined),
    };

    await assertNotificationTopology('amqp://rabbit', jest.fn().mockResolvedValue(connection) as never);

    expect(channel.assertQueue).toHaveBeenNthCalledWith(1, NOTIFICATION_RMQ_DLQ, {
      durable: true, autoDelete: false, exclusive: false,
    });
    expect(channel.assertQueue).toHaveBeenNthCalledWith(2, NOTIFICATION_RMQ_QUEUE, {
      durable: true,
      autoDelete: false,
      exclusive: false,
      arguments: notificationQueueArguments,
    });
    expect(channel.close).toHaveBeenCalled();
    expect(connection.close).toHaveBeenCalled();
  });
});
