From 249c711b53aaa43ebebe2abe749b0180fe3e145e Mon Sep 17 00:00:00 2001 From: Trivernis Date: Sat, 26 Jan 2019 17:13:54 +0100 Subject: [PATCH] Added Test - testing all servercommands in guilding --- test/test.js | 45 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 40 insertions(+), 5 deletions(-) diff --git a/test/test.js b/test/test.js index 9df1dc0..1149922 100644 --- a/test/test.js +++ b/test/test.js @@ -4,6 +4,14 @@ const mockobjects = require('./mockobjects.js'), rewire = require('rewire'); let Discord = require("discord.js"); +mockobjects.mockLogger = { + error: () => {}, + warn: () => {}, + info: () => {}, + verbose: () => {}, + debug: () => {} +}; + describe('lib/utils', function() { const utils = require('../lib/utils.js'); @@ -210,12 +218,11 @@ describe('lib/music', function() { let dj = new music.DJ(mockobjects.mockVoicechannel); dj.connect().then(() => { dj.playYouTube('http://www.youtube.com/watch?v=ABCDEFGHIJK'); + setTimeout(() => { + assert(dj.playing); + done(); + }, 100); }); - - setTimeout(() => { - assert(dj.playing); - done(); - }, 100); }); it('gets the video name', function (done) { @@ -350,6 +357,7 @@ describe('lib/cmd', function() { describe('lib/guilding', function() { const guilding = rewire('../lib/guilding'); + const servercommands = require('../commands/servercommands'); guilding.__set__("sqlite3", null); guilding.__set__("utils", { dirExistence: (file, callback) => { @@ -436,5 +444,32 @@ describe('lib/guilding', function() { done(); }) }); + + it('handles all servercommands', function() { + let gh = new guilding.GuildHandler('test', '~'); + gh.db = new mockobjects.MockDatabase('', ()=>{}); + gh.registerMusicCommands(); + gh.ready = true; + let msgSpy = sinon.spy(); + let msg = { + content: 'test', + author: { + tag: undefined + }, + reply: msgSpy, + channel: { + send: msgSpy + } + }; + + for (let category of Object.keys(servercommands)) { + for (let command of Object.keys(servercommands[category])) { + msg.content = '~' + command; + gh.handleMessage(msg); + } + } + + assert(msgSpy.called); + }); }); }); \ No newline at end of file