Latest dev sync
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
import { expect } from 'chai';
|
||||
import mocks from './mockImports.js';
|
||||
|
||||
const modulePath = '../commands/admin/addmod.js';
|
||||
let importedModule;
|
||||
|
||||
const mockPayload = {
|
||||
cmd: 'addmod',
|
||||
trip: 'newTrip',
|
||||
}
|
||||
|
||||
describe('Checking addmod module', () => {
|
||||
// module meta data
|
||||
it('should be importable', async () => {
|
||||
importedModule = await import(modulePath);
|
||||
expect(importedModule).to.not.be.a('string');
|
||||
});
|
||||
|
||||
it('should be named', async () => {
|
||||
expect(importedModule.info.name).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be categorized', async () => {
|
||||
expect(importedModule.info.category).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be described', async () => {
|
||||
expect(importedModule.info.description).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be documented', async () => {
|
||||
expect(importedModule.info.usage).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be invokable', async () => {
|
||||
expect(importedModule.run).to.be.a('function');
|
||||
});
|
||||
|
||||
// module main function
|
||||
it('should be invokable only by an admin', async () => {
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: mockPayload,
|
||||
});
|
||||
|
||||
expect(resp).to.be.false;
|
||||
});
|
||||
|
||||
it('should add new trip to the config', async () => {
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.authedSocket,
|
||||
payload: mockPayload,
|
||||
});
|
||||
|
||||
expect(mocks.core.appConfig.data.globalMods[0].trip).to.equal(mockPayload.trip);
|
||||
});
|
||||
|
||||
it('should inform the new mod', async () => {
|
||||
mocks.server.findSockets = () => {
|
||||
return [{}];
|
||||
}
|
||||
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.authedSocket,
|
||||
payload: mockPayload,
|
||||
});
|
||||
|
||||
mocks.core.appConfig.data.globalMods = [];
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,145 @@
|
||||
import { expect } from 'chai';
|
||||
import mocks from './mockImports.js';
|
||||
|
||||
const modulePath = '../commands/mod/ban.js';
|
||||
let importedModule;
|
||||
|
||||
const mockPayload = {
|
||||
cmd: 'ban',
|
||||
userid: 1234,
|
||||
}
|
||||
|
||||
describe('Checking ban module', () => {
|
||||
// module meta data
|
||||
it('should be importable', async () => {
|
||||
importedModule = await import(modulePath);
|
||||
expect(importedModule).to.not.be.a('string');
|
||||
});
|
||||
|
||||
it('should be named', async () => {
|
||||
expect(importedModule.info.name).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be categorized', async () => {
|
||||
expect(importedModule.info.category).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be described', async () => {
|
||||
expect(importedModule.info.description).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be documented', async () => {
|
||||
expect(importedModule.info.usage).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be invokable', async () => {
|
||||
expect(importedModule.run).to.be.a('function');
|
||||
});
|
||||
|
||||
// module main function
|
||||
it('should be invokable only by a mod', async () => {
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: mockPayload,
|
||||
});
|
||||
|
||||
expect(resp).to.be.false;
|
||||
});
|
||||
|
||||
it('should check for invalid legacy params', async () => {
|
||||
mocks.authedSocket.hcProtocol = 1;
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.authedSocket,
|
||||
payload: mockPayload,
|
||||
});
|
||||
|
||||
expect(resp).to.be.false;
|
||||
});
|
||||
|
||||
it('should verify legacy params', async () => {
|
||||
mocks.authedSocket.hcProtocol = 1;
|
||||
mockPayload.nick = 5431;
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.authedSocket,
|
||||
payload: mockPayload,
|
||||
});
|
||||
|
||||
expect(resp).to.be.false;
|
||||
});
|
||||
|
||||
it('should accept legacy params', async () => {
|
||||
mocks.authedSocket.hcProtocol = 1;
|
||||
mockPayload.nick = 'lies';
|
||||
mocks.server.findSockets = (filterObj) => {
|
||||
return false;
|
||||
}
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.authedSocket,
|
||||
payload: mockPayload,
|
||||
});
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
|
||||
it('should check for invalid params', async () => {
|
||||
mocks.authedSocket.hcProtocol = 2;
|
||||
mockPayload.userid = 'test';
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.authedSocket,
|
||||
payload: mockPayload,
|
||||
});
|
||||
|
||||
expect(resp).to.be.false;
|
||||
});
|
||||
|
||||
it('should not ban mods', async () => {
|
||||
mocks.authedSocket.hcProtocol = 2;
|
||||
mockPayload.userid = 1234;
|
||||
|
||||
mocks.server.findSockets = (filterObj) => {
|
||||
return [mocks.authedSocket];
|
||||
}
|
||||
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.authedSocket,
|
||||
payload: mockPayload,
|
||||
});
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
|
||||
it('should blacklist the ip', async () => {
|
||||
mocks.authedSocket.hcProtocol = 2;
|
||||
mockPayload.userid = 1234;
|
||||
|
||||
mocks.server.findSockets = (filterObj) => {
|
||||
if (typeof filterObj.level === 'function') {
|
||||
filterObj.level();
|
||||
}
|
||||
|
||||
return [mocks.plebSocket];
|
||||
}
|
||||
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.authedSocket,
|
||||
payload: mockPayload,
|
||||
});
|
||||
|
||||
expect(mocks.server.police.addresses[0]).to.be.a('string');
|
||||
});
|
||||
|
||||
});
|
||||
@@ -0,0 +1,126 @@
|
||||
import { expect } from 'chai';
|
||||
import mocks from './mockImports.js';
|
||||
|
||||
const modulePath = '../commands/core/changecolor.js';
|
||||
let importedModule;
|
||||
|
||||
const mockPayload = {
|
||||
cmd: 'changecolor',
|
||||
color: '#000000',
|
||||
}
|
||||
|
||||
describe('Checking changecolor module', () => {
|
||||
// module meta data
|
||||
it('should be importable', async () => {
|
||||
importedModule = await import(modulePath);
|
||||
expect(importedModule).to.not.be.a('string');
|
||||
});
|
||||
|
||||
it('should be named', async () => {
|
||||
expect(importedModule.info.name).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be categorized', async () => {
|
||||
expect(importedModule.info.category).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be described', async () => {
|
||||
expect(importedModule.info.description).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be documented', async () => {
|
||||
expect(importedModule.info.usage).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be invokable', async () => {
|
||||
expect(importedModule.run).to.be.a('function');
|
||||
});
|
||||
|
||||
// module main function
|
||||
it('should ratelimit if required', async () => {
|
||||
const oldRL = mocks.server.police.frisk;
|
||||
mocks.server.police.frisk = () => true;
|
||||
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: mockPayload,
|
||||
});
|
||||
|
||||
mocks.server.police.frisk = oldRL;
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
|
||||
it('should be invokable by all', async () => {
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: mockPayload,
|
||||
});
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
|
||||
it('should check for invalid color type', async () => {
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: {
|
||||
cmd: 'changecolor',
|
||||
color: false,
|
||||
},
|
||||
});
|
||||
|
||||
expect(resp).to.be.false;
|
||||
});
|
||||
|
||||
it('should check for invalid color', async () => {
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: {
|
||||
cmd: 'changecolor',
|
||||
color: 'This is an invalid color',
|
||||
},
|
||||
});
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
|
||||
it('should allow a color reset', async () => {
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: {
|
||||
cmd: 'changecolor',
|
||||
color: 'reset',
|
||||
},
|
||||
});
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
|
||||
it('should initialize hooks', async () => {
|
||||
expect(() => importedModule.initHooks(mocks.server)).not.to.throw();
|
||||
});
|
||||
|
||||
it('should hook chat text to register /color', async () => {
|
||||
const resp = importedModule.colorCheck({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: {
|
||||
cmd: 'changecolor',
|
||||
color: 'reset',
|
||||
},
|
||||
});
|
||||
|
||||
expect(resp).to.be.false;
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,253 @@
|
||||
import { expect } from 'chai';
|
||||
import mocks from './mockImports.js';
|
||||
|
||||
const modulePath = '../commands/core/changenick.js';
|
||||
let importedModule;
|
||||
|
||||
const mockPayload = {
|
||||
cmd: 'changenick',
|
||||
nick: 'newNick',
|
||||
}
|
||||
|
||||
describe('Checking changenick module', () => {
|
||||
// module meta data
|
||||
it('should be importable', async () => {
|
||||
importedModule = await import(modulePath);
|
||||
expect(importedModule).to.not.be.a('string');
|
||||
});
|
||||
|
||||
it('should be named', async () => {
|
||||
expect(importedModule.info.name).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be categorized', async () => {
|
||||
expect(importedModule.info.category).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be described', async () => {
|
||||
expect(importedModule.info.description).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be documented', async () => {
|
||||
expect(importedModule.info.usage).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be invokable', async () => {
|
||||
expect(importedModule.run).to.be.a('function');
|
||||
});
|
||||
|
||||
// module main function
|
||||
it('should ratelimit if required', async () => {
|
||||
const oldRL = mocks.server.police.frisk;
|
||||
mocks.server.police.frisk = () => true;
|
||||
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: mockPayload,
|
||||
});
|
||||
|
||||
mocks.server.police.frisk = oldRL;
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
|
||||
it('should validate nick param', async () => {
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: {
|
||||
cmd: 'changenick',
|
||||
nick: 1234,
|
||||
},
|
||||
});
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
|
||||
it('should verify nick param', async () => {
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: {
|
||||
cmd: 'changenick',
|
||||
nick: 'this is invalid',
|
||||
},
|
||||
});
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
|
||||
it('should be invokable by all', async () => {
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: mockPayload,
|
||||
});
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
|
||||
it('should prevent admin impersonation', async () => {
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: {
|
||||
cmd: 'changenick',
|
||||
nick: 'admin',
|
||||
},
|
||||
});
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
|
||||
it('should not update if there is no change', async () => {
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: {
|
||||
cmd: 'changenick',
|
||||
nick: 'lies',
|
||||
},
|
||||
});
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
|
||||
it('should allow them to change case', async () => {
|
||||
const origFindSockets = mocks.server.findSockets;
|
||||
mocks.server.findSockets = (filterObj) => {
|
||||
if (typeof filterObj.nick === 'function') {
|
||||
filterObj.nick('lies');
|
||||
}
|
||||
|
||||
return [mocks.plebSocket];
|
||||
}
|
||||
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: {
|
||||
cmd: 'changenick',
|
||||
nick: 'Lies',
|
||||
},
|
||||
});
|
||||
|
||||
mocks.server.findSockets = origFindSockets;
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
|
||||
it('should not update if that nick exists', async () => {
|
||||
const origFindSockets = mocks.server.findSockets;
|
||||
mocks.server.findSockets = (filterObj) => {
|
||||
if (typeof filterObj.nick === 'function') {
|
||||
filterObj.nick('lies');
|
||||
}
|
||||
|
||||
return [mocks.plebSocket];
|
||||
}
|
||||
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: mockPayload,
|
||||
});
|
||||
|
||||
mocks.server.findSockets = origFindSockets;
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
|
||||
it('should output new user details to the channel', async () => {
|
||||
const origFindSockets = mocks.server.findSockets;
|
||||
const legacySocket = Object.assign({}, mocks.plebSocket);
|
||||
legacySocket.hcProtocol = 1;
|
||||
mocks.server.findSockets = (data) => {
|
||||
if (typeof data.nick !== 'undefined' ) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return [mocks.plebSocket, legacySocket];
|
||||
}
|
||||
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: mockPayload,
|
||||
});
|
||||
|
||||
mocks.server.findSockets = origFindSockets;
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
|
||||
it('should initialize hooks', async () => {
|
||||
expect(() => importedModule.initHooks(mocks.server)).not.to.throw();
|
||||
});
|
||||
|
||||
it('should hook should validate text input', async () => {
|
||||
const resp = importedModule.nickCheck({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: {
|
||||
cmd: 'chat',
|
||||
text: false,
|
||||
},
|
||||
});
|
||||
|
||||
expect(resp).to.be.false;
|
||||
});
|
||||
|
||||
it('should hook should verify text starts with /nick', async () => {
|
||||
const resp = importedModule.nickCheck({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: {
|
||||
cmd: 'chat',
|
||||
text: 'No slash command',
|
||||
},
|
||||
});
|
||||
|
||||
expect(resp).to.be.an('object');
|
||||
});
|
||||
|
||||
it('should hook should run with /nick', async () => {
|
||||
const resp = importedModule.nickCheck({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: {
|
||||
cmd: 'chat',
|
||||
text: '/nick test',
|
||||
},
|
||||
});
|
||||
|
||||
expect(resp).to.be.false;
|
||||
});
|
||||
|
||||
it('should hook fail on mangled input', async () => {
|
||||
const resp = importedModule.nickCheck({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: {
|
||||
cmd: 'chat',
|
||||
text: '/nick ',
|
||||
},
|
||||
});
|
||||
|
||||
expect(resp).to.be.false;
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,65 @@
|
||||
import { expect } from 'chai';
|
||||
import mocks from './mockImports.js';
|
||||
|
||||
const modulePath = '../commands/utility/_Channels.js';
|
||||
let importedModule;
|
||||
|
||||
describe('Checking channels module', () => {
|
||||
it('should be importable', async () => {
|
||||
importedModule = await import(modulePath);
|
||||
expect(importedModule).to.not.be.a('string');
|
||||
});
|
||||
|
||||
it('should reject empty channels', async () => {
|
||||
const resp = importedModule.canJoinChannel('', {});
|
||||
expect(resp).to.be.a('number');
|
||||
});
|
||||
|
||||
it('should reject too long of channels', async () => {
|
||||
const resp = importedModule.canJoinChannel('a'.repeat(121), {});
|
||||
expect(resp).to.be.a('number');
|
||||
});
|
||||
|
||||
it('should get channel data', async () => {
|
||||
const newConfig = Object.assign({}, mocks.core.appConfig.data);
|
||||
newConfig.permissions['test'] = {};
|
||||
const resp = importedModule.getChannelSettings(mocks.core.appConfig.data, 'test');
|
||||
expect(resp).to.be.an('object');
|
||||
});
|
||||
|
||||
it('should return empty array findUsers', async () => {
|
||||
const resp = importedModule.findUsers({}, {});
|
||||
expect(resp).to.be.an('array');
|
||||
});
|
||||
|
||||
it('should limit results', async () => {
|
||||
const oldFS = mocks.server.findSockets;
|
||||
mocks.server.findSockets = (filterObj) => {
|
||||
return [1, 2, 3];
|
||||
}
|
||||
const resp = importedModule.findUsers(mocks.server, {
|
||||
userid: 1234,
|
||||
}, 1);
|
||||
|
||||
mocks.server.findSockets = oldFS;
|
||||
|
||||
expect(resp).to.be.an('array');
|
||||
});
|
||||
|
||||
it('should respond to banned sockets', async () => {
|
||||
const newSocket = Object.assign({}, mocks.plebSocket);
|
||||
newSocket.banned = true;
|
||||
|
||||
const resp = importedModule.canJoinChannel('test', newSocket);
|
||||
|
||||
expect(resp).to.be.an('number');
|
||||
});
|
||||
|
||||
it('should provide duplicate user checks', async () => {
|
||||
const newSocket = Object.assign({}, mocks.plebSocket);
|
||||
|
||||
const resp = importedModule.socketInChannel(mocks.server, 'test', newSocket);
|
||||
|
||||
expect(resp).to.be.an('object');
|
||||
});
|
||||
})
|
||||
@@ -0,0 +1,198 @@
|
||||
import { expect } from 'chai';
|
||||
import mocks from './mockImports.js';
|
||||
|
||||
const modulePath = '../commands/core/chat.js';
|
||||
let importedModule;
|
||||
|
||||
const mockPayload = {
|
||||
cmd: 'chat',
|
||||
channel: 'cake',
|
||||
text: 'testing',
|
||||
}
|
||||
|
||||
describe('Checking chat module', () => {
|
||||
// module meta data
|
||||
it('should be importable', async () => {
|
||||
importedModule = await import(modulePath);
|
||||
expect(importedModule).to.not.be.a('string');
|
||||
});
|
||||
|
||||
it('should be named', async () => {
|
||||
expect(importedModule.info.name).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be categorized', async () => {
|
||||
expect(importedModule.info.category).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be described', async () => {
|
||||
expect(importedModule.info.description).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be documented', async () => {
|
||||
expect(importedModule.info.usage).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be invokable', async () => {
|
||||
expect(importedModule.run).to.be.a('function');
|
||||
});
|
||||
|
||||
// module main function
|
||||
it('should be invokable by all', async () => {
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: mockPayload,
|
||||
});
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
|
||||
it('should ratelimit on invalid text', async () => {
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: {
|
||||
cmd: 'chat',
|
||||
channel: 'cake',
|
||||
text: [],
|
||||
},
|
||||
});
|
||||
|
||||
expect(resp).to.be.false;
|
||||
});
|
||||
|
||||
it('should ratelimit if required', async () => {
|
||||
const oldRL = mocks.server.police.frisk;
|
||||
mocks.server.police.frisk = () => true;
|
||||
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: mockPayload,
|
||||
});
|
||||
|
||||
mocks.server.police.frisk = oldRL;
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
|
||||
it('should add sender admin label', async () => {
|
||||
const newSocket = Object.assign({}, mocks.authedSocket);
|
||||
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: newSocket,
|
||||
payload: mockPayload,
|
||||
});
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
|
||||
it('should add sender mod label', async () => {
|
||||
const newSocket = Object.assign({}, mocks.authedSocket);
|
||||
newSocket.level = 999999;
|
||||
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: newSocket,
|
||||
payload: mockPayload,
|
||||
});
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
|
||||
it('should add color', async () => {
|
||||
const newSocket = Object.assign({}, mocks.plebSocket);
|
||||
newSocket.color = '000000';
|
||||
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: newSocket,
|
||||
payload: mockPayload,
|
||||
});
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
|
||||
it('should initialize hooks', async () => {
|
||||
expect(() => importedModule.initHooks(mocks.server)).not.to.throw();
|
||||
});
|
||||
|
||||
it('should hook for / based commands', async () => {
|
||||
const resp = importedModule.commandCheckIn({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: mockPayload,
|
||||
});
|
||||
|
||||
expect(resp).to.be.an('object');
|
||||
});
|
||||
|
||||
it('should validate hook text param', async () => {
|
||||
const resp = importedModule.commandCheckIn({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: {
|
||||
cmd: 'chat',
|
||||
channel: 'cake',
|
||||
text: false,
|
||||
},
|
||||
});
|
||||
|
||||
expect(resp).to.be.false;
|
||||
});
|
||||
|
||||
it('should hook for /myhash', async () => {
|
||||
const resp = importedModule.commandCheckIn({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: {
|
||||
cmd: 'chat',
|
||||
channel: 'cake',
|
||||
text: '/myhash',
|
||||
},
|
||||
});
|
||||
|
||||
expect(resp).to.be.false;
|
||||
});
|
||||
|
||||
it('should hook for failed / commands, validating text input', async () => {
|
||||
const resp = importedModule.finalCmdCheck({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: {
|
||||
cmd: 'chat',
|
||||
channel: 'cake',
|
||||
text: false,
|
||||
},
|
||||
});
|
||||
|
||||
expect(resp).to.be.false;
|
||||
});
|
||||
|
||||
it('should final hook should ignore if input doesnt start with /', async () => {
|
||||
const resp = importedModule.finalCmdCheck({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: {
|
||||
cmd: 'chat',
|
||||
channel: 'cake',
|
||||
text: 'test',
|
||||
},
|
||||
});
|
||||
|
||||
expect(resp).to.be.an('object');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,80 @@
|
||||
import { expect } from 'chai';
|
||||
import mocks from './mockImports.js';
|
||||
|
||||
const modulePath = '../commands/internal/disconnect.js';
|
||||
let importedModule;
|
||||
|
||||
const mockPayload = {
|
||||
cmd: 'disconnect',
|
||||
}
|
||||
|
||||
describe('Checking disconnect module', () => {
|
||||
// module meta data
|
||||
it('should be importable', async () => {
|
||||
importedModule = await import(modulePath);
|
||||
expect(importedModule).to.not.be.a('string');
|
||||
});
|
||||
|
||||
it('should be named', async () => {
|
||||
expect(importedModule.info.name).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be categorized', async () => {
|
||||
expect(importedModule.info.category).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be described', async () => {
|
||||
expect(importedModule.info.description).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be documented', async () => {
|
||||
expect(importedModule.info.usage).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be invokable', async () => {
|
||||
expect(importedModule.run).to.be.a('function');
|
||||
});
|
||||
|
||||
// module main function
|
||||
it('should be invokable only internally', async () => {
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: mockPayload,
|
||||
});
|
||||
|
||||
expect(resp).to.be.false;
|
||||
});
|
||||
|
||||
it('should broadcast online remove event', async () => {
|
||||
mockPayload.cmdKey = 'test';
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: mockPayload,
|
||||
});
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
|
||||
it('should not broadcast online remove event if there is a duplicate', async () => {
|
||||
const origFindSockets = mocks.server.findSockets;
|
||||
mocks.server.findSockets = (data) => {
|
||||
return [];
|
||||
}
|
||||
|
||||
mockPayload.cmdKey = 'test';
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: mockPayload,
|
||||
});
|
||||
|
||||
mocks.server.findSockets = origFindSockets;
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,366 @@
|
||||
import { expect } from 'chai';
|
||||
import mocks from './mockImports.js';
|
||||
|
||||
const modulePath = '../commands/mod/dumb.js';
|
||||
let importedModule;
|
||||
|
||||
const mockPayload = {
|
||||
cmd: 'dumb',
|
||||
nick: 'nick',
|
||||
channel: 'cake',
|
||||
userid: 1234,
|
||||
allies: [],
|
||||
}
|
||||
|
||||
describe('Checking dumb module', () => {
|
||||
// module meta data
|
||||
it('should be importable', async () => {
|
||||
importedModule = await import(modulePath);
|
||||
expect(importedModule).to.not.be.a('string');
|
||||
});
|
||||
|
||||
it('should be named', async () => {
|
||||
expect(importedModule.info.name).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be categorized', async () => {
|
||||
expect(importedModule.info.category).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be described', async () => {
|
||||
expect(importedModule.info.description).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be documented', async () => {
|
||||
expect(importedModule.info.usage).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be invokable', async () => {
|
||||
expect(importedModule.run).to.be.a('function');
|
||||
});
|
||||
|
||||
// module export functions
|
||||
it('should export a random channel function', async () => {
|
||||
const resp = importedModule.getChannel();
|
||||
|
||||
expect(resp).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should export a common channel function', async () => {
|
||||
const resp = importedModule.getChannel('common');
|
||||
|
||||
expect(resp).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should initialize', async () => {
|
||||
mocks.core.muzzledHashes = undefined;
|
||||
const resp = importedModule.init(mocks.core);
|
||||
|
||||
expect(mocks.core.muzzledHashes).to.be.an('object');
|
||||
});
|
||||
|
||||
it('should initialize hooks', async () => {
|
||||
expect(() => importedModule.initHooks(mocks.server)).not.to.throw();
|
||||
});
|
||||
|
||||
// module main function
|
||||
it('should be invokable only by a mod', async () => {
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: mockPayload,
|
||||
});
|
||||
|
||||
expect(resp).to.be.false;
|
||||
});
|
||||
|
||||
it('should shadow block whisper attempts', async () => {
|
||||
mocks.core.muzzledHashes['testHash'] = true;
|
||||
mocks.plebSocket.hcProtocol = 1;
|
||||
|
||||
const resp = importedModule.whisperCheck({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: {
|
||||
cmd: 'whisper',
|
||||
text: [],
|
||||
channel: 'cake',
|
||||
},
|
||||
});
|
||||
|
||||
expect(resp).to.be.false;
|
||||
});
|
||||
|
||||
it('should shadow block chat attempts, validating input', async () => {
|
||||
mocks.core.muzzledHashes['testHash'] = true;
|
||||
mocks.plebSocket.hcProtocol = 1;
|
||||
|
||||
const resp = importedModule.chatCheck({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: {
|
||||
cmd: 'chat',
|
||||
text: [],
|
||||
channel: 'cake',
|
||||
},
|
||||
});
|
||||
|
||||
expect(resp).to.be.false;
|
||||
});
|
||||
|
||||
it('should shadow block chat attempts', async () => {
|
||||
mocks.core.muzzledHashes['testHash'] = true;
|
||||
mocks.plebSocket.hcProtocol = 1;
|
||||
|
||||
const resp = importedModule.chatCheck({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: {
|
||||
cmd: 'chat',
|
||||
text: 'test',
|
||||
channel: 'cake',
|
||||
},
|
||||
});
|
||||
|
||||
expect(resp).to.be.false;
|
||||
});
|
||||
|
||||
it('should shadow block chat attempts, checking for trips', async () => {
|
||||
mocks.core.muzzledHashes['testHash'] = true;
|
||||
mocks.plebSocket.hcProtocol = 1;
|
||||
const newSocket = Object.assign({}, mocks.plebSocket);
|
||||
newSocket.trip = 'test';
|
||||
|
||||
const resp = importedModule.chatCheck({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: newSocket,
|
||||
payload: {
|
||||
cmd: 'chat',
|
||||
text: 'test',
|
||||
channel: 'cake',
|
||||
},
|
||||
});
|
||||
|
||||
expect(resp).to.be.false;
|
||||
});
|
||||
|
||||
it('should shadow block chat attempts, checking for color', async () => {
|
||||
mocks.core.muzzledHashes['testHash'] = true;
|
||||
mocks.plebSocket.hcProtocol = 1;
|
||||
const newSocket = Object.assign({}, mocks.plebSocket);
|
||||
newSocket.color = '000000';
|
||||
|
||||
const resp = importedModule.chatCheck({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: newSocket,
|
||||
payload: {
|
||||
cmd: 'chat',
|
||||
text: 'test',
|
||||
channel: 'cake',
|
||||
},
|
||||
});
|
||||
|
||||
expect(resp).to.be.false;
|
||||
});
|
||||
|
||||
it('should shadow block chat attempts, checking for allies', async () => {
|
||||
mocks.core.muzzledHashes['testHash'] = {
|
||||
dumb: true,
|
||||
allies: [1234],
|
||||
};
|
||||
mocks.plebSocket.hcProtocol = 1;
|
||||
const newSocket = Object.assign({}, mocks.plebSocket);
|
||||
|
||||
const resp = importedModule.chatCheck({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: newSocket,
|
||||
payload: {
|
||||
cmd: 'chat',
|
||||
text: 'test',
|
||||
channel: 'cake',
|
||||
},
|
||||
});
|
||||
|
||||
expect(resp).to.be.false;
|
||||
});
|
||||
|
||||
it('should shadow block invite attempts', async () => {
|
||||
mocks.core.muzzledHashes['testHash'] = true;
|
||||
mocks.plebSocket.hcProtocol = 1;
|
||||
|
||||
const resp = importedModule.inviteCheck({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: {
|
||||
cmd: 'chat',
|
||||
text: [],
|
||||
channel: 'cake',
|
||||
},
|
||||
});
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
|
||||
it('should shadow block invite attempts with ratelimiting', async () => {
|
||||
const oldRL = mocks.server.police.frisk;
|
||||
mocks.server.police.frisk = () => true;
|
||||
|
||||
mocks.core.muzzledHashes['testHash'] = true;
|
||||
mocks.plebSocket.hcProtocol = 1;
|
||||
|
||||
const resp = importedModule.inviteCheck({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: {
|
||||
cmd: 'chat',
|
||||
text: [],
|
||||
channel: 'cake',
|
||||
},
|
||||
});
|
||||
|
||||
mocks.server.police.frisk = oldRL;
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
|
||||
it('should verify userid params on shadow block invite attempts', async () => {
|
||||
mocks.core.muzzledHashes['testHash'] = true;
|
||||
mocks.plebSocket.hcProtocol = 2;
|
||||
|
||||
const resp = importedModule.inviteCheck({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: {
|
||||
cmd: 'chat',
|
||||
userid: '1234',
|
||||
text: [],
|
||||
channel: 'cake',
|
||||
},
|
||||
});
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
|
||||
it('should verify channel params on shadow block invite attempts', async () => {
|
||||
mocks.core.muzzledHashes['testHash'] = true;
|
||||
mocks.plebSocket.hcProtocol = 2;
|
||||
|
||||
const resp = importedModule.inviteCheck({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: {
|
||||
cmd: 'chat',
|
||||
userid: 1234,
|
||||
text: [],
|
||||
channel: false,
|
||||
},
|
||||
});
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
|
||||
it('should accept an allies param', async () => {
|
||||
mockPayload.allies = [1234, 5678];
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.authedSocket,
|
||||
payload: mockPayload,
|
||||
});
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
|
||||
it('should accept legacy params', async () => {
|
||||
const newSocket = Object.assign({}, mocks.authedSocket);
|
||||
newSocket.hcProtocol = 1;
|
||||
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: newSocket,
|
||||
payload: {
|
||||
cmd: 'dumb',
|
||||
nick: false,
|
||||
},
|
||||
});
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
|
||||
it('should accept params', async () => {
|
||||
const newSocket = Object.assign({}, mocks.authedSocket);
|
||||
newSocket.hcProtocol = 2;
|
||||
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: newSocket,
|
||||
payload: {
|
||||
cmd: 'dumb',
|
||||
userid : false,
|
||||
},
|
||||
});
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
|
||||
it('should handle users not found', async () => {
|
||||
const newSocket = Object.assign({}, mocks.authedSocket);
|
||||
newSocket.hcProtocol = 2;
|
||||
|
||||
const oldFS = mocks.server.findSockets;
|
||||
mocks.server.findSockets = (filterObj) => {
|
||||
return false;
|
||||
}
|
||||
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: newSocket,
|
||||
payload: {
|
||||
cmd: 'dumb',
|
||||
userid : 0,
|
||||
},
|
||||
});
|
||||
|
||||
mocks.server.findSockets = oldFS;
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
|
||||
it('should not muzzle mods', async () => {
|
||||
const newSocket = Object.assign({}, mocks.authedSocket);
|
||||
newSocket.hcProtocol = 2;
|
||||
|
||||
const oldFS = mocks.server.findSockets;
|
||||
mocks.server.findSockets = (filterObj) => {
|
||||
return [newSocket];
|
||||
}
|
||||
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: newSocket,
|
||||
payload: {
|
||||
cmd: 'dumb',
|
||||
userid : 0,
|
||||
},
|
||||
});
|
||||
|
||||
mocks.server.findSockets = oldFS;
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,113 @@
|
||||
import { expect } from 'chai';
|
||||
import mocks from './mockImports.js';
|
||||
|
||||
const modulePath = '../commands/core/emote.js';
|
||||
let importedModule;
|
||||
|
||||
const mockPayload = {
|
||||
cmd: 'emote',
|
||||
channel: 'cake',
|
||||
text: 'testing',
|
||||
}
|
||||
|
||||
describe('Checking emote module', () => {
|
||||
// module meta data
|
||||
it('should be importable', async () => {
|
||||
importedModule = await import(modulePath);
|
||||
expect(importedModule).to.not.be.a('string');
|
||||
});
|
||||
|
||||
it('should be named', async () => {
|
||||
expect(importedModule.info.name).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be categorized', async () => {
|
||||
expect(importedModule.info.category).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be described', async () => {
|
||||
expect(importedModule.info.description).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be documented', async () => {
|
||||
expect(importedModule.info.usage).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be invokable', async () => {
|
||||
expect(importedModule.run).to.be.a('function');
|
||||
});
|
||||
|
||||
// module main function
|
||||
it('should be invokable by all', async () => {
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: mockPayload,
|
||||
});
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
|
||||
it('should not accept empty text', async () => {
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: {
|
||||
cmd: 'emote',
|
||||
text: false,
|
||||
},
|
||||
});
|
||||
|
||||
expect(resp).to.be.false;
|
||||
});
|
||||
|
||||
it('should ratelimit if required', async () => {
|
||||
const oldRL = mocks.server.police.frisk;
|
||||
mocks.server.police.frisk = () => true;
|
||||
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: mockPayload,
|
||||
});
|
||||
|
||||
mocks.server.police.frisk = oldRL;
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
|
||||
it('should include a users trip', async () => {
|
||||
const newSocket = Object.assign({}, mocks.authedSocket);
|
||||
newSocket.trip = 'test';
|
||||
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: newSocket,
|
||||
payload: mockPayload,
|
||||
});
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
|
||||
it('should initialize hooks', async () => {
|
||||
expect(() => importedModule.initHooks(mocks.server)).not.to.throw();
|
||||
});
|
||||
|
||||
it('should hook a /me text command, verifying params', async () => {
|
||||
const resp = importedModule.emoteCheck({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.authedSocket,
|
||||
payload: {
|
||||
cmd: 'chat',
|
||||
text: false,
|
||||
},
|
||||
});
|
||||
|
||||
expect(resp).to.be.false;
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,194 @@
|
||||
import { expect } from 'chai';
|
||||
import mocks from './mockImports.js';
|
||||
|
||||
const modulePath = '../commands/mod/forcecolor.js';
|
||||
let importedModule;
|
||||
|
||||
const mockPayload = {
|
||||
cmd: 'forcecolor',
|
||||
userid: 1234,
|
||||
color: '#000000',
|
||||
}
|
||||
|
||||
describe('Checking forcecolor module', () => {
|
||||
// module meta data
|
||||
it('should be importable', async () => {
|
||||
importedModule = await import(modulePath);
|
||||
expect(importedModule).to.not.be.a('string');
|
||||
});
|
||||
|
||||
it('should be named', async () => {
|
||||
expect(importedModule.info.name).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be categorized', async () => {
|
||||
expect(importedModule.info.category).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be described', async () => {
|
||||
expect(importedModule.info.description).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be documented', async () => {
|
||||
expect(importedModule.info.usage).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be invokable', async () => {
|
||||
expect(importedModule.run).to.be.a('function');
|
||||
});
|
||||
|
||||
// module main function
|
||||
it('should be invokable only by a mod', async () => {
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: mockPayload,
|
||||
});
|
||||
|
||||
expect(resp).to.be.false;
|
||||
});
|
||||
|
||||
it('should check for invalid nick', async () => {
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.authedSocket,
|
||||
payload: {
|
||||
cmd: 'changecolor',
|
||||
nick: false,
|
||||
color: false,
|
||||
},
|
||||
});
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
|
||||
it('should check for invalid color', async () => {
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.authedSocket,
|
||||
payload: {
|
||||
cmd: 'changecolor',
|
||||
nick: 'lies',
|
||||
color: false,
|
||||
},
|
||||
});
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
|
||||
it('should check accept color reset', async () => {
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.authedSocket,
|
||||
payload: {
|
||||
cmd: 'changecolor',
|
||||
nick: 'lies',
|
||||
color: 'reset',
|
||||
},
|
||||
});
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
|
||||
it('should check accept color', async () => {
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.authedSocket,
|
||||
payload: {
|
||||
cmd: 'changecolor',
|
||||
nick: 'lies',
|
||||
color: 'invalid color',
|
||||
},
|
||||
});
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
|
||||
it('should handle users not found', async () => {
|
||||
const oldFS = mocks.server.findSockets;
|
||||
mocks.server.findSockets = (filterObj) => {
|
||||
return false;
|
||||
}
|
||||
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.authedSocket,
|
||||
payload: {
|
||||
cmd: 'changecolor',
|
||||
nick: 'lies',
|
||||
color: '#000000',
|
||||
},
|
||||
});
|
||||
|
||||
mocks.server.findSockets = oldFS;
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
|
||||
it('should alert to invalid user', async () => {
|
||||
const oldFS = mocks.server.findSockets;
|
||||
mocks.server.findSockets = (filterObj) => {
|
||||
return [mocks.plebSocket];
|
||||
}
|
||||
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.authedSocket,
|
||||
payload: {
|
||||
cmd: 'changecolor',
|
||||
nick: 'lies',
|
||||
color: '#000000',
|
||||
},
|
||||
});
|
||||
|
||||
mocks.server.findSockets = oldFS;
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
|
||||
it('should not color mods', async () => {
|
||||
const oldFS = mocks.server.findSockets;
|
||||
mocks.server.findSockets = (filterObj) => {
|
||||
return [mocks.authedSocket];
|
||||
}
|
||||
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.authedSocket,
|
||||
payload: {
|
||||
cmd: 'changecolor',
|
||||
nick: 'lies',
|
||||
color: '#000000',
|
||||
},
|
||||
});
|
||||
|
||||
mocks.server.findSockets = oldFS;
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
|
||||
it('should initialize hooks', async () => {
|
||||
expect(() => importedModule.initHooks(mocks.server)).not.to.throw();
|
||||
});
|
||||
|
||||
it('should validate chat text in hook', async () => {
|
||||
const resp = importedModule.colorCheck({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.authedSocket,
|
||||
payload: {
|
||||
cmd: 'chat',
|
||||
},
|
||||
});
|
||||
|
||||
expect(resp).to.be.false;
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,182 @@
|
||||
import { expect } from 'chai';
|
||||
import mocks from './mockImports.js';
|
||||
|
||||
const modulePath = '../commands/core/help.js';
|
||||
let importedModule;
|
||||
|
||||
const mockPayload = {
|
||||
cmd: 'help',
|
||||
channel: 'cake',
|
||||
}
|
||||
|
||||
describe('Checking help module', () => {
|
||||
// module meta data
|
||||
it('should be importable', async () => {
|
||||
importedModule = await import(modulePath);
|
||||
expect(importedModule).to.not.be.a('string');
|
||||
});
|
||||
|
||||
it('should be named', async () => {
|
||||
expect(importedModule.info.name).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be categorized', async () => {
|
||||
expect(importedModule.info.category).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be described', async () => {
|
||||
expect(importedModule.info.description).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be documented', async () => {
|
||||
expect(importedModule.info.usage).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be invokable', async () => {
|
||||
expect(importedModule.run).to.be.a('function');
|
||||
});
|
||||
|
||||
// module main function
|
||||
it('should be invokable by all', async () => {
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: mockPayload,
|
||||
});
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
|
||||
it('should ratelimit if required', async () => {
|
||||
const oldRL = mocks.server.police.frisk;
|
||||
mocks.server.police.frisk = () => true;
|
||||
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: mockPayload,
|
||||
});
|
||||
|
||||
mocks.server.police.frisk = oldRL;
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
|
||||
it('should verify user input', async () => {
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: {
|
||||
cmd: 'help',
|
||||
command: false,
|
||||
},
|
||||
});
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
|
||||
it('should output over view', async () => {
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: {
|
||||
cmd: 'help',
|
||||
},
|
||||
});
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
|
||||
it('should output specific info', async () => {
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: {
|
||||
cmd: 'help',
|
||||
command: 'test',
|
||||
},
|
||||
});
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
|
||||
it('should handle unknown commands', async () => {
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: {
|
||||
cmd: 'help',
|
||||
command: 'undef',
|
||||
},
|
||||
});
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
|
||||
it('should handle unknown aliases', async () => {
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: {
|
||||
cmd: 'help',
|
||||
command: 'noalias',
|
||||
},
|
||||
});
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
|
||||
it('should initialize hooks', async () => {
|
||||
expect(() => importedModule.initHooks(mocks.server)).not.to.throw();
|
||||
});
|
||||
|
||||
it('should hook /help, verify params', async () => {
|
||||
const resp = importedModule.helpCheck({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: {
|
||||
cmd: 'chat',
|
||||
text: false,
|
||||
},
|
||||
});
|
||||
|
||||
expect(resp).to.be.false;
|
||||
});
|
||||
|
||||
it('should hook /help', async () => {
|
||||
const resp = importedModule.helpCheck({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: {
|
||||
cmd: 'chat',
|
||||
text: '/help',
|
||||
},
|
||||
});
|
||||
|
||||
expect(resp).to.be.false;
|
||||
});
|
||||
|
||||
it('should hook /help', async () => {
|
||||
const resp = importedModule.helpCheck({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: {
|
||||
cmd: 'chat',
|
||||
text: 'no cmd',
|
||||
},
|
||||
});
|
||||
|
||||
expect(resp).to.be.an('object');
|
||||
});
|
||||
|
||||
});
|
||||
@@ -0,0 +1,230 @@
|
||||
import { expect } from 'chai';
|
||||
import mocks from './mockImports.js';
|
||||
|
||||
const modulePath = '../commands/core/invite.js';
|
||||
let importedModule;
|
||||
|
||||
const mockPayload = {
|
||||
cmd: 'invite',
|
||||
channel: 'cake',
|
||||
text: 'testing',
|
||||
}
|
||||
|
||||
describe('Checking invite module', () => {
|
||||
// module meta data
|
||||
it('should be importable', async () => {
|
||||
importedModule = await import(modulePath);
|
||||
expect(importedModule).to.not.be.a('string');
|
||||
});
|
||||
|
||||
it('should be named', async () => {
|
||||
expect(importedModule.info.name).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be categorized', async () => {
|
||||
expect(importedModule.info.category).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be described', async () => {
|
||||
expect(importedModule.info.description).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be documented', async () => {
|
||||
expect(importedModule.info.usage).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be invokable', async () => {
|
||||
expect(importedModule.run).to.be.a('function');
|
||||
});
|
||||
|
||||
// module export functions
|
||||
it('should export a random channel function', async () => {
|
||||
const resp = importedModule.getChannel();
|
||||
|
||||
expect(resp).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should export a common channel function', async () => {
|
||||
const resp = importedModule.getChannel('common');
|
||||
|
||||
expect(resp).to.be.a('string');
|
||||
});
|
||||
|
||||
// module main function
|
||||
it('should be invokable by all', async () => {
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: mockPayload,
|
||||
});
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
|
||||
it('should ratelimit if required', async () => {
|
||||
const oldRL = mocks.server.police.frisk;
|
||||
mocks.server.police.frisk = () => true;
|
||||
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: mockPayload,
|
||||
});
|
||||
|
||||
mocks.server.police.frisk = oldRL;
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
|
||||
it('should validate channel legacy param', async () => {
|
||||
const newSocket = Object.assign({}, mocks.authedSocket);
|
||||
newSocket.hcProtocol = 1;
|
||||
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: newSocket,
|
||||
payload: {
|
||||
cmd: 'invite',
|
||||
nick: 'test',
|
||||
},
|
||||
});
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
|
||||
it('should validate nick legacy param', async () => {
|
||||
const newSocket = Object.assign({}, mocks.authedSocket);
|
||||
newSocket.hcProtocol = 1;
|
||||
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: newSocket,
|
||||
payload: {
|
||||
cmd: 'invite',
|
||||
channel: 1234,
|
||||
},
|
||||
});
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
|
||||
it('should validate userid param', async () => {
|
||||
const newSocket = Object.assign({}, mocks.authedSocket);
|
||||
newSocket.hcProtocol = 2;
|
||||
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: newSocket,
|
||||
payload: {
|
||||
cmd: 'invite',
|
||||
userid: 1234,
|
||||
},
|
||||
});
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
|
||||
it('should validate channel param', async () => {
|
||||
const newSocket = Object.assign({}, mocks.authedSocket);
|
||||
newSocket.hcProtocol = 2;
|
||||
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: newSocket,
|
||||
payload: {
|
||||
cmd: 'invite',
|
||||
channel: 1234,
|
||||
},
|
||||
});
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
|
||||
it('should handle user 404', async () => {
|
||||
const oldFS = mocks.server.findSockets;
|
||||
mockPayload.nick = 'lies';
|
||||
mocks.server.findSockets = (filterObj) => {
|
||||
return false;
|
||||
}
|
||||
const newSocket = Object.assign({}, mocks.authedSocket);
|
||||
newSocket.hcProtocol = 1;
|
||||
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: newSocket,
|
||||
payload: {
|
||||
cmd: 'invite',
|
||||
channel: 'cake',
|
||||
nick: 'lies',
|
||||
userid: 1234,
|
||||
},
|
||||
});
|
||||
|
||||
mocks.server.findSockets = oldFS;
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
|
||||
it('should handle legacy users', async () => {
|
||||
const oldFS = mocks.server.findSockets;
|
||||
mockPayload.nick = 'lies';
|
||||
mocks.server.findSockets = (filterObj) => {
|
||||
return [{
|
||||
hcProtocol: 1,
|
||||
}];
|
||||
}
|
||||
const newSocket = Object.assign({}, mocks.authedSocket);
|
||||
newSocket.hcProtocol = 1;
|
||||
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: newSocket,
|
||||
payload: {
|
||||
cmd: 'invite',
|
||||
channel: 'cake',
|
||||
nick: 'lies',
|
||||
userid: 1234,
|
||||
},
|
||||
});
|
||||
|
||||
mocks.server.findSockets = oldFS;
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
|
||||
it('should handle invites', async () => {
|
||||
const oldFS = mocks.server.findSockets;
|
||||
mockPayload.nick = 'lies';
|
||||
mocks.server.findSockets = (filterObj) => {
|
||||
return [{
|
||||
hcProtocol: 2,
|
||||
}];
|
||||
}
|
||||
const newSocket = Object.assign({}, mocks.authedSocket);
|
||||
newSocket.hcProtocol = 2;
|
||||
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: newSocket,
|
||||
payload: {
|
||||
cmd: 'invite',
|
||||
channel: 'cake',
|
||||
nick: 'lies',
|
||||
userid: 1234,
|
||||
},
|
||||
});
|
||||
|
||||
mocks.server.findSockets = oldFS;
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,288 @@
|
||||
import { expect } from 'chai';
|
||||
import mocks from './mockImports.js';
|
||||
|
||||
const modulePath = '../commands/core/join.js';
|
||||
let importedModule;
|
||||
|
||||
const mockPayload = {
|
||||
cmd: 'join',
|
||||
channel: 'cake',
|
||||
text: 'testing',
|
||||
}
|
||||
|
||||
describe('Checking join module', () => {
|
||||
// module meta data
|
||||
it('should be importable', async () => {
|
||||
importedModule = await import(modulePath);
|
||||
expect(importedModule).to.not.be.a('string');
|
||||
});
|
||||
|
||||
it('should be named', async () => {
|
||||
expect(importedModule.info.name).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be categorized', async () => {
|
||||
expect(importedModule.info.category).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be described', async () => {
|
||||
expect(importedModule.info.description).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be documented', async () => {
|
||||
expect(importedModule.info.usage).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be invokable', async () => {
|
||||
expect(importedModule.run).to.be.a('function');
|
||||
});
|
||||
|
||||
// module main function
|
||||
it('should be invokable by all', async () => {
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: mockPayload,
|
||||
});
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
|
||||
it('should ratelimit if required', async () => {
|
||||
const oldRL = mocks.server.police.frisk;
|
||||
mocks.server.police.frisk = () => true;
|
||||
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: mockPayload,
|
||||
});
|
||||
|
||||
mocks.server.police.frisk = oldRL;
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
|
||||
it('should upgrade legacy users', async () => {
|
||||
const newSocket = Object.assign({}, mocks.authedSocket);
|
||||
newSocket.hcProtocol = undefined;
|
||||
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: newSocket,
|
||||
payload: {
|
||||
cmd: 'join',
|
||||
nick: 'test#test',
|
||||
channel: 'cake',
|
||||
},
|
||||
});
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
|
||||
it('should fail on invalid channels', async () => {
|
||||
const newSocket = Object.assign({}, mocks.authedSocket);
|
||||
newSocket.hcProtocol = undefined;
|
||||
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: newSocket,
|
||||
payload: {
|
||||
cmd: 'join',
|
||||
nick: 'test#test',
|
||||
channel: false,
|
||||
},
|
||||
});
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
|
||||
it('should allow join only if not already joined', async () => {
|
||||
const newSocket = Object.assign({}, mocks.authedSocket);
|
||||
newSocket.channel = undefined;
|
||||
newSocket.hcProtocol = undefined;
|
||||
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: newSocket,
|
||||
payload: {
|
||||
cmd: 'join',
|
||||
nick: 'test#test',
|
||||
channel: 'cake',
|
||||
},
|
||||
});
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
|
||||
it('should allow join only user has a valid name', async () => {
|
||||
const newSocket = Object.assign({}, mocks.authedSocket);
|
||||
newSocket.channel = undefined;
|
||||
newSocket.hcProtocol = undefined;
|
||||
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: newSocket,
|
||||
payload: {
|
||||
cmd: 'join',
|
||||
nick: 't e s t#test',
|
||||
channel: 'cake',
|
||||
},
|
||||
});
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
|
||||
it('should prevent admin impersonation', async () => {
|
||||
const newSocket = Object.assign({}, mocks.authedSocket);
|
||||
newSocket.channel = undefined;
|
||||
newSocket.hcProtocol = undefined;
|
||||
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: newSocket,
|
||||
payload: {
|
||||
cmd: 'join',
|
||||
nick: 'admin#test',
|
||||
channel: 'cake',
|
||||
},
|
||||
});
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
|
||||
it('should prevent two of the same name in the same channel', async () => {
|
||||
const newSocket = Object.assign({}, mocks.authedSocket);
|
||||
newSocket.channel = undefined;
|
||||
newSocket.hcProtocol = undefined;
|
||||
|
||||
mocks.server.findSockets = (filterObj) => {
|
||||
return false;
|
||||
}
|
||||
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: newSocket,
|
||||
payload: {
|
||||
cmd: 'join',
|
||||
nick: 'admin#test',
|
||||
channel: 'cake',
|
||||
},
|
||||
});
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
|
||||
it('should announce new user', async () => {
|
||||
const newSocket = Object.assign({}, mocks.authedSocket);
|
||||
newSocket.channel = undefined;
|
||||
newSocket.hcProtocol = undefined;
|
||||
|
||||
mocks.server.findSockets = (filterObj) => {
|
||||
if (filterObj.nick) {
|
||||
if (typeof filterObj.nick === 'function') {
|
||||
filterObj.nick('nick');
|
||||
}
|
||||
|
||||
return false;
|
||||
} else {
|
||||
return [mocks.plebSocket];
|
||||
}
|
||||
}
|
||||
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: newSocket,
|
||||
payload: {
|
||||
cmd: 'join',
|
||||
nick: 'admin#test',
|
||||
channel: 'cake',
|
||||
},
|
||||
});
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
|
||||
it('should restore a join', async () => {
|
||||
const newSocket = Object.assign({}, mocks.authedSocket);
|
||||
|
||||
const resp = await importedModule.restoreJoin({
|
||||
server: mocks.server,
|
||||
socket: newSocket,
|
||||
channel: 'test',
|
||||
});
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
|
||||
it('should accept a restoration refusal', async () => {
|
||||
const newSocket = Object.assign({}, mocks.authedSocket);
|
||||
newSocket.banned = true;
|
||||
|
||||
const resp = await importedModule.restoreJoin({
|
||||
server: mocks.server,
|
||||
socket: newSocket,
|
||||
channel: 'test',
|
||||
});
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
|
||||
it('should account for duplicate connections', async () => {
|
||||
const newSocket = Object.assign({}, mocks.authedSocket);
|
||||
const newServer = Object.assign({}, mocks.server);
|
||||
const origFindSockets = mocks.server.findSockets;
|
||||
|
||||
newServer.findSockets = (filterObj) => {
|
||||
if (typeof filterObj.nick !== 'undefined') {
|
||||
filterObj.nick('nick');
|
||||
}
|
||||
return [mocks.authedSocket];
|
||||
}
|
||||
|
||||
const resp = await importedModule.restoreJoin({
|
||||
server: newServer,
|
||||
socket: newSocket,
|
||||
channel: 'test',
|
||||
});
|
||||
|
||||
mocks.server.findSockets = origFindSockets;
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
|
||||
it('should handle non-duplicate connections', async () => {
|
||||
const newSocket = Object.assign({}, mocks.authedSocket);
|
||||
const newServer = Object.assign({}, mocks.server);
|
||||
const origFindSockets = mocks.server.findSockets;
|
||||
let alreadyRan = false;
|
||||
|
||||
newServer.findSockets = (filterObj) => {
|
||||
if (alreadyRan === false) {
|
||||
alreadyRan = true;
|
||||
return [mocks.authedSocket];
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
const resp = await importedModule.restoreJoin({
|
||||
server: newServer,
|
||||
socket: newSocket,
|
||||
channel: 'test',
|
||||
});
|
||||
|
||||
mocks.server.findSockets = origFindSockets;
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,171 @@
|
||||
import { expect } from 'chai';
|
||||
import mocks from './mockImports.js';
|
||||
|
||||
const modulePath = '../commands/mod/kick.js';
|
||||
let importedModule;
|
||||
|
||||
const mockPayload = {
|
||||
cmd: 'kick',
|
||||
userid: 1234,
|
||||
to: 'no_cake',
|
||||
}
|
||||
|
||||
describe('Checking kick module', () => {
|
||||
// module meta data
|
||||
it('should be importable', async () => {
|
||||
importedModule = await import(modulePath);
|
||||
expect(importedModule).to.not.be.a('string');
|
||||
});
|
||||
|
||||
it('should be named', async () => {
|
||||
expect(importedModule.info.name).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be categorized', async () => {
|
||||
expect(importedModule.info.category).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be described', async () => {
|
||||
expect(importedModule.info.description).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be documented', async () => {
|
||||
expect(importedModule.info.usage).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be invokable', async () => {
|
||||
expect(importedModule.run).to.be.a('function');
|
||||
});
|
||||
|
||||
// module main function
|
||||
it('should be invokable only by a mod', async () => {
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: mockPayload,
|
||||
});
|
||||
|
||||
expect(resp).to.be.false;
|
||||
});
|
||||
|
||||
it('should validate legacy params', async () => {
|
||||
const newSocket = Object.assign({}, mocks.authedSocket);
|
||||
newSocket.hcProtocol = 1;
|
||||
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: newSocket,
|
||||
payload: {
|
||||
cmd: 'kick',
|
||||
},
|
||||
});
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
|
||||
it('should handle no users found', async () => {
|
||||
mocks.authedSocket.hcProtocol = 2;
|
||||
mocks.server.findSockets = (filterObj) => {
|
||||
if (typeof filterObj.nick === 'function') {
|
||||
filterObj.nick('lies');
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.authedSocket,
|
||||
payload: {
|
||||
cmd: 'kick',
|
||||
userid: 1234,
|
||||
to: 'test',
|
||||
},
|
||||
});
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
|
||||
it('should validate params', async () => {
|
||||
mocks.server.findSockets = (filterObj) => {
|
||||
if (typeof filterObj.nick === 'function') {
|
||||
filterObj.nick('lies');
|
||||
}
|
||||
|
||||
return [mocks.plebSocket];
|
||||
}
|
||||
|
||||
mocks.authedSocket.hcProtocol = 2;
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.authedSocket,
|
||||
payload: {
|
||||
cmd: 'kick',
|
||||
userid: false,
|
||||
},
|
||||
});
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
|
||||
it('should accept a "to" param', async () => {
|
||||
mocks.authedSocket.hcProtocol = 2;
|
||||
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.authedSocket,
|
||||
payload: {
|
||||
cmd: 'kick',
|
||||
userid: 1234,
|
||||
to: 'test',
|
||||
},
|
||||
});
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
|
||||
it('should kick to random channel', async () => {
|
||||
mocks.authedSocket.hcProtocol = 2;
|
||||
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.authedSocket,
|
||||
payload: {
|
||||
cmd: 'kick',
|
||||
userid: 1234,
|
||||
},
|
||||
});
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
|
||||
it('should not kick mods', async () => {
|
||||
mocks.authedSocket.hcProtocol = 2;
|
||||
mocks.server.findSockets = (filterObj) => {
|
||||
if (typeof filterObj.nick === 'function') {
|
||||
filterObj.nick('lies');
|
||||
}
|
||||
|
||||
return [mocks.authedSocket];
|
||||
}
|
||||
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.authedSocket,
|
||||
payload: {
|
||||
cmd: 'kick',
|
||||
userid: 1234,
|
||||
to: 'test',
|
||||
},
|
||||
});
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,52 @@
|
||||
import { expect } from 'chai';
|
||||
import mocks from './mockImports.js';
|
||||
|
||||
const modulePath = '../commands/utility/_LegacyFunctions.js';
|
||||
let importedModule;
|
||||
|
||||
describe('Checking legacyFunctions module', () => {
|
||||
it('should be importable', async () => {
|
||||
importedModule = await import(modulePath);
|
||||
expect(importedModule).to.not.be.a('string');
|
||||
});
|
||||
|
||||
it('should handle pass and password', async () => {
|
||||
const resp = importedModule.upgradeLegacyJoin(mocks.server, mocks.plebSocket, {
|
||||
nick: 'test#test',
|
||||
password: 'test',
|
||||
});
|
||||
expect(resp).to.be.an('object');
|
||||
});
|
||||
|
||||
it('should handle mod label', async () => {
|
||||
const resp = importedModule.legacyLevelToLabel(9999999);
|
||||
expect(resp).to.equal('admin');
|
||||
});
|
||||
|
||||
it('should handle mod label', async () => {
|
||||
const resp = importedModule.legacyLevelToLabel(999999);
|
||||
expect(resp).to.equal('mod');
|
||||
});
|
||||
|
||||
it('should provide duplicate user checks', async () => {
|
||||
const newSocket = Object.assign({}, mocks.plebSocket);
|
||||
newSocket.trip = false;
|
||||
|
||||
const resp = importedModule.legacyWhisperOut({
|
||||
cmd: 'whisper',
|
||||
}, newSocket);
|
||||
|
||||
expect(resp).to.be.an('object');
|
||||
});
|
||||
|
||||
it('should apply missing user id', async () => {
|
||||
const newSocket = Object.assign({}, mocks.authedSocket);
|
||||
newSocket.userid = undefined;
|
||||
|
||||
const resp = importedModule.upgradeLegacyJoin(mocks.server, newSocket, {
|
||||
nick: 'test#test',
|
||||
password: 'test',
|
||||
});
|
||||
expect(resp).to.be.an('object');
|
||||
});
|
||||
})
|
||||
@@ -0,0 +1,68 @@
|
||||
import { expect } from 'chai';
|
||||
import mocks from './mockImports.js';
|
||||
|
||||
const modulePath = '../commands/admin/listusers.js';
|
||||
let importedModule;
|
||||
|
||||
const mockPayload = {
|
||||
cmd: 'listusers',
|
||||
}
|
||||
|
||||
describe('Checking listusers module', () => {
|
||||
// module meta data
|
||||
it('should be importable', async () => {
|
||||
importedModule = await import(modulePath);
|
||||
expect(importedModule).to.not.be.a('string');
|
||||
});
|
||||
|
||||
it('should be named', async () => {
|
||||
expect(importedModule.info.name).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be categorized', async () => {
|
||||
expect(importedModule.info.category).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be described', async () => {
|
||||
expect(importedModule.info.description).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be documented', async () => {
|
||||
expect(importedModule.info.usage).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be invokable', async () => {
|
||||
expect(importedModule.run).to.be.a('function');
|
||||
});
|
||||
|
||||
// module main function
|
||||
it('should be invokable only by an admin', async () => {
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: mockPayload,
|
||||
});
|
||||
|
||||
expect(resp).to.be.false;
|
||||
});
|
||||
|
||||
it('should send a reply', async () => {
|
||||
mocks.server.findSockets = (filterObj) => {
|
||||
if (typeof filterObj.channel === 'function') {
|
||||
filterObj.channel();
|
||||
}
|
||||
|
||||
return [{}];
|
||||
}
|
||||
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.authedSocket,
|
||||
payload: mockPayload,
|
||||
});
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,115 @@
|
||||
const mocks = {
|
||||
core: {
|
||||
sessionKey: 'test',
|
||||
appConfig: {
|
||||
data: {
|
||||
globalMods: [],
|
||||
permissions: [],
|
||||
channels: {
|
||||
test: {
|
||||
owned: false,
|
||||
}
|
||||
},
|
||||
tripSalt: 'test',
|
||||
adminTrip: '',
|
||||
},
|
||||
write: async () => '',
|
||||
},
|
||||
muzzledHashes: [],
|
||||
stats: {
|
||||
increment: () => 1,
|
||||
decrement: () => 1,
|
||||
get: () => 1,
|
||||
set: () => 1,
|
||||
},
|
||||
dynamicImports: {
|
||||
reloadDirCache: () => '',
|
||||
},
|
||||
commands: {
|
||||
reloadCommands: () => '',
|
||||
commands: [],
|
||||
categoriesList: ['test'],
|
||||
all: () => [{
|
||||
info: {
|
||||
name: 'test',
|
||||
category: 'test',
|
||||
},
|
||||
}],
|
||||
get: (name) => {
|
||||
if (name === 'undef') {
|
||||
return undefined;
|
||||
} else if(name === 'noalias') {
|
||||
return {
|
||||
info: {
|
||||
name: 'test',
|
||||
category: 'test',
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return {
|
||||
info: {
|
||||
name: 'test',
|
||||
category: 'test',
|
||||
aliases: ['testing'],
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
configManager: {
|
||||
save: () => true,
|
||||
},
|
||||
},
|
||||
server : {
|
||||
police: {
|
||||
addresses: [],
|
||||
frisk: () => false,
|
||||
arrest: (address) => mocks.server.police.addresses.push(address),
|
||||
},
|
||||
findSockets: () => [],
|
||||
reply: () => true,
|
||||
broadcast: (data, filterObj) => {
|
||||
if (typeof filterObj.level === 'function') {
|
||||
filterObj.level();
|
||||
}
|
||||
|
||||
return true;
|
||||
},
|
||||
send: () => true,
|
||||
cmdKey: 'test',
|
||||
registerHook: () => true,
|
||||
loadHooks: () => true,
|
||||
clients: [{
|
||||
channel: 'cake',
|
||||
address: '127.0.0.1',
|
||||
}],
|
||||
getSocketHash: () => 'test',
|
||||
},
|
||||
plebSocket: {
|
||||
level: 100,
|
||||
address: '127.0.0.1',
|
||||
channel: 'cake',
|
||||
channels: [],
|
||||
terminate: () => true,
|
||||
nick: 'lies',
|
||||
hcProtocol: 2,
|
||||
hash: 'testHash',
|
||||
uType: 'user',
|
||||
userid: 1234,
|
||||
},
|
||||
authedSocket: {
|
||||
level: 9999999,
|
||||
address: '127.0.0.1',
|
||||
channel: 'cake',
|
||||
channels: [],
|
||||
terminate: () => true,
|
||||
hcProtocol: 2,
|
||||
nick: '[ignore this]',
|
||||
trip: 'and this',
|
||||
hash: 'testHash',
|
||||
uType: 'admin',
|
||||
userid: 1234,
|
||||
},
|
||||
};
|
||||
|
||||
export default mocks;
|
||||
@@ -0,0 +1,95 @@
|
||||
import { expect } from 'chai';
|
||||
import mocks from './mockImports.js';
|
||||
|
||||
const modulePath = '../commands/core/morestats.js';
|
||||
let importedModule;
|
||||
|
||||
const mockPayload = {
|
||||
cmd: 'morestats',
|
||||
channel: 'cake',
|
||||
}
|
||||
|
||||
describe('Checking morestats module', () => {
|
||||
// module meta data
|
||||
it('should be importable', async () => {
|
||||
importedModule = await import(modulePath);
|
||||
expect(importedModule).to.not.be.a('string');
|
||||
});
|
||||
|
||||
it('should be named', async () => {
|
||||
expect(importedModule.info.name).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be categorized', async () => {
|
||||
expect(importedModule.info.category).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be described', async () => {
|
||||
expect(importedModule.info.description).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be documented', async () => {
|
||||
expect(importedModule.info.usage).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be invokable', async () => {
|
||||
expect(importedModule.run).to.be.a('function');
|
||||
});
|
||||
|
||||
// module main function
|
||||
it('should be invokable by all', async () => {
|
||||
const newSocket = Object.assign({}, mocks.plebSocket);
|
||||
newSocket.channel = 'programming';
|
||||
mocks.server.clients = [
|
||||
newSocket,
|
||||
];
|
||||
mocks.core.stats.get = (type) => {
|
||||
if (type === 'start-time') {
|
||||
return process.hrtime();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: mockPayload,
|
||||
});
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
|
||||
it('should initialize hooks', async () => {
|
||||
expect(() => importedModule.initHooks(mocks.server)).not.to.throw();
|
||||
});
|
||||
|
||||
it('should validate params with /stats', async () => {
|
||||
const resp = importedModule.statsCheck({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: {
|
||||
cmd: 'chat',
|
||||
},
|
||||
});
|
||||
|
||||
expect(resp).to.be.false;
|
||||
});
|
||||
|
||||
it('should run with /stats', async () => {
|
||||
const resp = importedModule.statsCheck({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: {
|
||||
cmd: 'chat',
|
||||
text: '/stats',
|
||||
},
|
||||
});
|
||||
|
||||
expect(resp).to.be.false;
|
||||
});
|
||||
|
||||
});
|
||||
@@ -0,0 +1,50 @@
|
||||
import { expect } from 'chai';
|
||||
import mocks from './mockImports.js';
|
||||
|
||||
const modulePath = '../commands/core/ping.js';
|
||||
let importedModule;
|
||||
|
||||
const mockPayload = {
|
||||
cmd: 'ping',
|
||||
channel: 'cake',
|
||||
text: 'testing',
|
||||
}
|
||||
|
||||
describe('Checking ping module', () => {
|
||||
// module meta data
|
||||
it('should be importable', async () => {
|
||||
importedModule = await import(modulePath);
|
||||
expect(importedModule).to.not.be.a('string');
|
||||
});
|
||||
|
||||
it('should be named', async () => {
|
||||
expect(importedModule.info.name).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be categorized', async () => {
|
||||
expect(importedModule.info.category).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be described', async () => {
|
||||
expect(importedModule.info.description).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be documented', async () => {
|
||||
expect(importedModule.info.usage).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be invokable', async () => {
|
||||
expect(importedModule.run).to.be.a('function');
|
||||
});
|
||||
|
||||
// module main function
|
||||
it('should be invokable by all', async () => {
|
||||
expect(() => importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: mockPayload,
|
||||
})).not.to.throw();
|
||||
});
|
||||
|
||||
});
|
||||
@@ -0,0 +1,89 @@
|
||||
import { expect } from 'chai';
|
||||
import mocks from './mockImports.js';
|
||||
|
||||
const modulePath = '../commands/admin/reload.js';
|
||||
let importedModule;
|
||||
|
||||
const mockPayload = {
|
||||
cmd: 'reload',
|
||||
}
|
||||
|
||||
describe('Checking reload module', () => {
|
||||
// module meta data
|
||||
it('should be importable', async () => {
|
||||
importedModule = await import(modulePath);
|
||||
expect(importedModule).to.not.be.a('string');
|
||||
});
|
||||
|
||||
it('should be named', async () => {
|
||||
expect(importedModule.info.name).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be categorized', async () => {
|
||||
expect(importedModule.info.category).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be described', async () => {
|
||||
expect(importedModule.info.description).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be documented', async () => {
|
||||
expect(importedModule.info.usage).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be invokable', async () => {
|
||||
expect(importedModule.run).to.be.a('function');
|
||||
});
|
||||
|
||||
// module main function
|
||||
it('should be invokable only by an admin', async () => {
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: mockPayload,
|
||||
});
|
||||
|
||||
expect(resp).to.be.false;
|
||||
});
|
||||
|
||||
it('should reload server commands', async () => {
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.authedSocket,
|
||||
payload: mockPayload,
|
||||
});
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
|
||||
it('should report reload errors', async () => {
|
||||
mocks.core.commands.reloadCommands = () => 'This is an error';
|
||||
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.authedSocket,
|
||||
payload:
|
||||
mockPayload,
|
||||
});
|
||||
|
||||
mocks.core.commands.reloadCommands = () => '';
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
|
||||
it('should report an optional reason', async () => {
|
||||
mockPayload.reason = 'This is a reason';
|
||||
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.authedSocket,
|
||||
payload: mockPayload,
|
||||
});
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,76 @@
|
||||
import { expect } from 'chai';
|
||||
import mocks from './mockImports.js';
|
||||
|
||||
const modulePath = '../commands/admin/removemod.js';
|
||||
let importedModule;
|
||||
|
||||
const mockPayload = {
|
||||
cmd: 'removemod',
|
||||
trip: 'newTrip',
|
||||
}
|
||||
|
||||
describe('Checking removemod module', () => {
|
||||
// module meta data
|
||||
it('should be importable', async () => {
|
||||
importedModule = await import(modulePath);
|
||||
expect(importedModule).to.not.be.a('string');
|
||||
});
|
||||
|
||||
it('should be named', async () => {
|
||||
expect(importedModule.info.name).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be categorized', async () => {
|
||||
expect(importedModule.info.category).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be described', async () => {
|
||||
expect(importedModule.info.description).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be documented', async () => {
|
||||
expect(importedModule.info.usage).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be invokable', async () => {
|
||||
expect(importedModule.run).to.be.a('function');
|
||||
});
|
||||
|
||||
// module main function
|
||||
it('should be invokable only by an admin', async () => {
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: mockPayload,
|
||||
});
|
||||
|
||||
expect(resp).to.be.false;
|
||||
});
|
||||
|
||||
it('should remove trip from the config', async () => {
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.authedSocket,
|
||||
payload: mockPayload,
|
||||
});
|
||||
|
||||
expect(mocks.core.appConfig.data.globalMods[0]).to.be.undefined;
|
||||
});
|
||||
|
||||
it('should inform the ex-mod', async () => {
|
||||
mocks.server.findSockets = () => {
|
||||
return [{}];
|
||||
}
|
||||
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.authedSocket,
|
||||
payload: mockPayload,
|
||||
});
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,92 @@
|
||||
import { expect } from 'chai';
|
||||
import mocks from './mockImports.js';
|
||||
|
||||
const modulePath = '../commands/admin/saveconfig.js';
|
||||
let importedModule;
|
||||
|
||||
const mockPayload = {
|
||||
cmd: 'saveconfig',
|
||||
}
|
||||
|
||||
describe('Checking saveconfig module', () => {
|
||||
// module meta data
|
||||
it('should be importable', async () => {
|
||||
importedModule = await import(modulePath);
|
||||
expect(importedModule).to.not.be.a('string');
|
||||
});
|
||||
|
||||
it('should be named', async () => {
|
||||
expect(importedModule.info.name).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be categorized', async () => {
|
||||
expect(importedModule.info.category).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be described', async () => {
|
||||
expect(importedModule.info.description).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be documented', async () => {
|
||||
expect(importedModule.info.usage).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be invokable', async () => {
|
||||
expect(importedModule.run).to.be.a('function');
|
||||
});
|
||||
|
||||
// module main function
|
||||
it('should be invokable only by an admin', async () => {
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: mockPayload,
|
||||
});
|
||||
|
||||
expect(resp).to.be.false;
|
||||
});
|
||||
|
||||
it('should force a config save', async () => {
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.authedSocket,
|
||||
payload: mockPayload,
|
||||
});
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
|
||||
it('should report errors', async () => {
|
||||
mocks.core.appConfig.write = () => {
|
||||
throw new Error;
|
||||
}
|
||||
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.authedSocket,
|
||||
payload: mockPayload,
|
||||
});
|
||||
|
||||
mocks.core.appConfig.write = () => '';
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
|
||||
it('should broadcast save notice', async () => {
|
||||
mocks.server.findSockets = (filterObj) => {
|
||||
return [mocks.plebSocket];
|
||||
}
|
||||
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.authedSocket,
|
||||
payload: mockPayload,
|
||||
});
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,250 @@
|
||||
import { expect } from 'chai';
|
||||
import jsonwebtoken from 'jsonwebtoken';
|
||||
import mocks from './mockImports.js';
|
||||
|
||||
const modulePath = '../commands/core/session.js';
|
||||
let importedModule;
|
||||
|
||||
const mockPayload = {
|
||||
cmd: 'session',
|
||||
token: 'testing',
|
||||
}
|
||||
|
||||
describe('Checking session module', () => {
|
||||
// module meta data
|
||||
it('should be importable', async () => {
|
||||
importedModule = await import(modulePath);
|
||||
expect(importedModule).to.not.be.a('string');
|
||||
});
|
||||
|
||||
it('should be named', async () => {
|
||||
expect(importedModule.info.name).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be categorized', async () => {
|
||||
expect(importedModule.info.category).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be described', async () => {
|
||||
expect(importedModule.info.description).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be documented', async () => {
|
||||
expect(importedModule.info.usage).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should initialize', async () => {
|
||||
const resp = importedModule.init(mocks.core);
|
||||
expect(mocks.core).to.be.an('object');
|
||||
});
|
||||
|
||||
it('should provide current session string', async () => {
|
||||
const newCore = Object.assign({}, mocks.core);
|
||||
|
||||
const resp = await importedModule.getSession(mocks.plebSocket, newCore);
|
||||
|
||||
expect(resp).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be invokable', async () => {
|
||||
expect(importedModule.run).to.be.a('function');
|
||||
});
|
||||
|
||||
it('should initialize', async () => {
|
||||
const newCore = Object.assign({}, mocks.core);
|
||||
newCore.sessionKey = undefined;
|
||||
const resp = importedModule.init(newCore);
|
||||
|
||||
expect(newCore.sessionKey).to.not.equal(undefined);
|
||||
});
|
||||
|
||||
// module main function
|
||||
it('should be invokable by all', async () => {
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: mockPayload,
|
||||
});
|
||||
|
||||
expect(resp).to.be.false;
|
||||
});
|
||||
|
||||
it('should notify about required token', async () => {
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: {
|
||||
cmd: 'session',
|
||||
},
|
||||
});
|
||||
|
||||
expect(resp).to.be.false;
|
||||
});
|
||||
|
||||
it('should notify about invalid token', async () => {
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: {
|
||||
cmd: 'session',
|
||||
token: 'false',
|
||||
},
|
||||
});
|
||||
|
||||
expect(resp).to.be.false;
|
||||
});
|
||||
|
||||
it('should accept valid token', async () => {
|
||||
const newCore = Object.assign({}, mocks.core);
|
||||
newCore.sessionKey = 'test';
|
||||
const token = jsonwebtoken.sign({
|
||||
nick: 'test',
|
||||
channel: 'test',
|
||||
}, newCore.sessionKey);
|
||||
|
||||
const resp = await importedModule.run({
|
||||
core: newCore,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: {
|
||||
cmd: 'session',
|
||||
token: token,
|
||||
},
|
||||
});
|
||||
|
||||
expect(resp).to.be.false;
|
||||
});
|
||||
|
||||
it('should require a session channel value', async () => {
|
||||
const newCore = Object.assign({}, mocks.core);
|
||||
newCore.sessionKey = 'test';
|
||||
const token = jsonwebtoken.sign({
|
||||
test: 'test',
|
||||
}, newCore.sessionKey);
|
||||
|
||||
const resp = await importedModule.run({
|
||||
core: newCore,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: {
|
||||
cmd: 'session',
|
||||
token: token,
|
||||
},
|
||||
});
|
||||
|
||||
expect(resp).to.be.false;
|
||||
});
|
||||
|
||||
it('should require session channels value', async () => {
|
||||
const newCore = Object.assign({}, mocks.core);
|
||||
newCore.sessionKey = 'test';
|
||||
const token = jsonwebtoken.sign({
|
||||
channel: 'test',
|
||||
}, newCore.sessionKey);
|
||||
|
||||
const resp = await importedModule.run({
|
||||
core: newCore,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: {
|
||||
cmd: 'session',
|
||||
token: token,
|
||||
},
|
||||
});
|
||||
|
||||
expect(resp).to.be.false;
|
||||
});
|
||||
|
||||
it('should require session color value', async () => {
|
||||
const newCore = Object.assign({}, mocks.core);
|
||||
newCore.sessionKey = 'test';
|
||||
const token = jsonwebtoken.sign({
|
||||
channel: 'test',
|
||||
channels: ['test'],
|
||||
}, newCore.sessionKey);
|
||||
|
||||
const resp = await importedModule.run({
|
||||
core: newCore,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: {
|
||||
cmd: 'session',
|
||||
token: token,
|
||||
},
|
||||
});
|
||||
|
||||
expect(resp).to.be.false;
|
||||
});
|
||||
|
||||
it('should require session isBot value', async () => {
|
||||
const newCore = Object.assign({}, mocks.core);
|
||||
newCore.sessionKey = 'test';
|
||||
const token = jsonwebtoken.sign({
|
||||
channel: 'test',
|
||||
channels: ['test'],
|
||||
color: 'ffffff',
|
||||
}, newCore.sessionKey);
|
||||
|
||||
const resp = await importedModule.run({
|
||||
core: newCore,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: {
|
||||
cmd: 'session',
|
||||
token: token,
|
||||
},
|
||||
});
|
||||
|
||||
expect(resp).to.be.false;
|
||||
});
|
||||
|
||||
it('should require session level value', async () => {
|
||||
const newCore = Object.assign({}, mocks.core);
|
||||
newCore.sessionKey = 'test';
|
||||
const token = jsonwebtoken.sign({
|
||||
channel: 'test',
|
||||
channels: ['test'],
|
||||
color: 'ffffff',
|
||||
isBot: false,
|
||||
}, newCore.sessionKey);
|
||||
|
||||
const resp = await importedModule.run({
|
||||
core: newCore,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: {
|
||||
cmd: 'session',
|
||||
token: token,
|
||||
},
|
||||
});
|
||||
|
||||
expect(resp).to.be.false;
|
||||
});
|
||||
|
||||
it('should require session level value', async () => {
|
||||
const newCore = Object.assign({}, mocks.core);
|
||||
newCore.sessionKey = 'test';
|
||||
const token = jsonwebtoken.sign({
|
||||
channel: 'test',
|
||||
channels: ['test'],
|
||||
color: 'ffffff',
|
||||
isBot: false,
|
||||
nick: 'test',
|
||||
}, newCore.sessionKey);
|
||||
|
||||
const resp = await importedModule.run({
|
||||
core: newCore,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: {
|
||||
cmd: 'session',
|
||||
token: token,
|
||||
},
|
||||
});
|
||||
|
||||
expect(resp).to.be.false;
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,65 @@
|
||||
import { expect } from 'chai';
|
||||
import mocks from './mockImports.js';
|
||||
|
||||
const modulePath = '../commands/admin/shout.js';
|
||||
let importedModule;
|
||||
|
||||
const mockPayload = {
|
||||
cmd: 'shout',
|
||||
text: 'This is a shout',
|
||||
}
|
||||
|
||||
describe('Checking shout module', () => {
|
||||
// module meta data
|
||||
it('should be importable', async () => {
|
||||
importedModule = await import(modulePath);
|
||||
expect(importedModule).to.not.be.a('string');
|
||||
});
|
||||
|
||||
it('should be named', async () => {
|
||||
expect(importedModule.info.name).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be categorized', async () => {
|
||||
expect(importedModule.info.category).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be described', async () => {
|
||||
expect(importedModule.info.description).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be documented', async () => {
|
||||
expect(importedModule.info.usage).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be invokable', async () => {
|
||||
expect(importedModule.run).to.be.a('function');
|
||||
});
|
||||
|
||||
// module main function
|
||||
it('should be invokable only by an admin', async () => {
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: mockPayload,
|
||||
});
|
||||
|
||||
expect(resp).to.be.false;
|
||||
});
|
||||
|
||||
it('should do the broadcast', async () => {
|
||||
mocks.server.findSockets = () => {
|
||||
return [{}];
|
||||
}
|
||||
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.authedSocket,
|
||||
payload: mockPayload,
|
||||
});
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,61 @@
|
||||
import { expect } from 'chai';
|
||||
import mocks from './mockImports.js';
|
||||
|
||||
const modulePath = '../commands/internal/socketreply.js';
|
||||
let importedModule;
|
||||
|
||||
const mockPayload = {
|
||||
cmd: 'disconnect',
|
||||
}
|
||||
|
||||
describe('Checking socketreply module', () => {
|
||||
// module meta data
|
||||
it('should be importable', async () => {
|
||||
importedModule = await import(modulePath);
|
||||
expect(importedModule).to.not.be.a('string');
|
||||
});
|
||||
|
||||
it('should be named', async () => {
|
||||
expect(importedModule.info.name).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be categorized', async () => {
|
||||
expect(importedModule.info.category).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be described', async () => {
|
||||
expect(importedModule.info.description).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be documented', async () => {
|
||||
expect(importedModule.info.usage).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be invokable', async () => {
|
||||
expect(importedModule.run).to.be.a('function');
|
||||
});
|
||||
|
||||
// module main function
|
||||
it('should be invokable only internally', async () => {
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: mockPayload,
|
||||
});
|
||||
|
||||
expect(resp).to.be.false;
|
||||
});
|
||||
|
||||
it('should broadcast warning event', async () => {
|
||||
mockPayload.cmdKey = 'test';
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: mockPayload,
|
||||
});
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,71 @@
|
||||
import { expect } from 'chai';
|
||||
import mocks from './mockImports.js';
|
||||
|
||||
const modulePath = '../commands/mod/speak.js';
|
||||
let importedModule;
|
||||
|
||||
const mockPayload = {
|
||||
cmd: 'speak',
|
||||
ip: '127.0.0.1',
|
||||
}
|
||||
|
||||
describe('Checking speak module', () => {
|
||||
// module meta data
|
||||
it('should be importable', async () => {
|
||||
importedModule = await import(modulePath);
|
||||
expect(importedModule).to.not.be.a('string');
|
||||
});
|
||||
|
||||
it('should be named', async () => {
|
||||
expect(importedModule.info.name).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be categorized', async () => {
|
||||
expect(importedModule.info.category).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be described', async () => {
|
||||
expect(importedModule.info.description).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be documented', async () => {
|
||||
expect(importedModule.info.usage).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be invokable', async () => {
|
||||
expect(importedModule.run).to.be.a('function');
|
||||
});
|
||||
|
||||
// module main function
|
||||
it('should be invokable only by a mod', async () => {
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: mockPayload,
|
||||
});
|
||||
|
||||
expect(resp).to.be.false;
|
||||
});
|
||||
|
||||
it('should initialize', async () => {
|
||||
mocks.core.muzzledHashes = undefined;
|
||||
const resp = importedModule.init(mocks.core);
|
||||
|
||||
expect(mocks.core.muzzledHashes).to.be.an('object');
|
||||
});
|
||||
|
||||
it('should validate params', async () => {
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.authedSocket,
|
||||
payload: {
|
||||
cmd: 'speak',
|
||||
},
|
||||
});
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
|
||||
});
|
||||
@@ -0,0 +1,48 @@
|
||||
import { expect } from 'chai';
|
||||
import mocks from './mockImports.js';
|
||||
|
||||
const modulePath = '../commands/core/stats.js';
|
||||
let importedModule;
|
||||
|
||||
const mockPayload = {
|
||||
cmd: 'stats',
|
||||
}
|
||||
|
||||
describe('Checking stats module', () => {
|
||||
// module meta data
|
||||
it('should be importable', async () => {
|
||||
importedModule = await import(modulePath);
|
||||
expect(importedModule).to.not.be.a('string');
|
||||
});
|
||||
|
||||
it('should be named', async () => {
|
||||
expect(importedModule.info.name).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be categorized', async () => {
|
||||
expect(importedModule.info.category).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be described', async () => {
|
||||
expect(importedModule.info.description).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be documented', async () => {
|
||||
expect(importedModule.info.usage).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be invokable', async () => {
|
||||
expect(importedModule.run).to.be.a('function');
|
||||
});
|
||||
|
||||
// module main function
|
||||
it('should be invokable by all', async () => {
|
||||
expect(() => importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: mockPayload,
|
||||
})).not.to.throw();
|
||||
});
|
||||
|
||||
});
|
||||
@@ -0,0 +1,67 @@
|
||||
import { expect } from 'chai';
|
||||
import mocks from './mockImports.js';
|
||||
|
||||
const modulePath = '../commands/utility/_UAC.js';
|
||||
let importedModule;
|
||||
|
||||
describe('Checking UAC module', () => {
|
||||
it('should be importable', async () => {
|
||||
importedModule = await import(modulePath);
|
||||
expect(importedModule).to.not.be.a('string');
|
||||
});
|
||||
|
||||
it('should handle channel owners', async () => {
|
||||
const resp = importedModule.isChannelOwner(9999999);
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
|
||||
it('should handle channel mods', async () => {
|
||||
const resp = importedModule.isChannelModerator(9999999);
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
|
||||
it('should handle channel mods', async () => {
|
||||
const resp = importedModule.isChannelTrusted(9999999);
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
|
||||
it('should handle channel mods', async () => {
|
||||
const resp = importedModule.isTrustedUser(9999999);
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
|
||||
it('should return false on bad nickname', async () => {
|
||||
const resp = importedModule.verifyNickname();
|
||||
expect(resp).to.be.false;
|
||||
});
|
||||
|
||||
it('should return default perms', async () => {
|
||||
const resp = importedModule.getUserPerms(false);
|
||||
expect(resp).to.be.an('object');
|
||||
});
|
||||
|
||||
it('should return admin level labels', async () => {
|
||||
const newConfig = Object.assign({}, mocks.core.appConfig.data);
|
||||
newConfig.adminTrip = 'Tt8H7c';
|
||||
const resp = importedModule.getUserPerms('test', 'salt', newConfig, 'cake');
|
||||
expect(resp).to.be.an('object');
|
||||
});
|
||||
|
||||
it('should return mod level labels', async () => {
|
||||
const newConfig = Object.assign({}, mocks.core.appConfig.data);
|
||||
newConfig.globalMods = [{
|
||||
trip: 'Tt8H7c',
|
||||
}];
|
||||
const resp = importedModule.getUserPerms('test', 'salt', newConfig, 'cake');
|
||||
expect(resp).to.be.an('object');
|
||||
});
|
||||
|
||||
it('should return ownership info', async () => {
|
||||
const newConfig = Object.assign({}, mocks.core.appConfig.data);
|
||||
newConfig.permissions['cake'] = {
|
||||
owned: true,
|
||||
};
|
||||
const resp = importedModule.getUserPerms('test', 'salt', newConfig, 'cake');
|
||||
expect(resp).to.be.an('object');
|
||||
});
|
||||
})
|
||||
@@ -0,0 +1,64 @@
|
||||
import { expect } from 'chai';
|
||||
import mocks from './mockImports.js';
|
||||
|
||||
const modulePath = '../commands/mod/unban.js';
|
||||
let importedModule;
|
||||
|
||||
const mockPayload = {
|
||||
cmd: 'unban',
|
||||
ip: '127.0.0.1',
|
||||
}
|
||||
|
||||
describe('Checking unban module', () => {
|
||||
// module meta data
|
||||
it('should be importable', async () => {
|
||||
importedModule = await import(modulePath);
|
||||
expect(importedModule).to.not.be.a('string');
|
||||
});
|
||||
|
||||
it('should be named', async () => {
|
||||
expect(importedModule.info.name).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be categorized', async () => {
|
||||
expect(importedModule.info.category).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be described', async () => {
|
||||
expect(importedModule.info.description).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be documented', async () => {
|
||||
expect(importedModule.info.usage).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be invokable', async () => {
|
||||
expect(importedModule.run).to.be.a('function');
|
||||
});
|
||||
|
||||
// module main function
|
||||
it('should be invokable only by a mod', async () => {
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: mockPayload,
|
||||
});
|
||||
|
||||
expect(resp).to.be.false;
|
||||
});
|
||||
|
||||
it('should require ip or hash', async () => {
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.authedSocket,
|
||||
payload: {
|
||||
cmd: 'ban',
|
||||
},
|
||||
});
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
|
||||
});
|
||||
@@ -0,0 +1,50 @@
|
||||
import { expect } from 'chai';
|
||||
import mocks from './mockImports.js';
|
||||
|
||||
const modulePath = '../commands/mod/unbanall.js';
|
||||
let importedModule;
|
||||
|
||||
const mockPayload = {
|
||||
cmd: 'unbanall',
|
||||
}
|
||||
|
||||
describe('Checking unbanall module', () => {
|
||||
// module meta data
|
||||
it('should be importable', async () => {
|
||||
importedModule = await import(modulePath);
|
||||
expect(importedModule).to.not.be.a('string');
|
||||
});
|
||||
|
||||
it('should be named', async () => {
|
||||
expect(importedModule.info.name).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be categorized', async () => {
|
||||
expect(importedModule.info.category).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be described', async () => {
|
||||
expect(importedModule.info.description).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be documented', async () => {
|
||||
expect(importedModule.info.usage).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be invokable', async () => {
|
||||
expect(importedModule.run).to.be.a('function');
|
||||
});
|
||||
|
||||
// module main function
|
||||
it('should be invokable only by a mod', async () => {
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: mockPayload,
|
||||
});
|
||||
|
||||
expect(resp).to.be.false;
|
||||
});
|
||||
|
||||
});
|
||||
@@ -0,0 +1,269 @@
|
||||
import { expect } from 'chai';
|
||||
import mocks from './mockImports.js';
|
||||
|
||||
const modulePath = '../commands/core/whisper.js';
|
||||
let importedModule;
|
||||
|
||||
const mockPayload = {
|
||||
cmd: 'whisper',
|
||||
text: 'testing',
|
||||
userid: 1234,
|
||||
nick: 'test',
|
||||
}
|
||||
|
||||
describe('Checking whisper module', () => {
|
||||
// module meta data
|
||||
it('should be importable', async () => {
|
||||
importedModule = await import(modulePath);
|
||||
expect(importedModule).to.not.be.a('string');
|
||||
});
|
||||
|
||||
it('should be named', async () => {
|
||||
expect(importedModule.info.name).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be categorized', async () => {
|
||||
expect(importedModule.info.category).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be described', async () => {
|
||||
expect(importedModule.info.description).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be documented', async () => {
|
||||
expect(importedModule.info.usage).to.be.a('string');
|
||||
});
|
||||
|
||||
it('should be invokable', async () => {
|
||||
expect(importedModule.run).to.be.a('function');
|
||||
});
|
||||
|
||||
// module main function
|
||||
it('should be invokable by all', async () => {
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: mockPayload,
|
||||
});
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
|
||||
it('should reject invalid text', async () => {
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: {
|
||||
cmd: 'whisper',
|
||||
text: false,
|
||||
},
|
||||
});
|
||||
|
||||
expect(resp).to.be.false;
|
||||
});
|
||||
|
||||
it('should handle legacy users', async () => {
|
||||
const newSocket = Object.assign({}, mocks.authedSocket);
|
||||
newSocket.hcProtocol = 1;
|
||||
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: newSocket,
|
||||
payload: mockPayload,
|
||||
});
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
|
||||
it('should ratelimit if required', async () => {
|
||||
const oldRL = mocks.server.police.frisk;
|
||||
mocks.server.police.frisk = () => true;
|
||||
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: mockPayload,
|
||||
});
|
||||
|
||||
mocks.server.police.frisk = oldRL;
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
|
||||
it('should handle 404 users', async () => {
|
||||
const newSocket = Object.assign({}, mocks.authedSocket);
|
||||
newSocket.hcProtocol = 1;
|
||||
|
||||
mocks.server.findSockets = (filterObj) => {
|
||||
return false;
|
||||
}
|
||||
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: newSocket,
|
||||
payload: mockPayload,
|
||||
});
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
|
||||
it('should handle legacy users in', async () => {
|
||||
const newSocket = Object.assign({}, mocks.authedSocket);
|
||||
newSocket.hcProtocol = 1;
|
||||
|
||||
mocks.server.findSockets = (filterObj) => {
|
||||
return [mocks.authedSocket];
|
||||
}
|
||||
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: newSocket,
|
||||
payload: mockPayload,
|
||||
});
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
|
||||
it('should handle legacy users out', async () => {
|
||||
const newSocket = Object.assign({}, mocks.authedSocket);
|
||||
newSocket.hcProtocol = 1;
|
||||
|
||||
mocks.server.findSockets = (filterObj) => {
|
||||
return [newSocket];
|
||||
}
|
||||
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: newSocket,
|
||||
payload: mockPayload,
|
||||
});
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
|
||||
it('should handle users out', async () => {
|
||||
const newSocket = Object.assign({}, mocks.authedSocket);
|
||||
|
||||
mocks.server.findSockets = (filterObj) => {
|
||||
return [newSocket];
|
||||
}
|
||||
|
||||
const resp = await importedModule.run({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: newSocket,
|
||||
payload: mockPayload,
|
||||
});
|
||||
|
||||
expect(resp).to.be.true;
|
||||
});
|
||||
|
||||
it('should initialize hooks', async () => {
|
||||
expect(() => importedModule.initHooks(mocks.server)).not.to.throw();
|
||||
});
|
||||
|
||||
it('should hook for /whisper chat commands, verifying params', async () => {
|
||||
const resp = importedModule.whisperCheck({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: {
|
||||
cmd: 'chat',
|
||||
text: false,
|
||||
},
|
||||
});
|
||||
|
||||
expect(resp).to.be.false;
|
||||
});
|
||||
|
||||
it('should hook for /whisper chat commands', async () => {
|
||||
const resp = importedModule.whisperCheck({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: {
|
||||
cmd: 'chat',
|
||||
text: '/whisper user stuff',
|
||||
},
|
||||
});
|
||||
|
||||
expect(resp).to.be.false;
|
||||
});
|
||||
|
||||
it('should hook for /w chat commands', async () => {
|
||||
const resp = importedModule.whisperCheck({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: {
|
||||
cmd: 'chat',
|
||||
text: '/w user stuff',
|
||||
},
|
||||
});
|
||||
|
||||
expect(resp).to.be.false;
|
||||
});
|
||||
|
||||
it('should hook for /w chat commands, validating params', async () => {
|
||||
const resp = importedModule.whisperCheck({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: {
|
||||
cmd: 'chat',
|
||||
text: '/whisper ',
|
||||
},
|
||||
});
|
||||
|
||||
expect(resp).to.be.false;
|
||||
});
|
||||
|
||||
it('should hook for /reply chat commands', async () => {
|
||||
const resp = importedModule.whisperCheck({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: {
|
||||
cmd: 'chat',
|
||||
text: '/reply ',
|
||||
},
|
||||
});
|
||||
|
||||
expect(resp).to.be.false;
|
||||
});
|
||||
|
||||
it('should hook for /r chat commands', async () => {
|
||||
const resp = importedModule.whisperCheck({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: {
|
||||
cmd: 'chat',
|
||||
text: '/r ',
|
||||
},
|
||||
});
|
||||
|
||||
expect(resp).to.be.false;
|
||||
});
|
||||
|
||||
it('should hook only certain triggers', async () => {
|
||||
const resp = importedModule.whisperCheck({
|
||||
core: mocks.core,
|
||||
server: mocks.server,
|
||||
socket: mocks.plebSocket,
|
||||
payload: {
|
||||
cmd: 'chat',
|
||||
text: 'normal text',
|
||||
},
|
||||
});
|
||||
|
||||
expect(resp).to.be.an('object');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user