Add Tests for util.loadCommand if user doesn't have roles or userid
This commit is contained in:
parent
c816f182b2
commit
15b4a168df
4 changed files with 50 additions and 1 deletions
14
tests/commands/testingRoles.js
Normal file
14
tests/commands/testingRoles.js
Normal 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;
|
14
tests/commands/testingUsers.js
Normal file
14
tests/commands/testingUsers.js
Normal 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;
|
|
@ -3,5 +3,12 @@
|
|||
"author": {
|
||||
"bot": false
|
||||
},
|
||||
"content": "d!testing param1"
|
||||
"content": "d!testing param1",
|
||||
"member": {
|
||||
"roles": {
|
||||
"cache": [
|
||||
"NonRegular"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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');
|
||||
})
|
||||
});
|
||||
|
|
Reference in a new issue