Skip to content
This repository has been archived by the owner on Feb 17, 2023. It is now read-only.

Commit

Permalink
Merge branch 'initial_commit' of github.com:GannettDigital/fudd into …
Browse files Browse the repository at this point in the history
…initial_commit
  • Loading branch information
enigmatic00 committed Jun 20, 2016
2 parents 3711a3d + ac5abae commit a1fa6d6
Showing 1 changed file with 50 additions and 12 deletions.
62 changes: 50 additions & 12 deletions test/unit/fudd.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ var config = {
options: {durable: true}
}
],

bindings: [
{
bindingType: 'queue',
Expand All @@ -29,31 +28,21 @@ var config = {
};

describe('fudd', function() {

var Fudd;
var configUtilsStub;
var mapEachStub;
var seriesStub;

before('enable mockery', function() {
mockery.enable({useCleanCache: true});
mockery.registerAllowable('../../lib/fudd.js');

mockery.registerMock('amqplib/callback_api', {});
mockery.registerMock('palinode', {
series: seriesStub = sinon.stub(),
mapEach: mapEachStub = sinon.stub()
});
mockery.registerMock('./amqp-config-utils.js', configUtilsStub = sinon.stub().returns('amqp://some.host'));

Fudd = require('../../lib/fudd.js');
});

after('disable mockery', mockery.disable);

describe('setup', function() {
var callbackSpy;
var connectBindStub;
var disconnectStub;
var createExchangeBindStub;
var createQueueBindStub;
var createBindingsBindStub;
Expand All @@ -62,9 +51,22 @@ describe('fudd', function() {
var boundCreateQueue = function createQueueBindResult() {};
var boundCreateBindings = function createBindingsBindResult() {};

before('setup mocks', function() {
mockery.deregisterAll();
mockery.resetCache();
mockery.registerMock('amqplib/callback_api', {});
mockery.registerMock('palinode', {
series: seriesStub = sinon.stub(),
mapEach: mapEachStub = sinon.stub()
});
mockery.registerMock('./amqp-config-utils.js', {});
Fudd = require('../../lib/fudd.js');
});

before('setup stubs', function() {
callbackSpy = sinon.spy();
connectBindStub = sinon.stub(Fudd._connect, 'bind').returns(boundConnect);
Fudd.__proto__._disconnect = disconnectStub = sinon.spy();
createExchangeBindStub = sinon.stub(Fudd._createExchange, 'bind').returns(boundCreateExchange);
createQueueBindStub = sinon.stub(Fudd._createQueue, 'bind').returns(boundCreateQueue);
createBindingsBindStub = sinon.stub(Fudd._createBindings, 'bind').returns(boundCreateBindings);
Expand All @@ -80,6 +82,7 @@ describe('fudd', function() {
beforeEach('reset stubs', function() {
callbackSpy.reset();
connectBindStub.reset();
disconnectStub.reset();
seriesStub.reset();
mapEachStub.reset();
createExchangeBindStub.reset();
Expand All @@ -98,6 +101,27 @@ describe('fudd', function() {
expect(seriesStub.args[0][0]).to.eql([boundConnect, Fudd._createChannel]);
});

it('should call the finalCallback if the first series call calls back with an error', function() {
var expectedError = new Error('things happened');
seriesStub.callArgWith(1, expectedError);
expect(callbackSpy.args[0]).to.eql([expectedError]);
});

it('should call _createExchange.bind for each exchange in the config', function() {
seriesStub.callArgWith(1, null, 'connection', 'channel');
expect(createExchangeBindStub.callCount).to.equal(config.exchanges.length);
});

it('should call _createExchange.bind for each queue in the config', function() {
seriesStub.callArgWith(1, null, 'connection', 'channel');
expect(createQueueBindStub.callCount).to.equal(config.queues.length);
});

it('should call _createExchange.bind for each binding in the config', function() {
seriesStub.callArgWith(1, null, 'connection', 'channel');
expect(createBindingsBindStub.callCount).to.equal(config.bindings.length);
});

it('should invoke series again with a sequence of functions derived from the config', function() {
seriesStub.callArgWith(1, null, 'connection', 'channel');
expect(seriesStub.args[1][0]).to.eql([
Expand All @@ -107,5 +131,19 @@ describe('fudd', function() {
]);
});

it('should call the final callback with the error returned from creating the infrastructure', function() {
var expectedError = new Error('error creating infrastructure');
seriesStub.callArgWith(1, null, 'connection', 'channel');
seriesStub.callArgWith(1, expectedError);
expect(callbackSpy.args[0]).to.eql([expectedError]);
});

it('should invoke Fudd._disconnect wtih the connection and callback', function() {
seriesStub.callArgWith(1, null, 'connection', 'channel');
seriesStub.callArgWith(1, null);
expect(disconnectStub.args[0]).to.eql([
'connection', callbackSpy
]);
})
});
});

0 comments on commit a1fa6d6

Please sign in to comment.