1
0
mirror of https://github.com/hack-chat/main.git synced 2024-03-22 13:20:33 +08:00
hack-chat-main/test/removemod.test.js

82 lines
2.0 KiB
JavaScript
Raw Normal View History

2022-06-23 00:32:51 +08:00
import { expect } from 'chai';
import mocks from './mockImports.js';
const modulePath = '../commands/admin/removemod.js';
let importedModule;
const mockPayload = {
cmd: 'removemod',
2023-12-30 14:09:24 +08:00
trip: 'XVeP3T',
2022-06-23 00:32:51 +08:00
}
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 () => {
2023-12-30 14:09:24 +08:00
const newCore = Object.assign({}, mocks.core);
2022-06-23 00:32:51 +08:00
const resp = await importedModule.run({
2023-12-30 14:09:24 +08:00
core: newCore,
2022-06-23 00:32:51 +08:00
server: mocks.server,
socket: mocks.plebSocket,
payload: mockPayload,
});
expect(resp).to.be.false;
});
it('should remove trip from the config', async () => {
2023-12-30 14:09:24 +08:00
const newCore = Object.assign({}, mocks.core);
2022-06-23 00:32:51 +08:00
const resp = await importedModule.run({
2023-12-30 14:09:24 +08:00
core: newCore,
2022-06-23 00:32:51 +08:00
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 () => {
2023-12-30 14:09:24 +08:00
const newCore = Object.assign({}, mocks.core);
2022-06-23 00:32:51 +08:00
mocks.server.findSockets = () => {
return [{}];
}
const resp = await importedModule.run({
2023-12-30 14:09:24 +08:00
core: newCore,
2022-06-23 00:32:51 +08:00
server: mocks.server,
socket: mocks.authedSocket,
payload: mockPayload,
});
expect(resp).to.be.true;
});
});