Skip to content

Commit

Permalink
test(site): test site registry call
Browse files Browse the repository at this point in the history
  • Loading branch information
trs committed Oct 30, 2017
1 parent 154cd5a commit d787d4c
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/commands/registration/site/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
const when = require('when');
const _ = require('lodash');

const registry = require('./registry');

module.exports = {
directive: 'SITE',
handler: function ({log, command} = {}) {
const registry = require('./registry');
const subCommand = this.commands.parse(command.arg);
const rawSubCommand = _.get(command, 'arg', '');
const subCommand = this.commands.parse(rawSubCommand);
const subLog = log.child({subverb: subCommand.directive});

if (!registry.hasOwnProperty(subCommand.directive)) return this.reply(502);
Expand Down
52 changes: 52 additions & 0 deletions test/commands/registration/site/site.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
const when = require('when');
const {expect} = require('chai');
const sinon = require('sinon');
const bunyan = require('bunyan');

const siteRegistry = require('../../../../src/commands/registration/site/registry');
const FtpCommands = require('../../../../src/commands');

const CMD = 'SITE';
describe(CMD, function () {
let sandbox;
const log = bunyan.createLogger({name: 'site-test'});
const mockClient = {
reply: () => when.resolve(),
commands: new FtpCommands()
};
const cmdFn = require(`../../../../src/commands/registration/${CMD.toLowerCase()}`).handler.bind(mockClient);

beforeEach(() => {
sandbox = sinon.sandbox.create();

sandbox.stub(mockClient, 'reply').resolves();
});
afterEach(() => {
sandbox.restore();
});

it('// unsuccessful', () => {
return cmdFn({log})
.then(() => {
expect(mockClient.reply.args[0][0]).to.equal(502);
});
});

it('// unsuccessful', () => {
return cmdFn({log, command: {arg: 'BAD'}})
.then(() => {
expect(mockClient.reply.args[0][0]).to.equal(502);
});
});

it('// successful', () => {
sandbox.stub(siteRegistry.CHMOD, 'handler').resolves();

return cmdFn({log, command: {arg: 'CHMOD test'}})
.then(() => {
const {command} = siteRegistry.CHMOD.handler.args[0][0];
expect(command.directive).to.equal('CHMOD');
expect(command.arg).to.equal('test');
});
});
});

0 comments on commit d787d4c

Please sign in to comment.