From 7d7f483e8e024d0a0b7836281af917a7833f7228 Mon Sep 17 00:00:00 2001 From: Rafal Proszowski Date: Fri, 22 Dec 2017 14:31:27 +0000 Subject: [PATCH] Catchup with the tests We'd like to go forward with the confidence of application keep on working. Ideal situation would be to hold a set of tests, covering each line of code in our system. This however proves to be difficult for different reasons. For instance, I'd like to test that `lit` command when successful would create a message in a separate channel. Sounds simple, yet the hubot testing helper does not support the functionality of multiple rooms. This issue has already been raised with upstream [1] and needs yet to be resolved. In order to keep hubot happy, I had to separate the script tests into a separate directory. In fact, two of them, as I've separated the response messages from script file, to be DRY about it when using in tests. The `.messages.js` file is obsolete and _should_ be removed once we come out with ideal configuration system. I took the lousy approach of implementing tests for the other functions. I'm sorry. [1] https://github.com/mtsmfm/hubot-test-helper/issues/32 --- package.json | 2 +- scripts/lit.js | 21 +++--------------- scripts/tests/general.spec.js | 31 +++++++++++++++++++++++++++ scripts/tests/lit.spec.js | 40 +++++++++++++++++++++++++++++++++++ scripts/tests/pugme.spec.js | 39 ++++++++++++++++++++++++++++++++++ scripts/utils/lit.messages.js | 26 +++++++++++++++++++++++ 6 files changed, 140 insertions(+), 19 deletions(-) create mode 100644 scripts/tests/general.spec.js create mode 100644 scripts/tests/lit.spec.js create mode 100644 scripts/tests/pugme.spec.js create mode 100644 scripts/utils/lit.messages.js diff --git a/package.json b/package.json index d2b90a3..7922320 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "local-server-start": "docker-compose up --build --force-recreate", "local-server-stop": "docker-compose down", "start": "./bin/hubot --name robotk", - "test": "mocha ./**/*.spec.js" + "test": "mocha **/*.spec.js scripts/**/*.spec.js" }, "dependencies": { "hubot": "2.19.0", diff --git a/scripts/lit.js b/scripts/lit.js index f2876e1..3ff8f31 100644 --- a/scripts/lit.js +++ b/scripts/lit.js @@ -6,28 +6,13 @@ // Configuration: // // Commands: -// randbot lit - Immortalizes a message in #lit... fam +// hubot lit - Immortalizes a message in #lit... fam +// hubot lit - Immortalizes a shared message in #lit... fam // // Author: // mikestephens/harasho -const Response = require('../lib/response'); - -const failureMessages = new Response([ - "The fuck you talking 'bout fam?", - 'You kiss your mother with hat mouth?', - 'Who do you think you are...', - 'Arse biscuits.', - "nah, i'll pass :troll:" -]); - -const successMessages = new Response([ - 'I gotchu fam', - "You're the boss! :+1:", - 'Thought you may ask for that. I liked that too.', - 'really? you seriously think that deserves fam? gee...', - 'got your back, jack' -]); +const { failureMessages, successMessages } = require('./utils/lit.messages'); // TODO: make this a configurable values // paro: Just for the time being, let's keep these separate. diff --git a/scripts/tests/general.spec.js b/scripts/tests/general.spec.js new file mode 100644 index 0000000..3559c30 --- /dev/null +++ b/scripts/tests/general.spec.js @@ -0,0 +1,31 @@ +const Helper = require('hubot-test-helper'); +const co = require('co'); +const { expect } = require('chai'); + +const helper = new Helper('../'); + +describe('robotk general', () => { + beforeEach(() => { + this.room = helper.createRoom(); + }); + + afterEach(() => { + this.room.destroy(); + }); + + context('user calls robotk by the wrong name', () => { + beforeEach(() => co(function* () { + yield this.room.user.say('alice', "randbot: i don't even know who you are any more"); + }.bind(this))); + + it('should reply to the user with touching story', () => { + expect(this.room.messages.length).to.equal(2); + expect(this.room.messages[1][1]).to.contain([ + 'That was my old form.', + 'I have become perfect.', + 'I am become RoboTK.', + 'You shall address me as such.' + ].join(' ')); + }); + }); +}); diff --git a/scripts/tests/lit.spec.js b/scripts/tests/lit.spec.js new file mode 100644 index 0000000..0d3ddfe --- /dev/null +++ b/scripts/tests/lit.spec.js @@ -0,0 +1,40 @@ +const Helper = require('hubot-test-helper'); +const co = require('co'); +const { expect } = require('chai'); + +const helper = new Helper('../'); +const { failureMessages, successMessages } = require('../utils/lit.messages'); + +describe('robotk lit', () => { + beforeEach(() => { + this.room = helper.createRoom(); + }); + + afterEach(() => { + this.room.destroy(); + }); + + context('user requires robotk to lit invalid content', () => { + beforeEach(() => co(function* () { + yield this.room.user.say('alice', '@hubot lit that'); + }.bind(this))); + + it('should fail to lit message due to incorrect syntax', () => { + expect(this.room.messages.length).to.equal(2); + expect(this.room.messages[1][1]).to.be.oneOf(failureMessages.all()); + }); + }); + + context('user requires robotk to lit url', () => { + const url = 'https://hashtaggaming.slack.com/archives/test'; + + beforeEach(() => co(function* () { + yield this.room.user.say('alice', `@hubot lit ${url}`); + }.bind(this))); + + it('should lit message successfully', () => { + expect(this.room.messages.length).to.equal(3); + expect(this.room.messages[2][1]).to.be.oneOf(successMessages.all()); + }); + }); +}); diff --git a/scripts/tests/pugme.spec.js b/scripts/tests/pugme.spec.js new file mode 100644 index 0000000..dca2f86 --- /dev/null +++ b/scripts/tests/pugme.spec.js @@ -0,0 +1,39 @@ +const Helper = require('hubot-test-helper'); +const co = require('co'); +const { expect } = require('chai'); + +const helper = new Helper('../'); + +describe('robotk pugme', () => { + beforeEach(() => { + this.room = helper.createRoom(); + }); + + afterEach(() => { + this.room.destroy(); + }); + + context('user requests to pug them', () => { + beforeEach(() => co(function* () { + yield this.room.user.say('alice', '@hubot pug me'); + yield new Promise(resolve => setTimeout(resolve, 1000)); // Damn it yash. + }.bind(this))); + + it('should reply to the user with a pug pic', () => { + expect(this.room.messages.length).to.equal(2); + expect(this.room.messages[1][1]).to.contain('media.tumblr.com'); + }); + }); + + context('user requests to pug bomb them', () => { + beforeEach(() => co(function* () { + yield this.room.user.say('alice', '@hubot pug bomb 3'); + yield new Promise(resolve => setTimeout(resolve, 1000)); // Damn it yash. + }.bind(this))); + + it('should reply to the user with a wave of pug pics', () => { + expect(this.room.messages.length).to.equal(4); + expect(this.room.messages[3][1]).to.contain('You dun goofed now!'); + }); + }); +}); diff --git a/scripts/utils/lit.messages.js b/scripts/utils/lit.messages.js new file mode 100644 index 0000000..5728202 --- /dev/null +++ b/scripts/utils/lit.messages.js @@ -0,0 +1,26 @@ +// FIXME: This file is completely obsolete. Ideally, we'd be holding these +// responses in a configuration file somewhere and load them into a Response +// class on request. + +const Response = require('../../lib/response'); + +const failureMessages = new Response([ + "The fuck you talking 'bout fam?", + 'You kiss your mother with hat mouth?', + 'Who do you think you are...', + 'Arse biscuits.', + "nah, i'll pass :troll:" +]); + +const successMessages = new Response([ + 'I gotchu fam', + "You're the boss! :+1:", + 'Thought you may ask for that. I liked that too.', + 'really? you seriously think that deserves fam? gee...', + 'got your back, jack' +]); + +module.exports = { + failureMessages, + successMessages +};