From 0902dfd34f8fc327002dfbdb0b694cb5e664609d Mon Sep 17 00:00:00 2001 From: xfd1387 Date: Mon, 13 Feb 2023 12:47:50 +0200 Subject: [PATCH 1/2] The amqplib function unbindQueue was missing in ChannelWrapper --- src/ChannelWrapper.ts | 8 ++++++++ test/ChannelWrapperTest.ts | 26 ++++++++++++++++++++++++++ test/fixtures.ts | 11 +++++++++++ 3 files changed, 45 insertions(+) diff --git a/src/ChannelWrapper.ts b/src/ChannelWrapper.ts index ba28e353..ccc6f887 100644 --- a/src/ChannelWrapper.ts +++ b/src/ChannelWrapper.ts @@ -878,6 +878,14 @@ export default class ChannelWrapper extends EventEmitter { } } + /** Send a `unbindQueue` to the underlying channel. */ + // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types + async unbindQueue(queue: string, source: string, pattern: string, args?: any): Promise { + if (this._channel) { + return await this._channel.unbindQueue(queue, source, pattern, args); + } + } + /** Send a `deleteQueue` to the underlying channel. */ async deleteQueue( queue: string, diff --git a/test/ChannelWrapperTest.ts b/test/ChannelWrapperTest.ts index 67ac3a7e..73cb4de9 100644 --- a/test/ChannelWrapperTest.ts +++ b/test/ChannelWrapperTest.ts @@ -585,6 +585,32 @@ describe('ChannelWrapper', function () { channelWrapper.checkExchange('fish'); expect(channel.checkExchange).to.have.beenCalledTimes(1); expect(channel.checkExchange).to.have.beenCalledWith('fish'); + + }); + }); + + it('should proxy assertQueue, assertExchange, bindQueue and unbindQueue to the underlying channel', function () { + connectionManager.simulateConnect(); + const channelWrapper = new ChannelWrapper(connectionManager); + return channelWrapper.waitForConnect().then(function () { + // get the underlying channel + const channel = getUnderlyingChannel(channelWrapper); + + channelWrapper.assertQueue('dog'); + expect(channel.assertQueue).to.have.beenCalledTimes(1); + expect(channel.assertQueue).to.have.beenCalledWith('dog', undefined); + + channelWrapper.assertExchange('bone', 'topic'); + expect(channel.assertExchange).to.have.beenCalledTimes(1); + expect(channel.assertExchange).to.have.beenCalledWith('bone', 'topic', undefined); + + channelWrapper.bindQueue('dog', 'bone', 'legs'); + expect(channel.bindQueue).to.have.beenCalledTimes(1); + expect(channel.bindQueue).to.have.beenCalledWith('dog', 'bone', 'legs', undefined); + + channelWrapper.unbindQueue('dog', 'bone', 'legs'); + expect(channel.unbindQueue).to.have.beenCalledTimes(1); + expect(channel.unbindQueue).to.have.beenCalledWith('dog', 'bone', 'legs', undefined); }); }); diff --git a/test/fixtures.ts b/test/fixtures.ts index 9345119a..e79512d3 100644 --- a/test/fixtures.ts +++ b/test/fixtures.ts @@ -131,6 +131,17 @@ export class FakeChannel extends EventEmitter { return {}; }); + unbindQueue = jest + .fn() + .mockImplementation(async function ( + _queue: string, + _source: string, + _pattern: string, + _args?: any + ): Promise { + return {}; + }); + assertExchange = jest .fn() .mockImplementation(async function ( From f126b1ce29eec38ae0d34afc73820939e8948cc7 Mon Sep 17 00:00:00 2001 From: xfd1387 Date: Mon, 13 Feb 2023 14:40:51 +0200 Subject: [PATCH 2/2] remove unnecessary return from unbindQueue func --- src/ChannelWrapper.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ChannelWrapper.ts b/src/ChannelWrapper.ts index ccc6f887..241b41dc 100644 --- a/src/ChannelWrapper.ts +++ b/src/ChannelWrapper.ts @@ -882,7 +882,7 @@ export default class ChannelWrapper extends EventEmitter { // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types async unbindQueue(queue: string, source: string, pattern: string, args?: any): Promise { if (this._channel) { - return await this._channel.unbindQueue(queue, source, pattern, args); + await this._channel.unbindQueue(queue, source, pattern, args); } }