Skip to content

Commit

Permalink
Merge pull request #44 from bartfeenstra/fix-pm
Browse files Browse the repository at this point in the history
Fix broken private messages, and increase code coverage
  • Loading branch information
mose authored Feb 27, 2018
2 parents 488bdc0 + e5f6ddb commit bb3abbc
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 7 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@
"grunt-release": "^0.14.0",
"hubot": "^3.0.0",
"hubot-mock-adapter-v3": "^1.0.0",
"hubot-test-helper": "^1.8.1",
"matchdep": "^0.1.2",
"mocha": "^3.0.2",
"nyc": "^11.0.3",
"semantic-release": "^6.3.6",
"sinon": "^1.4.2",
"sinon-chai": "^2.8.0",
"standard": "^10.0.2",
"semantic-release": "^6.3.6"
"standard": "^10.0.2"
},
"main": "index.coffee",
"scripts": {
Expand Down
8 changes: 3 additions & 5 deletions src/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ const helpContents = (name, commands) => `\
`

module.exports = (robot) => {
const replyInPrivate = process.env.HUBOT_HELP_REPLY_IN_PRIVATE

robot.respond(/help(?:\s+(.*))?$/i, (msg) => {
let cmds = getHelpCommands(robot)
const filter = msg.match[1]
Expand All @@ -74,9 +72,9 @@ module.exports = (robot) => {

const emit = cmds.join('\n')

if (replyInPrivate && msg.message && msg.message.user && msg.message.user.name && msg.message.user.name !== msg.message.room) {
msg.reply('replied to you in private!')
return robot.send({ room: msg.message.user.name }, emit)
if (process.env.HUBOT_HELP_REPLY_IN_PRIVATE && msg.message && msg.message.user && msg.message.user.name && msg.message.user.name !== msg.message.room) {
msg.reply('I just replied to you in private.')
return msg.sendPrivate(emit)
} else {
return msg.send(emit)
}
Expand Down
58 changes: 58 additions & 0 deletions test/help_message_visibility_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
'use strict'

/* global describe, beforeEach, afterEach, it, context */

const chai = require('chai')
const expect = chai.expect

chai.use(require('sinon-chai'))

const Helper = require('hubot-test-helper')

const helper = new Helper('../src/help.js')

describe('help', () => describe('message visibility', () => {
beforeEach(function () {
this.timeout(5000)
this.room = helper.createRoom()
})

afterEach(function () {
this.room.destroy()
})

context('when HUBOT_HELP_REPLY_IN_PRIVATE is unset', () => it('replies in the same room', function (done) {
this.room.user.say('john', '@hubot help help').then(() => {
expect(this.room.messages).to.eql([
['john', '@hubot help help'],
['hubot', 'hubot help - Displays all of the help commands that this bot knows about.\nhubot help <query> - Displays all help commands that match <query>.']
])
}).then(done, done)
}))
}))

describe('help', () => describe('message visibility', () => {
beforeEach(function () {
process.env.HUBOT_HELP_REPLY_IN_PRIVATE = true
this.room = helper.createRoom()
})

afterEach(function () {
delete process.env.HUBOT_HELP_REPLY_IN_PRIVATE
this.room.destroy()
})

context('when HUBOT_HELP_REPLY_IN_PRIVATE is set', () => it('replies in a private message', function (done) {
this.room.user.say('john', '@hubot help help').then(() => {
expect(this.room.messages).to.eql([
['john', '@hubot help help'],
['hubot', '@john I just replied to you in private.']
])
expect(this.room.privateMessages).to.eql({
john: [
['hubot', 'hubot help - Displays all of the help commands that this bot knows about.\nhubot help <query> - Displays all help commands that match <query>.']
]
})
}).then(done, done)
}))
}))

0 comments on commit bb3abbc

Please sign in to comment.