Skip to content

Commit

Permalink
feat: what's your pirate name? (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
bcoe authored Jan 17, 2017
1 parent cf7343a commit 2468c46
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 4 deletions.
26 changes: 26 additions & 0 deletions commands/name.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
exports.suffixes = [
'the Red',
'the Sour',
'the Strong',
'the Grumpy',
'the Stout'
]

exports.prefixes = [
"Lil'",
'Peg-legged',
'Two-Legged',
'One-Eyed',
'Two-Eyed',
'Four-Eyed',
'Smelly'
]

exports.command = 'name'
exports.describe = "what's yer pirate name?"
exports.builder = {}
exports.handler = function (argv) {
const prefix = exports.prefixes[parseInt(Math.random() * exports.prefixes.length)]
const suffix = exports.suffixes[parseInt(Math.random() * exports.suffixes.length)]
argv.respond(`${argv.user_name} your pirate name is, "${prefix} ${argv.user_name} ${suffix}"`)
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "server.js",
"scripts": {
"pretest": "standard",
"test": "nyc mocha test.js",
"test": "nyc mocha test/ test/commands/",
"start": "./bin/pirate-joe.js",
"coverage": "nyc report --reporter=text-lcov | coveralls"
},
Expand Down
1 change: 0 additions & 1 deletion server.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ app.post('/', function (req, res) {
// provides a respond function that any yargs
// command can use to respond to Slack.
context.respond = buildResponder(req.body.response_url)

// run the yargs parser on the inbound slack command.
parser.parse(req.body.text || '', context, (err, argv, output) => {
if (err) logger.error(err.message)
Expand Down
17 changes: 17 additions & 0 deletions test/commands/name.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* global describe, it */

const name = require('../../commands/name')

require('chai').should()

describe('Name Command', () => {
it('generates a random pirate name', (done) => {
name.handler({
user_name: 'bcoe',
respond: (msg) => {
msg.should.match(/bcoe your pirate name is/)
return done()
}
})
})
})
4 changes: 2 additions & 2 deletions test.js → test/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
// to the originating slack channel.
const nock = require('nock')
const request = require('request')
const startServer = require('./server')
const startServer = require('../server')

require('chai').should()

describe('Pirate Joe', () => {
describe('Pirate Joe Server', () => {
let server = null
// all tests run against an actual running
// instance of the server.
Expand Down

0 comments on commit 2468c46

Please sign in to comment.