Skip to content

Commit

Permalink
The amqplib function unbindQueue was missing in ChannelWrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
xfd1387 committed Feb 13, 2023
1 parent 7a3d1d1 commit 0902dfd
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/ChannelWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
if (this._channel) {
return await this._channel.unbindQueue(queue, source, pattern, args);
}
}

/** Send a `deleteQueue` to the underlying channel. */
async deleteQueue(
queue: string,
Expand Down
26 changes: 26 additions & 0 deletions test/ChannelWrapperTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

Expand Down
11 changes: 11 additions & 0 deletions test/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Replies.Empty> {
return {};
});

assertExchange = jest
.fn()
.mockImplementation(async function (
Expand Down

0 comments on commit 0902dfd

Please sign in to comment.