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
command: npm install
- run:
name: installing additional dependencies
command: npm install sqlite3
- save_cache:
paths:
- node_modules
@ -43,3 +47,11 @@ jobs:
- run:
name: Testing ./lib/music
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 = {
pause: () => console.log('pause();'),
resume: () => console.log('resume();'),
setVolume: (perc) => console.log(`setVolume(${perc});`),
on: (event, callback) => console.log(`on(${event}, ${callback});`),
end: () => console.log('end();')
pause: () => console.log('Dispatcher.pause();'),
resume: () => console.log('Dispatcher.resume();'),
setVolume: (perc) => console.log(`Dispatcher.setVolume(${perc});`),
on: (event, callback) => console.log(`Dispatcher.on(${event}, ${callback});`),
end: () => console.log('Dispatcher.end();')
};
exports.mockConnection = {
@ -11,28 +20,32 @@ exports.mockConnection = {
members: {
size: 10
},
leave: () => console.log('leave();')
leave: () => console.log('Connection.leave();')
},
status: 0,
playFile: (fname) => {
console.log(`playFile(${fname});`);
console.log(`Connection.playFile(${fname});`);
return exports.mockDispatcher;
},
playStream: (stream, opts) => {
console.log(`playStream(ytdl, ${opts};`);
console.log(`Connection.playStream(ytdl, ${opts};`);
return exports.mockDispatcher;
},
disconnect: () => console.log('disconnect();')
disconnect: () => console.log('Connection.disconnect();')
};
exports.mockVoicechannel = {
name: 'mockVoicechannel',
join: () => {
console.log('join();');
console.log('Voicechannel.join();');
return new Promise((rs, rj) => rs(exports.mockConnection));
},
members: {
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'),
mockclasses = require('./mockobjects.js');
mockobjects = require('./mockobjects.js');
function main() {
let dj = new music.DJ(mockclasses.mockVoicechannel)
music.setLogger({
error: () => {},
warn: () => {},
info: () => {},
verbose: () => {},
debug: () => {}
});
let dj = new music.DJ(mockobjects.mockVoicechannel)
music.setLogger(mockobjects.mockLogger);
dj.connect().then(() => {
console.log('connected', dj.connected);
dj.playFile('test');
@ -20,8 +14,8 @@ function main() {
dj.skip();
dj.stop();
dj.shuffle();
console.log(dj.playlist);
console.log(dj.song);
console.log('dj.playlist: ', dj.playlist);
console.log('dj.song: ', dj.song);
dj.clear();
process.exit(0);
});

Loading…
Cancel
Save