Added Tests

- added tests for lib/cmd
pull/26/head
Trivernis 6 years ago
parent 8b2f9c45cf
commit 298119511a

@ -50,3 +50,26 @@ exports.mockVoicechannel = {
exports.mockChannel = {
send: (msg) => console.log('Send: ', msg)
};
exports.mockCommand = {
"name": "test",
"permission": "all",
"description": "Tests everything",
"category": "Test",
"response": {
"success": "Testing successful"
},
"textReply": () => {
return 'test';
},
"promiseReply": () => {
return new Promise((rs, rj) => {
rs('test');
});
},
"richEmbedReply": () => {
return {embed: {
title: 'rich embed'
}};
}
};

@ -160,7 +160,8 @@ describe('lib/utils', function() {
});
});
describe('The dj class', function () {
describe('lib/music', function() {
const music = rewire('../lib/music');
const Readable = require('stream').Readable;
@ -176,6 +177,8 @@ describe('The dj class', function () {
return s;
});
describe('#DJ', function () {
it('connects to a VoiceChannel', function (done) {
let dj = new music.DJ(mockobjects.mockVoicechannel);
dj.connect().then(()=> {
@ -212,7 +215,7 @@ describe('The dj class', function () {
setTimeout(() => {
assert(dj.playing);
done();
}, 211);
}, 100);
});
it('gets the video name', function (done) {
@ -301,4 +304,46 @@ describe('The dj class', function () {
done();
});
})
});
});
describe('lib/cmd', function() {
const cmd = rewire('../lib/cmd');
cmd.__set__("logger", mockobjects.mockLogger);
describe('#Servant', function() {
it('creates commands', function() {
let servant = new cmd.Servant('');
servant.createCommand(mockobjects.mockCommand, mockobjects.mockCommand.textReply);
assert(servant.commands['test']);
servant.createCommand(mockobjects.mockCommand, mockobjects.mockCommand.promiseReply);
assert(servant.commands['test']);
servant.createCommand(mockobjects.mockCommand, mockobjects.mockCommand.richEmbedReply);
assert(servant.commands['test']);
});
it('removes commands', function() {
let servant = new cmd.Servant('');
servant.createCommand(mockobjects.mockCommand, mockobjects.mockCommand.textReply);
assert(servant.commands['test']);
servant.removeCommand('test');
assert(!servant.commands['test'])
});
it('parses commands', function() {
let spy = sinon.spy();
let servant = new cmd.Servant('');
servant.createCommand(mockobjects.mockCommand, spy);
assert(servant.commands['test']);
assert(!spy.called);
servant.parseCommand({
content: 'test',
author: {
tag: undefined
}
});
assert(spy.called);
});
});
});
Loading…
Cancel
Save