Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RC v2.1.0 #113

Merged
merged 28 commits into from
Apr 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
0e02829
fix(package): update @types/jest to version 25.1.0
greenkeeper[bot] Jan 27, 2020
4b99813
chore(package): update lockfile package-lock.json
greenkeeper[bot] Jan 27, 2020
e4ba6b8
chore(package): update ts-jest to version 25.1.0
greenkeeper[bot] Jan 30, 2020
d559760
chore(package): update lockfile package-lock.json
greenkeeper[bot] Jan 30, 2020
62c76d4
fix(package): update @types/node to version 13.7.2
greenkeeper[bot] Feb 18, 2020
024d8a6
chore(package): update lockfile package-lock.json
greenkeeper[bot] Feb 18, 2020
51fed73
Add: Tests for Help Command
ctsstc Apr 10, 2020
8a4c561
Fix: Prevent console errors from showing in the middle of search's te…
ctsstc Apr 10, 2020
a7e516e
Edit: SOOOO MUCH REFACTORING
ctsstc Apr 11, 2020
7535920
Edit: Changed my mind!
ctsstc Apr 11, 2020
8e02ac0
SR: Fix spelling
ctsstc Apr 11, 2020
cce729b
SR: Remove unused import
ctsstc Apr 11, 2020
ba5626b
SR: Check reference, not deep equals
ctsstc Apr 11, 2020
219eb11
SR: Add snapshot for help message
ctsstc Apr 11, 2020
cb8a998
SR: Remove trailing comma
ctsstc Apr 11, 2020
a470b82
PR: Lint autofix
ctsstc Apr 11, 2020
47d3d36
SR: remove unused import
ctsstc Apr 11, 2020
ad6e528
SR: Make linter happy
ctsstc Apr 11, 2020
086e06d
Edit: Update version v2.0.4 --> v2.1.0
ctsstc Apr 20, 2020
3d6f57e
Merge remote-tracking branch 'origin/greenkeeper/@types/node-13.7.2' …
ctsstc Apr 20, 2020
28a948e
Update: node version & explicitly set in nvmrc
ctsstc Apr 20, 2020
93ab189
Update: heroku round 2, trying for a node version
ctsstc Apr 20, 2020
0bc28d4
Update: nvmrc to appease travis
ctsstc Apr 20, 2020
9cfcdfc
Update: Looks like audit fix changes
ctsstc Apr 24, 2020
a197e55
Merge remote-tracking branch 'origin/greenkeeper/ts-jest-25.1.0' into…
ctsstc Apr 24, 2020
84a6fd1
Edit: Supress TS error
ctsstc Apr 24, 2020
b47b0d0
Merge remote-tracking branch 'origin/greenkeeper/@types/jest-25.1.0' …
ctsstc Apr 24, 2020
d4686d7
Update: jest to match ts-jest and @type/jest
ctsstc Apr 24, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
node
v13.7
12 changes: 12 additions & 0 deletions __tests__/commands/__snapshots__/help.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Help Command Execute DMs commands with prefix and descriptions it still looks the same 1`] = `
"I am here to help! Well...mostly just make you chuckle at this point, let's be honest.

Here is a list of the commands that we've got right now:
\`\`\`
!one → I am number one.
!two → Two is not just a number.
!blueFish → Not a red fish.
\`\`\`"
`;
110 changes: 110 additions & 0 deletions __tests__/commands/help.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import Help from '../../src/commands/help';
import Commands from '../../src/library/commands';
import { message as mockMessage, MockedMessage } from '../mocks/discord';

// TODO: These should be in a factory/mock
const oneCommand = {
name: 'one',
description: 'I am number one.',
execute: jest.fn()
};

const twoCommand = {
name: 'two',
description: 'Two is not just a number.',
execute: jest.fn()
};

const blueFishCommand = {
name: 'blueFish',
description: 'Not a red fish.',
execute: jest.fn()
};

const commands = new Commands({
one: oneCommand,
two: twoCommand,
blueFish: blueFishCommand
});

let sendMock: MockedMessage;
let authorSend: MockedMessage;
beforeEach(() => {
sendMock = jest.fn();
mockMessage.reply = sendMock;
authorSend = jest.fn();
// @ts-ignore
mockMessage.author = {
send: authorSend
};
});

describe('Help Command', () => {
describe('Execute', () => {
beforeEach(() => {
Help.execute([], mockMessage, { commands });
});

test('Lets you know to check your DMs', () => {
expect(sendMock).lastCalledWith('sliding into your DMs...');
});

describe('DMs commands with prefix and descriptions', () => {
let message: string;
beforeEach(() => {
message = authorSend.mock.calls[0][0];
});

test('Snarky', () => {
const snark = "I am here to help! Well...mostly just make you chuckle " +
"at this point, let's be honest.";
expect(message).toContain(snark);
});

test('Command pretext header', () => {
const pretext = "Here is a list of the commands that we've got right now:";
expect(message).toContain(pretext);
});

test('Code block start', () => {
expect(message).toContain('```\n');
});

test('Code block end', () => {
const lines = message.split('\n');
const lastLine = lines[lines.length - 1];
expect(lastLine).toEqual('```');
});

test('it still looks the same', () => {
expect(message).toMatchSnapshot();
});

describe('Commands', () => {
test('one command', () => {
expect(message).toContain('!one');
});

test('one description', () => {
expect(message).toContain(oneCommand.description);
});

test('two command', () => {
expect(message).toContain('!two');
});

test('two description', () => {
expect(message).toContain(twoCommand.description);
});

test('blueFish command', () => {
expect(message).toContain('!blueFish');
});

test('BlueFish description', () => {
expect(message).toContain(blueFishCommand.description);
});
});
});
});
});
24 changes: 19 additions & 5 deletions __tests__/commands/search.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,24 @@ describe('Search Command', () => {
await Search.execute(['dingusy'], mockMessage);
expect(sendMock).lastCalledWith(results.items[0].link);
});
test('Malformed Response', async () => {
const mockedData = Promise.resolve({ data: {} });
axiosMock.get.mockResolvedValueOnce(mockedData);
await Search.execute(['NOPE'], mockMessage);
expect(sendMock).lastCalledWith("I'm Sorry Dave, I'm afraid I can't do that...");
describe('Malformed Response', () => {
let consoleErrorMock: jest.SpyInstance<void, any>;
beforeEach(async () => {
const mockedData = Promise.resolve({ data: {} });
axiosMock.get.mockResolvedValueOnce(mockedData);
consoleErrorMock = jest.spyOn(console, 'error')
.mockImplementation(() => undefined); // Prevent it from spewing into the test results
await Search.execute(['NOPE'], mockMessage);
});
afterEach(() => {
consoleErrorMock.mockRestore();
});
test('Responds with error message', async () => {
expect(sendMock).lastCalledWith("I'm Sorry Dave, I'm afraid I can't do that...");
});
test('Console logs an error', () => {
const errorMessage = "Malformed Google Search Response: {}";
expect(consoleErrorMock).lastCalledWith(errorMessage);
});
});
});
5 changes: 3 additions & 2 deletions __tests__/library/commandLoader.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import glob from 'glob';
import CommandLoader, { ICommandClasses } from '../../src/library/commandLoader';
import { COMMANDS_PATH_GLOB } from './../../src/library/commands';

describe('CommandLoader', () => {
let commandClasses: ICommandClasses;
const files = glob.sync(COMMANDS_PATH_GLOB);
const commandsPathGlob = './src/commands/*.ts';
const files = glob.sync(commandsPathGlob);

beforeEach(() => {
commandClasses = CommandLoader.getCommandClasses(files);
Expand All @@ -16,6 +16,7 @@ describe('CommandLoader', () => {
});
});

// More of an integration test against real commands
describe('Class names match their file names', () => {
test('they match their key name', () => {
for (let commandName of Object.keys(commandClasses)) {
Expand Down
45 changes: 36 additions & 9 deletions __tests__/library/commands.test.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,43 @@
import { ICommandClasses } from '../../src/library/commandLoader';
import Commands from '../../src/library/commands';
import ICommand from '../../src/library/iCommand';

// TODO: I feel like this class is too basic to test,
// and ultimately a wrapper for other classes that have been tested
// Might just remove it some day
describe('Commands', () => {
const commands = new Commands();
test('Has a command', () => {
expect(Object.keys(commands.all).length).toBeGreaterThan(0);
expect(commands.names.length).toBeGreaterThan(0);
let mockHelloCommand: ICommand;
let mockYetAnotherCommand: ICommand;
let mockCommands: ICommandClasses;
let commands: Commands;

beforeEach(() => {
// TODO: these should probably go into a factory/mock
mockHelloCommand = {
name: 'Hello',
description: 'Hello World',
execute: jest.fn()
};
mockYetAnotherCommand = {
name: 'YAC',
description: 'Yet Another Command!',
execute: jest.fn()
};
mockCommands = {
hello: mockHelloCommand,
yac: mockYetAnotherCommand
};
commands = new Commands(mockCommands);
});

test('.names returns command names', () => {
const commandNames = ['hello', 'yac'];
expect(commands.names).toEqual(commandNames);
});

test('Can fetch a command', () => {
const first = commands.names[0];
expect(commands.get(first)).not.toBeUndefined();
const helloCommand = commands.get('hello');
expect(helloCommand).toBe(mockHelloCommand);
});

test('Finds the longest name', () => {
expect(commands.longestNameLength()).toEqual(5);
});
});
Loading