diff --git a/.circleci/config.yml b/.circleci/config.yml index 270c801..9188ea1 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -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 @@ -42,4 +46,12 @@ jobs: # run tests! - run: name: Testing ./lib/music - command: node ./testscripts/musicTest.js \ No newline at end of file + 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 \ No newline at end of file diff --git a/testscripts/cmdTest.js b/testscripts/cmdTest.js new file mode 100644 index 0000000..eae8b1a --- /dev/null +++ b/testscripts/cmdTest.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(); +} \ No newline at end of file diff --git a/testscripts/guildingTest.js b/testscripts/guildingTest.js new file mode 100644 index 0000000..fcad9c1 --- /dev/null +++ b/testscripts/guildingTest.js @@ -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(); +} \ No newline at end of file diff --git a/testscripts/mockobjects.js b/testscripts/mockobjects.js index db66e94..86e7ed0 100644 --- a/testscripts/mockobjects.js +++ b/testscripts/mockobjects.js @@ -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();') -}; \ No newline at end of file + leave: () => console.log('Voicechannel.leave();') +}; + +exports.mockChannel = { + send: (msg) => console.log('Send: ', msg) +} \ No newline at end of file diff --git a/testscripts/musicTest.js b/testscripts/musicTest.js index fe9f801..1c90aab 100644 --- a/testscripts/musicTest.js +++ b/testscripts/musicTest.js @@ -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); });