discord-irc/test/create-bots.test.js
Edward Jones 221d42a44b
Upgrade sinon to ^7.4.1, sinon-chai to ^3.3.0 (#503)
* Upgrade sinon to ^5.1.1 and sinon-chai to ^3.1.0

* Upgrade sinon to ^6.3.5

* Upgrade sinon to ^7.4.1
2019-08-08 13:03:05 -03:00

64 lines
1.8 KiB
JavaScript

/* eslint-disable no-unused-expressions, prefer-arrow-callback */
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.createSandbox({
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 () {
function 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 () {
function wrap() {
createBots(stringConfig);
}
(wrap).should.throw('Invalid configuration file given');
});
it('should be possible to run it through require(\'discord-irc\')', function () {
const bots = index(singleTestConfig);
bots.length.should.equal(1);
this.connectStub.should.have.been.called;
});
});