Added Tests

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

@ -49,4 +49,27 @@ exports.mockVoicechannel = {
exports.mockChannel = { exports.mockChannel = {
send: (msg) => console.log('Send: ', msg) 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 music = rewire('../lib/music');
const Readable = require('stream').Readable; const Readable = require('stream').Readable;
@ -176,129 +177,173 @@ describe('The dj class', function () {
return s; return s;
}); });
it('connects to a VoiceChannel', function (done) { describe('#DJ', function () {
let dj = new music.DJ(mockobjects.mockVoicechannel);
dj.connect().then(()=> { it('connects to a VoiceChannel', function (done) {
assert(dj.connected); let dj = new music.DJ(mockobjects.mockVoicechannel);
done(); dj.connect().then(()=> {
assert(dj.connected);
done();
});
}); });
});
it('listens on Repeat', function () { it('listens on Repeat', function () {
let dj = new music.DJ(mockobjects.mockVoicechannel); let dj = new music.DJ(mockobjects.mockVoicechannel);
dj.current = {'url': '', 'title': ''}; dj.current = {'url': '', 'title': ''};
dj.listenOnRepeat = true; dj.listenOnRepeat = true;
assert(dj.repeat); assert(dj.repeat);
assert(dj.queue.length > 0); assert(dj.queue.length > 0);
}); });
it('plays Files', function (done) { it('plays Files', function (done) {
let dj = new music.DJ(mockobjects.mockVoicechannel); let dj = new music.DJ(mockobjects.mockVoicechannel);
dj.connect().then(() => { dj.connect().then(() => {
dj.playFile(); dj.playFile();
assert(dj.playing); assert(dj.playing);
done(); done();
});
}); });
});
it('plays YouTube urls', function (done) { it('plays YouTube urls', function (done) {
let dj = new music.DJ(mockobjects.mockVoicechannel); let dj = new music.DJ(mockobjects.mockVoicechannel);
dj.connect().then(() => { dj.connect().then(() => {
dj.playYouTube('http://www.youtube.com/watch?v=ABCDEFGHIJK'); dj.playYouTube('http://www.youtube.com/watch?v=ABCDEFGHIJK');
});
setTimeout(() => {
assert(dj.playing);
done();
}, 100);
}); });
setTimeout(() => { it('gets the video name', function (done) {
assert(dj.playing); let dj = new music.DJ(mockobjects.mockVoicechannel);
done(); dj.getVideoName('http://www.youtube.com/watch?v=ABCDEFGHIJK').then((name) => {
}, 211); assert(name === 'test');
}); done();
})
});
it('gets the video name', function (done) { it('sets the volume', function(done) {
let dj = new music.DJ(mockobjects.mockVoicechannel); let dj = new music.DJ(mockobjects.mockVoicechannel);
dj.getVideoName('http://www.youtube.com/watch?v=ABCDEFGHIJK').then((name) => { dj.connect().then(() => {
assert(name === 'test'); dj.playFile();
done(); dj.setVolume(100);
}) assert(dj.volume === 100);
}); done();
})
});
it('sets the volume', function(done) { it('pauses playback', function(done) {
let dj = new music.DJ(mockobjects.mockVoicechannel); let dj = new music.DJ(mockobjects.mockVoicechannel);
dj.connect().then(() => { dj.connect().then(() => {
dj.playFile(); dj.playFile();
dj.setVolume(100); dj.pause();
assert(dj.volume === 100); done();
done(); })
}) });
});
it('pauses playback', function(done) { it('resumes playback', function(done) {
let dj = new music.DJ(mockobjects.mockVoicechannel); let dj = new music.DJ(mockobjects.mockVoicechannel);
dj.connect().then(() => { dj.connect().then(() => {
dj.playFile(); dj.playFile();
dj.pause(); dj.resume();
done(); done();
}) })
}); });
it('resumes playback', function(done) { it('stops playback', function(done) {
let dj = new music.DJ(mockobjects.mockVoicechannel); let dj = new music.DJ(mockobjects.mockVoicechannel);
dj.connect().then(() => { dj.connect().then(() => {
dj.playFile(); dj.playFile();
dj.resume(); assert(dj.playing);
done(); dj.stop();
}) assert(!dj.conn && !dj.disp);
}); done();
});
});
it('stops playback', function(done) { it('skips songs', function(done) {
let dj = new music.DJ(mockobjects.mockVoicechannel); let dj = new music.DJ(mockobjects.mockVoicechannel);
dj.connect().then(() => { dj.connect().then(() => {
dj.playFile(); dj.playYouTube('http://www.youtube.com/watch?v=ABCDEFGHIJK');
assert(dj.playing); dj.playYouTube('http://www.youtube.com/watch?v=ABCDEFGHIJK');
dj.stop(); dj.playYouTube('http://www.youtube.com/watch?v=ABCDEFGHIJK');
assert(!dj.conn && !dj.disp); dj.playYouTube('http://www.youtube.com/watch?v=ABCDEFGHIJK');
done(); dj.skip();
dj.skip();
done();
});
}); });
});
it('skips songs', function(done) { it('returns a playlist', function(done) {
let dj = new music.DJ(mockobjects.mockVoicechannel); let dj = new music.DJ(mockobjects.mockVoicechannel);
dj.connect().then(() => { dj.connect().then(() => {
dj.playYouTube('http://www.youtube.com/watch?v=ABCDEFGHIJK'); dj.queue = [{
dj.playYouTube('http://www.youtube.com/watch?v=ABCDEFGHIJK'); 'title': 'title',
dj.playYouTube('http://www.youtube.com/watch?v=ABCDEFGHIJK'); 'url': 'http://www.youtube.com/watch?v=ABCDEFGHIJK'}, {
dj.playYouTube('http://www.youtube.com/watch?v=ABCDEFGHIJK'); 'title': 'title',
dj.skip(); 'url': 'http://www.youtube.com/watch?v=ABCDEFGHIJK'}];
dj.skip(); assert(dj.playlist.length > 0);
done(); done();
});
}); });
it('clears the queue', function(done) {
let dj = new music.DJ(mockobjects.mockVoicechannel);
dj.connect().then(() => {
dj.queue = [{
'title': 'title',
'url': 'http://www.youtube.com/watch?v=ABCDEFGHIJK'}, {
'title': 'title',
'url': 'http://www.youtube.com/watch?v=ABCDEFGHIJK'}];
dj.clear();
assert(dj.queue.length === 0);
done();
});
})
}); });
});
it('returns a playlist', function(done) { describe('lib/cmd', function() {
let dj = new music.DJ(mockobjects.mockVoicechannel); const cmd = rewire('../lib/cmd');
dj.connect().then(() => { cmd.__set__("logger", mockobjects.mockLogger);
dj.queue = [{
'title': 'title', describe('#Servant', function() {
'url': 'http://www.youtube.com/watch?v=ABCDEFGHIJK'}, {
'title': 'title', it('creates commands', function() {
'url': 'http://www.youtube.com/watch?v=ABCDEFGHIJK'}]; let servant = new cmd.Servant('');
assert(dj.playlist.length > 0); servant.createCommand(mockobjects.mockCommand, mockobjects.mockCommand.textReply);
done(); 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('clears the queue', function(done) { it('removes commands', function() {
let dj = new music.DJ(mockobjects.mockVoicechannel); let servant = new cmd.Servant('');
dj.connect().then(() => { servant.createCommand(mockobjects.mockCommand, mockobjects.mockCommand.textReply);
dj.queue = [{ assert(servant.commands['test']);
'title': 'title', servant.removeCommand('test');
'url': 'http://www.youtube.com/watch?v=ABCDEFGHIJK'}, { assert(!servant.commands['test'])
'title': 'title',
'url': 'http://www.youtube.com/watch?v=ABCDEFGHIJK'}];
dj.clear();
assert(dj.queue.length === 0);
done();
}); });
})
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