|
| 1 | +import Help from '../../src/commands/help'; |
| 2 | +import Commands from '../../src/library/commands'; |
| 3 | +import { message as mockMessage, MockedMessage } from '../mocks/discord'; |
| 4 | + |
| 5 | +// TODO: These should be in a factory/mock |
| 6 | +const oneCommand = { |
| 7 | + name: 'one', |
| 8 | + description: 'I am number one.', |
| 9 | + execute: jest.fn() |
| 10 | +}; |
| 11 | + |
| 12 | +const twoCommand = { |
| 13 | + name: 'two', |
| 14 | + description: 'Two is not just a number.', |
| 15 | + execute: jest.fn() |
| 16 | +}; |
| 17 | + |
| 18 | +const blueFishCommand = { |
| 19 | + name: 'blueFish', |
| 20 | + description: 'Not a red fish.', |
| 21 | + execute: jest.fn() |
| 22 | +}; |
| 23 | + |
| 24 | +const commands = new Commands({ |
| 25 | + one: oneCommand, |
| 26 | + two: twoCommand, |
| 27 | + blueFish: blueFishCommand |
| 28 | +}); |
| 29 | + |
| 30 | +let sendMock: MockedMessage; |
| 31 | +let authorSend: MockedMessage; |
| 32 | +beforeEach(() => { |
| 33 | + sendMock = jest.fn(); |
| 34 | + mockMessage.reply = sendMock; |
| 35 | + authorSend = jest.fn(); |
| 36 | + // @ts-ignore |
| 37 | + mockMessage.author = { |
| 38 | + send: authorSend |
| 39 | + }; |
| 40 | +}); |
| 41 | + |
| 42 | +describe('Help Command', () => { |
| 43 | + describe('Execute', () => { |
| 44 | + beforeEach(() => { |
| 45 | + Help.execute([], mockMessage, { commands }); |
| 46 | + }); |
| 47 | + |
| 48 | + test('Lets you know to check your DMs', () => { |
| 49 | + expect(sendMock).lastCalledWith('sliding into your DMs...'); |
| 50 | + }); |
| 51 | + |
| 52 | + describe('DMs commands with prefix and descriptions', () => { |
| 53 | + let message: string; |
| 54 | + beforeEach(() => { |
| 55 | + message = authorSend.mock.calls[0][0]; |
| 56 | + }); |
| 57 | + |
| 58 | + test('Snarky', () => { |
| 59 | + const snark = "I am here to help! Well...mostly just make you chuckle " + |
| 60 | + "at this point, let's be honest."; |
| 61 | + expect(message).toContain(snark); |
| 62 | + }); |
| 63 | + |
| 64 | + test('Command pretext header', () => { |
| 65 | + const pretext = "Here is a list of the commands that we've got right now:"; |
| 66 | + expect(message).toContain(pretext); |
| 67 | + }); |
| 68 | + |
| 69 | + test('Code block start', () => { |
| 70 | + expect(message).toContain('```\n'); |
| 71 | + }); |
| 72 | + |
| 73 | + test('Code block end', () => { |
| 74 | + const lines = message.split('\n'); |
| 75 | + const lastLine = lines[lines.length - 1]; |
| 76 | + expect(lastLine).toEqual('```'); |
| 77 | + }); |
| 78 | + |
| 79 | + test('it still looks the same', () => { |
| 80 | + expect(message).toMatchSnapshot(); |
| 81 | + }); |
| 82 | + |
| 83 | + describe('Commands', () => { |
| 84 | + test('one command', () => { |
| 85 | + expect(message).toContain('!one'); |
| 86 | + }); |
| 87 | + |
| 88 | + test('one description', () => { |
| 89 | + expect(message).toContain(oneCommand.description); |
| 90 | + }); |
| 91 | + |
| 92 | + test('two command', () => { |
| 93 | + expect(message).toContain('!two'); |
| 94 | + }); |
| 95 | + |
| 96 | + test('two description', () => { |
| 97 | + expect(message).toContain(twoCommand.description); |
| 98 | + }); |
| 99 | + |
| 100 | + test('blueFish command', () => { |
| 101 | + expect(message).toContain('!blueFish'); |
| 102 | + }); |
| 103 | + |
| 104 | + test('BlueFish description', () => { |
| 105 | + expect(message).toContain(blueFishCommand.description); |
| 106 | + }); |
| 107 | + }); |
| 108 | + }); |
| 109 | + }); |
| 110 | +}); |
0 commit comments