Add Tests for util.loadCommand if user doesn't have roles or userid

This commit is contained in:
Vylpes 2021-02-13 16:15:06 +00:00
parent c816f182b2
commit 15b4a168df
4 changed files with 50 additions and 1 deletions

View file

@ -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;

View file

@ -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;

View file

@ -3,5 +3,12 @@
"author": {
"bot": false
},
"content": "d!testing param1"
"content": "d!testing param1",
"member": {
"roles": {
"cache": [
"NonRegular"
]
}
}
}

View file

@ -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');
})
});