diff --git a/src/ChannelWrapper.js b/src/ChannelWrapper.js index 663e7eb..780bce2 100644 --- a/src/ChannelWrapper.js +++ b/src/ChannelWrapper.js @@ -428,4 +428,14 @@ export default class ChannelWrapper extends EventEmitter { assertQueue() { return this._channel && this._channel.assertQueue.apply(this._channel, arguments); } + + // Send a `bindQueue` to the underlying channel. + bindQueue() { + return this._channel && this._channel.bindQueue.apply(this._channel, arguments); + } + + // Send a `assertExchange` to the underlying channel. + assertExchange() { + return this._channel && this._channel.assertExchange.apply(this._channel, arguments); + } } diff --git a/test/ChannelWrapperTest.js b/test/ChannelWrapperTest.js index 75c76aa..7fe8327 100644 --- a/test/ChannelWrapperTest.js +++ b/test/ChannelWrapperTest.js @@ -458,6 +458,62 @@ describe('ChannelWrapper', function() { return channelWrapper.nack('c', false, true); }); + it('should proxy assertQueue, bindQueue, assertExchange to the underlying channel', function() { + connectionManager.simulateConnect(); + const channelWrapper = new ChannelWrapper(connectionManager); + return channelWrapper.waitForConnect() + .then(function() { + // get the underlying channel + const channel = channelWrapper._channel; + + channelWrapper.assertQueue('dog'); + expect(channel.assertQueue.calledOnce).to.be.true; + expect(channel.assertQueue.lastCall.args).to.eql(['dog']); + + channelWrapper.bindQueue('dog', 'bone'); + expect(channel.bindQueue.calledOnce).to.be.true; + expect(channel.bindQueue.lastCall.args).to.eql(['dog', 'bone']); + + channelWrapper.assertExchange('bone'); + expect(channel.assertExchange.calledOnce).to.be.true; + expect(channel.assertExchange.lastCall.args).to.eql(['bone']); + }); + }); + + it(`should proxy assertQueue, bindQueue, assertExchange to the underlying channel, + even if we aren't done setting up`, function() { + const channelWrapper = new ChannelWrapper(connectionManager); + + channelWrapper.addSetup(function() { + channelWrapper.assertQueue('dog'); + channelWrapper.bindQueue('dog', 'bone'); + channelWrapper.assertExchange('bone'); + return Promise.resolve(); + }); + + connectionManager.simulateConnect(); + + return channelWrapper.waitForConnect() + .then(function() { + const channel = channelWrapper._channel; + expect(channel.assertQueue.calledOnce).to.be.true; + expect(channel.assertQueue.lastCall.args).to.eql(['dog']); + + expect(channel.bindQueue.calledOnce).to.be.true; + expect(channel.bindQueue.lastCall.args).to.eql(['dog', 'bone']); + + expect(channel.assertExchange.calledOnce).to.be.true; + expect(channel.assertExchange.lastCall.args).to.eql(['bone']); + }); + }); + + it('should ignore assertQueue, bindQueue, assertExchange if we are disconnected', function() { + const channelWrapper = new ChannelWrapper(connectionManager); + channelWrapper.assertQueue('dog', true); + channelWrapper.bindQueue('dog', 'bone', true); + channelWrapper.assertExchange('bone', true); + }); + // Not much to test here - just make sure we don't throw any exceptions or anything weird. :) it('clean up when closed', function() { diff --git a/test/fixtures.js b/test/fixtures.js index a7c3796..52c3a55 100644 --- a/test/fixtures.js +++ b/test/fixtures.js @@ -71,6 +71,12 @@ export class FakeConfirmChannel extends EventEmitter { this.nackAll = sinon.spy(function(requeue) {}); // eslint-disable-line + this.assertQueue = sinon.spy(function(queue, options) {}); //eslint-disable-line + + this.bindQueue = sinon.spy(function(queue, source, pattern, args) {}); //eslint-disable-line + + this.assertExchange = sinon.spy(function(exchange, type, options) {}); //eslint-disable-line + this.close = sinon.spy(() => this.emit('close')); } } @@ -119,4 +125,4 @@ export class FakeAmqpConnectionManager extends EventEmitter { err: new Error(('Boom!')) }); } -} \ No newline at end of file +}