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