Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions scripts/jobs-suggestion.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ function maybe(p, fn) {
}

function response() {
return 'Hi! please post jobs via a pull request to https://github.com/newhavenio/newhavenio';
return process.env.JOBS_BOARD_SUGGESTION;
}

module.exports = function(robot) {
robot.hear(/[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)?/gi, function(msg) {
let max = parseInt(process.env.JOBS_SUGGESTION_MAX_PERCENTAGE, 10) || 100
if(msg.message.user.room === process.env.JOBS_BOARD_ROOM) {
if((msg.message.user.room === process.env.JOBS_BOARD_ROOM) && (msg.message.user.id != process.env.IOBOT_USER_ID)) {
maybe(max, function() {
msg.send(response());
});
Expand Down
10 changes: 10 additions & 0 deletions test/jobs-suggestion-test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@ response = "Hi! please post jobs via a pull request to https://github.com/newhav
describe 'jobs-suggestion', ->
context 'in #jobs', ->
beforeEach ->
process.env.JOBS_BOARD_SUGGESTION = response
process.env.JOBS_SUGGESTION_MAX_PERCENTAGE = "100"
process.env.JOBS_BOARD_ROOM = "jobs"
process.env.IOBOT_USER_ID = "iobot"
@room = helper.createRoom({name: 'jobs'})

afterEach ->
delete process.env.JOBS_SUGGESTION_MAX_PERCENTAGE
delete process.env.JOBS_BOARD_ROOM
delete process.env.IOBOT_USER_ID
@room.destroy()

context 'with a url', ->
Expand All @@ -27,6 +30,13 @@ describe 'jobs-suggestion', ->
['hubot', response]
]

context 'by the robot itself', ->
it 'does not respond', ->
@room.user.say('iobot', 'check out my job post here: https://www.example.com').then =>
expect(@room.messages[0..1]).to.eql [
['iobot', 'check out my job post here: https://www.example.com']
]

context 'without a url', ->
it 'does not respond', ->
@room.user.say('alice', 'check out my job post here: not a url').then =>
Expand Down