Merge pull request #20 from Trivernis/test-configuration-2

Additional testscripts
pull/21/head
Trivernis 6 years ago committed by GitHub
commit 693a399f58
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -30,6 +30,10 @@ jobs:
name: Installing dependencies name: Installing dependencies
command: npm install command: npm install
- run:
name: installing additional dependencies
command: npm install sqlite3
- save_cache: - save_cache:
paths: paths:
- node_modules - node_modules
@ -42,4 +46,12 @@ jobs:
# run tests! # run tests!
- run: - run:
name: Testing ./lib/music name: Testing ./lib/music
command: node ./testscripts/musicTest.js command: node ./testscripts/musicTest.js
- run:
name: Testing ./lib/cmd
command: node ./testscripts/cmdTest.js
- run:
name: Testing ./lib/guilding
command: node ./testscripts/guildingTest.js

@ -0,0 +1,39 @@
const cmd = require("../lib/cmd.js"),
mockobjects = require("./mockobjects.js"),
servercmd = require('../commands/servercommands');
function main() {
cmd.setLogger(mockobjects.mockLogger);
console.log('Creating new servant instance');
let servant = new cmd.Servant('#');
console.log('registering all music commands...');
for (let [key, value] of Object.entries(servercmd.music)) {
servant.createCommand(value, () => {
console.log(` - invoked ${value.name} callback`);
});
}
console.log('parsing and deleting all music commands...');
for (let [key, value] of Object.entries(servercmd.music)) {
servant.parseCommand({
content: '#' + value.name,
author: {
tag: undefined
}
});
servant.removeCommand(value.name);
}
process.exit(0);
}
if (typeof require !== "undefined" && require.main === module) {
process.on("unhandledRejection", (reason, p) => {
console.error("Unhandled Rejection at: Promise", p, "reason:", reason);
throw Error("Promise rejection");
});
setTimeout(() => process.exit(1), 60000);
main();
}

@ -0,0 +1,44 @@
const guilding = require("../lib/guilding.js")
music = require("../lib/music.js"),
mockobjects = require("./mockobjects.js"),
servercmd = require("../commands/servercommands");
function main() {
guilding.setLogger(mockobjects.mockLogger);
music.setLogger(mockobjects.mockLogger);
console.log('Creating guildHandler instance');
let guildHandler = new guilding.GuildHandler('TEST', '#');
guildHandler.dj = new music.DJ(mockobjects.mockVoicechannel);
setTimeout(() => {
for (let [key, value] of Object.entries(servercmd.music)) {
guildHandler.handleMessage({
content: '#' + value.name + ' arg1 arg2 arg3 arg4',
author: {
tag: undefined,
id: 0,
createdTimestamp: new Date(),
username: 'TEST'
},
member: {
voiceChannel: mockobjects.mockVoicechannel
},
channel: mockobjects.mockChannel,
reply: mockobjects.mockChannel.send
});
}
guildHandler.destroy();
process.exit(0);
}, 1000);
}
if (typeof require !== "undefined" && require.main === module) {
process.on("unhandledRejection", (reason, p) => {
console.error("Unhandled Rejection at: Promise", p, "reason:", reason);
throw Error("Promise rejection");
});
setTimeout(() => process.exit(1), 60000);
main();
}

@ -1,9 +1,18 @@
exports.mockLogger = {
error: msg => raise(msg),
warn: msg => console.error("warn: ", msg),
warning: msg => console.error("warn: ", msg),
info: msg => console.log("info: ", msg),
verbose: msg => console.log("verbose: ", msg),
debug: msg => console.log("debug: ", msg)
};
exports.mockDispatcher = { exports.mockDispatcher = {
pause: () => console.log('pause();'), pause: () => console.log('Dispatcher.pause();'),
resume: () => console.log('resume();'), resume: () => console.log('Dispatcher.resume();'),
setVolume: (perc) => console.log(`setVolume(${perc});`), setVolume: (perc) => console.log(`Dispatcher.setVolume(${perc});`),
on: (event, callback) => console.log(`on(${event}, ${callback});`), on: (event, callback) => console.log(`Dispatcher.on(${event}, ${callback});`),
end: () => console.log('end();') end: () => console.log('Dispatcher.end();')
}; };
exports.mockConnection = { exports.mockConnection = {
@ -11,28 +20,32 @@ exports.mockConnection = {
members: { members: {
size: 10 size: 10
}, },
leave: () => console.log('leave();') leave: () => console.log('Connection.leave();')
}, },
status: 0, status: 0,
playFile: (fname) => { playFile: (fname) => {
console.log(`playFile(${fname});`); console.log(`Connection.playFile(${fname});`);
return exports.mockDispatcher; return exports.mockDispatcher;
}, },
playStream: (stream, opts) => { playStream: (stream, opts) => {
console.log(`playStream(ytdl, ${opts};`); console.log(`Connection.playStream(ytdl, ${opts};`);
return exports.mockDispatcher; return exports.mockDispatcher;
}, },
disconnect: () => console.log('disconnect();') disconnect: () => console.log('Connection.disconnect();')
}; };
exports.mockVoicechannel = { exports.mockVoicechannel = {
name: 'mockVoicechannel', name: 'mockVoicechannel',
join: () => { join: () => {
console.log('join();'); console.log('Voicechannel.join();');
return new Promise((rs, rj) => rs(exports.mockConnection)); return new Promise((rs, rj) => rs(exports.mockConnection));
}, },
members: { members: {
size: 10 size: 10
}, },
leave: () => console.log('leave();') leave: () => console.log('Voicechannel.leave();')
}; };
exports.mockChannel = {
send: (msg) => console.log('Send: ', msg)
}

@ -1,15 +1,9 @@
const music = require('../lib/music.js'), const music = require('../lib/music.js'),
mockclasses = require('./mockobjects.js'); mockobjects = require('./mockobjects.js');
function main() { function main() {
let dj = new music.DJ(mockclasses.mockVoicechannel) let dj = new music.DJ(mockobjects.mockVoicechannel)
music.setLogger({ music.setLogger(mockobjects.mockLogger);
error: () => {},
warn: () => {},
info: () => {},
verbose: () => {},
debug: () => {}
});
dj.connect().then(() => { dj.connect().then(() => {
console.log('connected', dj.connected); console.log('connected', dj.connected);
dj.playFile('test'); dj.playFile('test');
@ -20,8 +14,8 @@ function main() {
dj.skip(); dj.skip();
dj.stop(); dj.stop();
dj.shuffle(); dj.shuffle();
console.log(dj.playlist); console.log('dj.playlist: ', dj.playlist);
console.log(dj.song); console.log('dj.song: ', dj.song);
dj.clear(); dj.clear();
process.exit(0); process.exit(0);
}); });

Loading…
Cancel
Save