Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Catchup with the tests
Browse files Browse the repository at this point in the history
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] mtsmfm/hubot-test-helper#32
paroxp committed Dec 23, 2017

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent f929acc commit cefea7a
Showing 3 changed files with 110 additions and 0 deletions.
31 changes: 31 additions & 0 deletions tests/general.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const Helper = require('hubot-test-helper');
const co = require('co');
const { expect } = require('chai');

const helper = new Helper('../scripts/');

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(' '));
});
});
});
40 changes: 40 additions & 0 deletions tests/lit.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const Helper = require('hubot-test-helper');
const co = require('co');
const { expect } = require('chai');

const helper = new Helper('../scripts/');
const responses = require('../lib/responses.json');

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(responses.lit.failure);
});
});

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(responses.lit.success);
});
});
});
39 changes: 39 additions & 0 deletions tests/pugme.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const Helper = require('hubot-test-helper');
const co = require('co');
const { expect } = require('chai');

const helper = new Helper('../scripts/');

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!');
});
});
});

0 comments on commit cefea7a

Please sign in to comment.