Compare commits
3 commits
main
...
feature/im
Author | SHA1 | Date | |
---|---|---|---|
|
21711c66ad | ||
|
893c0e1675 | ||
|
15b4a168df |
7 changed files with 114 additions and 3 deletions
|
@ -31,6 +31,8 @@ class event {
|
||||||
"message": message
|
"message": message
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Emit when bot is logged in and ready to use
|
// Emit when bot is logged in and ready to use
|
||||||
|
|
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": {
|
"author": {
|
||||||
"bot": false
|
"bot": false
|
||||||
},
|
},
|
||||||
"content": "d!testing param1"
|
"content": "d!testing param1",
|
||||||
|
"member": {
|
||||||
|
"roles": {
|
||||||
|
"cache": [
|
||||||
|
"NonRegular"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
const { client } = require('../../../src');
|
const { client } = require('../../../src');
|
||||||
const { readFileSync } = require('fs');
|
const { readFileSync } = require('fs');
|
||||||
|
const { expect } = require('@jest/globals');
|
||||||
|
|
||||||
// Mocks
|
// Mocks
|
||||||
jest.mock('discord.js');
|
jest.mock('discord.js');
|
||||||
|
@ -18,10 +19,27 @@ describe('Client Tests', () => {
|
||||||
instance = new client(config, commandConfig);
|
instance = new client(config, commandConfig);
|
||||||
|
|
||||||
expect(instance.config).toBe(config);
|
expect(instance.config).toBe(config);
|
||||||
|
expect(instance.commandConfig).toBe(commandConfig);
|
||||||
expect(instance.events).toBeDefined();
|
expect(instance.events).toBeDefined();
|
||||||
expect(instance.util).toBeDefined();
|
expect(instance.util).toBeDefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('Configure Client (Undefined: config)', () => {
|
||||||
|
expect(() => {
|
||||||
|
instance = new client(config, commandConfig);
|
||||||
|
instance._config = undefined;
|
||||||
|
instance.start();
|
||||||
|
}).toThrow("Config has not been set");
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Configure Client (Undefined: Command Config)', () => {
|
||||||
|
expect(() => {
|
||||||
|
instance = new client(config, commandConfig);
|
||||||
|
instance._commandConfig = undefined;
|
||||||
|
instance.start();
|
||||||
|
}).toThrow("Command Config has not been set");
|
||||||
|
});
|
||||||
|
|
||||||
test('Configure Client (Incorrect parameters: token)', () => {
|
test('Configure Client (Incorrect parameters: token)', () => {
|
||||||
expect(() => {
|
expect(() => {
|
||||||
delete config.token;
|
delete config.token;
|
||||||
|
@ -51,7 +69,9 @@ describe('Client Tests', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Start Client', () => {
|
test('Start Client', () => {
|
||||||
instance = new client(config, commandConfig);
|
expect(() => {
|
||||||
instance.start();
|
instance = new client(config, commandConfig);
|
||||||
|
instance.start();
|
||||||
|
}).not.toThrow();
|
||||||
});
|
});
|
||||||
});
|
});
|
|
@ -1,5 +1,6 @@
|
||||||
const events = require('../../../src/client/events');
|
const events = require('../../../src/client/events');
|
||||||
const { readFileSync } = require('fs');
|
const { readFileSync } = require('fs');
|
||||||
|
const { expect } = require('@jest/globals');
|
||||||
|
|
||||||
// Mocks
|
// Mocks
|
||||||
jest.mock('discord.js');
|
jest.mock('discord.js');
|
||||||
|
@ -86,4 +87,43 @@ describe('events.message', () => {
|
||||||
instance.message(message)
|
instance.message(message)
|
||||||
}).not.toThrow();
|
}).not.toThrow();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('Should return if message doesnt have prefix', () => {
|
||||||
|
message.content = "Just a normal message";
|
||||||
|
const res = instance.message(message);
|
||||||
|
|
||||||
|
expect(res).toBe(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('events.ready', () => {
|
||||||
|
let instance;
|
||||||
|
let message;
|
||||||
|
let config;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
instance = new events();
|
||||||
|
message = JSON.parse(readFileSync('tests/json/message.json'));
|
||||||
|
config = JSON.parse(readFileSync('tests/json/config.json'));
|
||||||
|
|
||||||
|
instance.config = config;
|
||||||
|
|
||||||
|
instance.util = jest.fn();
|
||||||
|
instance.util.loadCommand = jest.fn(() => {
|
||||||
|
return {
|
||||||
|
"valid": true,
|
||||||
|
"message": "No message was set"
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
console = jest.fn();
|
||||||
|
console.log = jest.fn();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Should log when ready', () => {
|
||||||
|
const res = instance.ready();
|
||||||
|
|
||||||
|
expect(console.log).toHaveBeenCalledTimes(1);
|
||||||
|
expect(console.log).toHaveBeenCalledWith("Ready");
|
||||||
|
});
|
||||||
});
|
});
|
|
@ -83,4 +83,18 @@ describe('util.loadCommand', () => {
|
||||||
expect(res.valid).toBe(false);
|
expect(res.valid).toBe(false);
|
||||||
expect(res.message).toBe('Command folder does not exist');
|
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