Skip to content

Commit

Permalink
test(rabbitmq): tests for retrieving consumer tag fix
Browse files Browse the repository at this point in the history
fix #755
  • Loading branch information
gunesyu committed Aug 20, 2024
1 parent fafd49a commit 01c18b3
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions packages/rabbitmq/src/tests/amqp.connection.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { AmqpConnection } from '../amqp/connection';

const mockConsumerTag = 'amq.ctag-mock';

const mockChannel = 'mockChannel';
const mockConfig = {
hostname: 'localhost',
port: 5672,
username: 'guest',
password: 'guest',
vhost: '/',
uri: 'amqp://guest:guest@localhost:5672/',
};

describe('AmqpConnection', () => {
let connection: AmqpConnection;

beforeEach(async () => {
jest
.spyOn(AmqpConnection.prototype as any, 'selectManagedChannel')
.mockReturnValue({
addSetup: jest.fn((callback) => callback(mockChannel)),
});
jest
.spyOn(AmqpConnection.prototype as any, 'setupSubscriberChannel')
.mockReturnValue(mockConsumerTag);
jest
.spyOn(AmqpConnection.prototype as any, 'setupRpcChannel')
.mockReturnValue(mockConsumerTag);

connection = new AmqpConnection(mockConfig);
});

it('should return consumer tag when resolves', async () => {
const mockHandler = jest.fn();
const mockMsgOptions = { queueOptions: { channel: mockChannel } };
const mockHandlerName = 'mockHandlerName';
const mockConsumeOptions = {};

const result = await connection.createSubscriber(
mockHandler,
mockMsgOptions,
mockHandlerName,
mockConsumeOptions
);

expect(result).toEqual({ consumerTag: mockConsumerTag });
});

it('should return consumer tag when resolves', async () => {
const mockHandler = jest.fn();
const mockRpcOptions = { queueOptions: { channel: mockChannel } };

const result = await connection.createRpc(mockHandler, mockRpcOptions);

expect(result).toEqual({ consumerTag: mockConsumerTag });
});
});

0 comments on commit 01c18b3

Please sign in to comment.