Skip to content

Commit

Permalink
Semistandard
Browse files Browse the repository at this point in the history
  • Loading branch information
thbkid committed Jan 7, 2021
1 parent 0e4d93f commit 7d7f0b1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 28 deletions.
44 changes: 22 additions & 22 deletions test/amqp.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('AMQP', function () {
});
describe('#connect', function () {
it('should should fail to connect to bad endpoint', function (done) {
var amqp = new AMQP({
const amqp = new AMQP({
url: 'amqp://guest:guest@localhost:6767',
exchange: 'FOO'
});
Expand All @@ -32,12 +32,12 @@ describe('AMQP', function () {
});
});
it('should return a promise', async function () {
var amqp = new AMQP(config.good);
const amqp = new AMQP(config.good);
expect(amqp.connect()).to.be.fulfilled();
});
it('should declare your queue, and bind it', async function () {
var amqpLibMock = require('./amqplibmock')();
var MockedAMQP = SandboxedModule.require('../amqp', {
const amqpLibMock = require('./amqplibmock')();
const MockedAMQP = SandboxedModule.require('../amqp', {
requires: {
amqplib: amqpLibMock.mock
}
Expand All @@ -52,8 +52,8 @@ describe('AMQP', function () {
expect(amqpLibMock.bindQueueSpy.callCount).to.equal(2);
});
it('allows you to specify an array for routingKey and binds each given', function (done) {
var amqpLibMock = require('./amqplibmock')();
var MockedAMQP = SandboxedModule.require('../amqp', {
const amqpLibMock = require('./amqplibmock')();
const MockedAMQP = SandboxedModule.require('../amqp', {
requires: {
amqplib: amqpLibMock.mock
}
Expand All @@ -70,8 +70,8 @@ describe('AMQP', function () {
}).catch(done);
});
it('should just declare if you don\'t specify routing key', function (done) {
var amqpLibMock = require('./amqplibmock')();
var MockedAMQP = SandboxedModule.require('../amqp', {
const amqpLibMock = require('./amqplibmock')();
const MockedAMQP = SandboxedModule.require('../amqp', {
requires: {
amqplib: amqpLibMock.mock
}
Expand All @@ -89,24 +89,24 @@ describe('AMQP', function () {
});
describe('#publish', function () {
it('should resolve successfully', async function () {
var amqp = new AMQP(config.good);
const amqp = new AMQP(config.good);
await amqp.connect();
await expect(amqp.publish('myqueue', 'test', {})).to.eventually.be.fulfilled();
});
it('should accept objects', async function () {
var amqp = new AMQP(config.good);
const amqp = new AMQP(config.good);
await amqp.connect();
await expect(amqp.publish('myqueue', { woo: 'test' }, {})).to.eventually.be.fulfilled();
});
});
describe('#consume', async function () {
it('if done(err) is called with err === null, calls ack().', function (done) {
var ack = function () {
const ack = function () {
done();
};

var amqpLibMock = require('./amqplibmock')({ overrides: { ack: ack } });
var MockedAMQP = SandboxedModule.require('../amqp', {
const amqpLibMock = require('./amqplibmock')({ overrides: { ack: ack } });
const MockedAMQP = SandboxedModule.require('../amqp', {
requires: {
amqplib: amqpLibMock.mock
}
Expand All @@ -119,21 +119,21 @@ describe('AMQP', function () {

mockedAMQP.connect().then(function () {
mockedAMQP.consume(myMessageHandler);
}).catch(done);
}).catch((done));
});

it('if json unparsable, calls nack() with requeue of false.', function (done) {
var nack = function (message, upTo, requeue) {
const nack = function (message, upTo, requeue) {
expect(requeue).to.equal(false);
done();
};

var amqpLibMock = require('./amqplibmock')({
const amqpLibMock = require('./amqplibmock')({
messageToDeliver: 'nonvalidjson',
overrides: { nack: nack }
});

var MockedAMQP = SandboxedModule.require('../amqp', {
const MockedAMQP = SandboxedModule.require('../amqp', {
requires: {
amqplib: amqpLibMock.mock
}
Expand All @@ -150,14 +150,14 @@ describe('AMQP', function () {
});
it('if json callback called with err, calls nack() with requeue as given.',
function (done) {
var nack = function (message, upTo, requeue) {
const nack = function (message, upTo, requeue) {
expect(requeue).to.equal('requeue');
done();
};

var amqpLibMock = require('./amqplibmock')({ overrides: { nack: nack } });
const amqpLibMock = require('./amqplibmock')({ overrides: { nack: nack } });

var MockedAMQP = SandboxedModule.require('../amqp', {
const MockedAMQP = SandboxedModule.require('../amqp', {
requires: {
amqplib: amqpLibMock.mock
}
Expand All @@ -175,8 +175,8 @@ describe('AMQP', function () {
});
describe('#close', function () {
it('should close the connection', async function () {
var amqpLibMock = require('./amqplibmock')();
var MockedAMQP = SandboxedModule.require('../amqp', {
const amqpLibMock = require('./amqplibmock')();
const MockedAMQP = SandboxedModule.require('../amqp', {
requires: {
amqplib: amqpLibMock.mock
}
Expand Down
12 changes: 6 additions & 6 deletions test/amqplibmock.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/**
* This is a mock for the underlying amqplib library that we are wrapping.
*/
var Sinon = require('sinon');
const Sinon = require('sinon');

module.exports = function (config) {
var overrides = (config && config.overrides) || {};
var messageToDeliver = (config && config.messageToDeliver) || '{}';
const overrides = (config && config.overrides) || {};
const messageToDeliver = (config && config.messageToDeliver) || '{}';

var channelMock = {
const channelMock = {
consume: Sinon.stub().callsArgWith(1, {
content: {
toString: function () { return messageToDeliver; }
Expand All @@ -21,12 +21,12 @@ module.exports = function (config) {
nack: overrides.nack || Sinon.spy()
};

var connectionMock = {
const connectionMock = {
createConfirmChannel: Sinon.stub().resolves(channelMock),
close: Sinon.stub().resolves()
};

var amqpLibMock = {
const amqpLibMock = {
connect: Sinon.stub().resolves(connectionMock)
};

Expand Down

0 comments on commit 7d7f0b1

Please sign in to comment.