forked from ekmartin/slack-irc
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcreate-bots.test.js
57 lines (48 loc) · 1.76 KB
/
create-bots.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/* eslint no-unused-expressions: 0 */
import chai from 'chai';
import sinon from 'sinon';
import sinonChai from 'sinon-chai';
import Bot from '../lib/bot';
import index from '../lib/index';
import testConfig from './fixtures/test-config.json';
import singleTestConfig from './fixtures/single-test-config.json';
import badConfig from './fixtures/bad-config.json';
import stringConfig from './fixtures/string-config.json';
import { createBots } from '../lib/helpers';
chai.should();
chai.use(sinonChai);
describe('Create Bots', function() {
const sandbox = sinon.sandbox.create({
useFakeTimers: false,
useFakeServer: false
});
beforeEach(function() {
this.connectStub = sandbox.stub(Bot.prototype, 'connect');
});
afterEach(function() {
sandbox.restore();
});
it('should work when given an array of configs', function() {
const bots = createBots(testConfig);
bots.length.should.equal(2);
this.connectStub.should.have.been.called;
});
it('should work when given an object as a config file', function() {
const bots = createBots(singleTestConfig);
bots.length.should.equal(1);
this.connectStub.should.have.been.called;
});
it('should throw a configuration error if any fields are missing', function() {
const wrap = () => createBots(badConfig);
(wrap).should.throw('Missing configuration field nickname');
});
it('should throw if a configuration file is neither an object or an array', function() {
const wrap = () => createBots(stringConfig);
(wrap).should.throw('Invalid configuration file given');
});
it('should be possible to run it through require(\'slack-irc\')', function() {
const bots = index(singleTestConfig);
bots.length.should.equal(1);
this.connectStub.should.have.been.called;
});
});