From 15b4a168df1d8443ebfbbe5f21e411a02ea6225c Mon Sep 17 00:00:00 2001 From: Vylpes Date: Sat, 13 Feb 2021 16:15:06 +0000 Subject: [PATCH] Add Tests for util.loadCommand if user doesn't have roles or userid --- tests/commands/testingRoles.js | 14 ++++++++++++++ tests/commands/testingUsers.js | 14 ++++++++++++++ tests/json/message.json | 9 ++++++++- tests/src/client/util.test.js | 14 ++++++++++++++ 4 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 tests/commands/testingRoles.js create mode 100644 tests/commands/testingUsers.js diff --git a/tests/commands/testingRoles.js b/tests/commands/testingRoles.js new file mode 100644 index 0000000..5b9da82 --- /dev/null +++ b/tests/commands/testingRoles.js @@ -0,0 +1,14 @@ +const { command } = require('../../src'); + +class test extends command { + constructor() { + super("test"); + super.roles = "Regular"; + } + + test(context) { + context.message.reply(`Testing done by ${context.config.tester}`); + } +} + +module.exports = test; \ No newline at end of file diff --git a/tests/commands/testingUsers.js b/tests/commands/testingUsers.js new file mode 100644 index 0000000..d146756 --- /dev/null +++ b/tests/commands/testingUsers.js @@ -0,0 +1,14 @@ +const { command } = require('../../src'); + +class test extends command { + constructor() { + super("test"); + super.users = "000000000000000001"; + } + + test(context) { + context.message.reply(`Testing done by ${context.config.tester}`); + } +} + +module.exports = test; \ No newline at end of file diff --git a/tests/json/message.json b/tests/json/message.json index d353f84..7b26052 100644 --- a/tests/json/message.json +++ b/tests/json/message.json @@ -3,5 +3,12 @@ "author": { "bot": false }, - "content": "d!testing param1" + "content": "d!testing param1", + "member": { + "roles": { + "cache": [ + "NonRegular" + ] + } + } } \ No newline at end of file diff --git a/tests/src/client/util.test.js b/tests/src/client/util.test.js index 51a372d..5d3b627 100644 --- a/tests/src/client/util.test.js +++ b/tests/src/client/util.test.js @@ -83,4 +83,18 @@ describe('util.loadCommand', () => { expect(res.valid).toBe(false); expect(res.message).toBe('Command folder does not exist'); }); + + test('Should throw error if user does not have required role', () => { + let res = instance.loadCommand('testingRoles', 'param1', message); + + expect(res.valid).toBe(false); + expect(res.message).toBe('You require the `Regular` role to run this command'); + }); + + test('Should throw error if user is not in users array', () => { + let res = instance.loadCommand('testingUsers', 'param1', message); + + expect(res.valid).toBe(false); + expect(res.message).toBe('You do not have permission to run this command'); + }) });