diff --git a/src/commands/registration/site/index.js b/src/commands/registration/site/index.js index 521a0f59..bc5a0a24 100644 --- a/src/commands/registration/site/index.js +++ b/src/commands/registration/site/index.js @@ -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); diff --git a/test/commands/registration/site/site.spec.js b/test/commands/registration/site/site.spec.js new file mode 100644 index 00000000..d09cc508 --- /dev/null +++ b/test/commands/registration/site/site.spec.js @@ -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'); + }); + }); +});