forked from PluralFlux/PluralFlux
forgot to switch over some tests in bot.test and commands.test
This commit is contained in:
@@ -35,7 +35,6 @@ cmds.memberCommand = async function(message, args) {
|
|||||||
reply = await memberHelper.parseMemberCommand(message.author.id, authorFull, args, attachmentUrl, attachmentExpires)
|
reply = await memberHelper.parseMemberCommand(message.author.id, authorFull, args, attachmentUrl, attachmentExpires)
|
||||||
}
|
}
|
||||||
catch(e) {
|
catch(e) {
|
||||||
console.log(e);
|
|
||||||
await message.reply(e.message);
|
await message.reply(e.message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ describe('bot', () => {
|
|||||||
|
|
||||||
describe('handleMessageCreate', () => {
|
describe('handleMessageCreate', () => {
|
||||||
|
|
||||||
test('on message creation, if message is from bot, return', async() => {
|
test('on message creation, if message is from bot, return', async () => {
|
||||||
// Arrange
|
// Arrange
|
||||||
const message = {
|
const message = {
|
||||||
author: {
|
author: {
|
||||||
@@ -87,7 +87,7 @@ describe('bot', () => {
|
|||||||
expect(res).toBeUndefined();
|
expect(res).toBeUndefined();
|
||||||
})
|
})
|
||||||
|
|
||||||
test('on message creation, if message is empty, return', async() => {
|
test('on message creation, if message is empty, return', async () => {
|
||||||
// Arrange
|
// Arrange
|
||||||
const message = {
|
const message = {
|
||||||
content: " ",
|
content: " ",
|
||||||
@@ -127,7 +127,8 @@ describe('bot', () => {
|
|||||||
bot: false
|
bot: false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
jest.spyOn(global.console, 'error').mockImplementation(() => {})
|
jest.spyOn(global.console, 'error').mockImplementation(() => {
|
||||||
|
})
|
||||||
// Act
|
// Act
|
||||||
await handleMessageCreate(message);
|
await handleMessageCreate(message);
|
||||||
// Assert
|
// Assert
|
||||||
@@ -137,7 +138,7 @@ describe('bot', () => {
|
|||||||
expect(console.error).toHaveBeenCalledWith(new Error('error'));
|
expect(console.error).toHaveBeenCalledWith(new Error('error'));
|
||||||
})
|
})
|
||||||
|
|
||||||
test("if no command after prefix, return correct enum", async() => {
|
test("if no command after prefix, return correct enum", async () => {
|
||||||
// Arrange
|
// Arrange
|
||||||
const message = {
|
const message = {
|
||||||
content: "pf;",
|
content: "pf;",
|
||||||
@@ -154,7 +155,7 @@ describe('bot', () => {
|
|||||||
expect(webhookHelper.sendMessageAsMember).not.toHaveBeenCalled();
|
expect(webhookHelper.sendMessageAsMember).not.toHaveBeenCalled();
|
||||||
})
|
})
|
||||||
|
|
||||||
test("if command after prefix, call parseCommandArgs and commandsMap.get", async() => {
|
test("if command after prefix, call parseCommandArgs and commandsMap.get", async () => {
|
||||||
// Arrange
|
// Arrange
|
||||||
const message = {
|
const message = {
|
||||||
content: "pf;help",
|
content: "pf;help",
|
||||||
@@ -177,7 +178,7 @@ describe('bot', () => {
|
|||||||
expect(webhookHelper.sendMessageAsMember).not.toHaveBeenCalled();
|
expect(webhookHelper.sendMessageAsMember).not.toHaveBeenCalled();
|
||||||
})
|
})
|
||||||
|
|
||||||
test('if commands.commandsMap.get returns undefined, call aliasesMap.get and commandsMap.get again with that value', async() => {
|
test('if commands.commandsMap.get returns undefined, call aliasesMap.get and commandsMap.get again with that value', async () => {
|
||||||
// Arrange
|
// Arrange
|
||||||
const message = {
|
const message = {
|
||||||
content: "pf;m",
|
content: "pf;m",
|
||||||
@@ -202,7 +203,7 @@ describe('bot', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
test('if aliasesMap.get returns undefined, do not call commandsMap again', async() => {
|
test('if aliasesMap.get returns undefined, do not call commandsMap again', async () => {
|
||||||
// Arrange
|
// Arrange
|
||||||
const message = {
|
const message = {
|
||||||
content: "pf;m",
|
content: "pf;m",
|
||||||
@@ -223,7 +224,7 @@ describe('bot', () => {
|
|||||||
expect(commands.aliasesMap.get).toHaveBeenCalledWith('m');
|
expect(commands.aliasesMap.get).toHaveBeenCalledWith('m');
|
||||||
})
|
})
|
||||||
|
|
||||||
test("if command exists, call command.execute", () => {
|
test("if command exists, call command.execute", async () => {
|
||||||
// Arrange
|
// Arrange
|
||||||
const message = {
|
const message = {
|
||||||
content: "pf;member test",
|
content: "pf;member test",
|
||||||
@@ -240,7 +241,7 @@ describe('bot', () => {
|
|||||||
command.execute = jest.fn().mockResolvedValue();
|
command.execute = jest.fn().mockResolvedValue();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
return handleMessageCreate(message).then(() => {
|
await handleMessageCreate(message)
|
||||||
// Assert
|
// Assert
|
||||||
expect(command.execute).toHaveBeenCalledTimes(1);
|
expect(command.execute).toHaveBeenCalledTimes(1);
|
||||||
expect(command.execute).toHaveBeenCalledWith(message, ['test']);
|
expect(command.execute).toHaveBeenCalledWith(message, ['test']);
|
||||||
@@ -264,7 +265,8 @@ describe('bot', () => {
|
|||||||
},
|
},
|
||||||
reply: jest.fn()
|
reply: jest.fn()
|
||||||
}
|
}
|
||||||
jest.spyOn(global.console, 'error').mockImplementation(() => {})
|
jest.spyOn(global.console, 'error').mockImplementation(() => {
|
||||||
|
})
|
||||||
// Act
|
// Act
|
||||||
await handleMessageCreate(message);
|
await handleMessageCreate(message);
|
||||||
// Assert
|
// Assert
|
||||||
@@ -272,7 +274,7 @@ describe('bot', () => {
|
|||||||
expect(console.error).toHaveBeenCalledWith(new Error('error'))
|
expect(console.error).toHaveBeenCalledWith(new Error('error'))
|
||||||
})
|
})
|
||||||
|
|
||||||
test("if command does not exist, return correct enum", async() => {
|
test("if command does not exist, return correct enum", async () => {
|
||||||
// Arrange
|
// Arrange
|
||||||
commands.commandsMap.get = jest.fn().mockReturnValue();
|
commands.commandsMap.get = jest.fn().mockReturnValue();
|
||||||
commands.aliasesMap.get = jest.fn().mockReturnValue();
|
commands.aliasesMap.get = jest.fn().mockReturnValue();
|
||||||
@@ -289,9 +291,8 @@ describe('bot', () => {
|
|||||||
expect(message.reply).toHaveBeenCalledWith(enums.err.COMMAND_NOT_RECOGNIZED);
|
expect(message.reply).toHaveBeenCalledWith(enums.err.COMMAND_NOT_RECOGNIZED);
|
||||||
expect(message.reply).toHaveBeenCalledTimes(1);
|
expect(message.reply).toHaveBeenCalledTimes(1);
|
||||||
})
|
})
|
||||||
})
|
|
||||||
|
|
||||||
test('login calls client.login with correct argument', async() => {
|
test('login calls client.login with correct argument', async () => {
|
||||||
// Arrange
|
// Arrange
|
||||||
client.login = jest.fn().mockResolvedValue();
|
client.login = jest.fn().mockResolvedValue();
|
||||||
// Act
|
// Act
|
||||||
|
|||||||
@@ -72,28 +72,28 @@ describe('commands', () => {
|
|||||||
describe('memberCommand', () => {
|
describe('memberCommand', () => {
|
||||||
|
|
||||||
|
|
||||||
test('calls parseMemberCommand with the correct arguments', () => {
|
test('calls parseMemberCommand with the correct arguments', async () => {
|
||||||
// Arrange
|
// Arrange
|
||||||
memberHelper.parseMemberCommand = jest.fn().mockResolvedValue("parsed command");
|
memberHelper.parseMemberCommand = jest.fn().mockResolvedValue("parsed command");
|
||||||
// Act
|
// Act
|
||||||
return commands.memberCommand(message, args).then(() => {
|
await commands.memberCommand(message, args)
|
||||||
|
// Assert
|
||||||
expect(memberHelper.parseMemberCommand).toHaveBeenCalledTimes(1);
|
expect(memberHelper.parseMemberCommand).toHaveBeenCalledTimes(1);
|
||||||
expect(memberHelper.parseMemberCommand).toHaveBeenCalledWith(authorId, `${username}#${discriminator}`, args, attachmentUrl, attachmentExpiration);
|
expect(memberHelper.parseMemberCommand).toHaveBeenCalledWith(authorId, `${username}#${discriminator}`, args, attachmentUrl, attachmentExpiration);
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
|
||||||
test('if parseMemberCommand returns error, log error and reply with error', () => {
|
test('if parseMemberCommand returns error, log error and reply with error', async () => {
|
||||||
// Arrange
|
// Arrange
|
||||||
memberHelper.parseMemberCommand = jest.fn().mockImplementation(() => {
|
memberHelper.parseMemberCommand = jest.fn().mockImplementation(() => {
|
||||||
throw new Error('error')
|
throw new Error('error')
|
||||||
});
|
});
|
||||||
// Act
|
// Act
|
||||||
return commands.memberCommand(message, args).catch(() => {
|
await commands.memberCommand(message, args)
|
||||||
|
// Assert
|
||||||
expect(message.reply).toHaveBeenCalledTimes(1);
|
expect(message.reply).toHaveBeenCalledTimes(1);
|
||||||
expect(message.reply).toHaveBeenCalledWith('error');
|
expect(message.reply).toHaveBeenCalledWith('error');
|
||||||
expect(console.error).toHaveBeenCalledWith(new Error('error'));
|
|
||||||
});
|
});
|
||||||
})
|
|
||||||
|
|
||||||
test('if parseMemberCommand returns embed, reply with embed', async () => {
|
test('if parseMemberCommand returns embed, reply with embed', async () => {
|
||||||
// Arrange
|
// Arrange
|
||||||
@@ -105,7 +105,7 @@ describe('commands', () => {
|
|||||||
expect(message.reply).toHaveBeenCalledWith({embeds: [embed]})
|
expect(message.reply).toHaveBeenCalledWith({embeds: [embed]})
|
||||||
})
|
})
|
||||||
|
|
||||||
test('if parseMemberCommand returns object, reply with embed and content', () => {
|
test('if parseMemberCommand returns object, reply with embed and content', async () => {
|
||||||
// Arrange
|
// Arrange
|
||||||
const reply = {
|
const reply = {
|
||||||
errors: ['error', 'error2'],
|
errors: ['error', 'error2'],
|
||||||
@@ -114,39 +114,41 @@ describe('commands', () => {
|
|||||||
}
|
}
|
||||||
memberHelper.parseMemberCommand = jest.fn().mockResolvedValue(reply);
|
memberHelper.parseMemberCommand = jest.fn().mockResolvedValue(reply);
|
||||||
// Act
|
// Act
|
||||||
return commands.memberCommand(message, args).catch(() => {
|
await commands.memberCommand(message, args);
|
||||||
// Assert
|
// Assert
|
||||||
expect(message.reply).toHaveBeenCalledTimes(1);
|
expect(message.reply).toHaveBeenCalledTimes(1);
|
||||||
expect(message.reply).toHaveBeenCalledWith({
|
expect(message.reply).toHaveBeenCalledWith({
|
||||||
content: `success\n\n${enums.err.ERRORS_OCCURRED}\n\nerror\nerror2}`,
|
content: `success\n\n${enums.err.ERRORS_OCCURRED}\n\nerror\nerror2`,
|
||||||
embeds: [reply.embed]
|
embeds: [reply.embed]
|
||||||
})
|
})
|
||||||
});
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('importCommand', () => {
|
describe('importCommand', () => {
|
||||||
test('if message includes --help and no attachmentURL, return help message', () => {
|
test('if message includes --help and no attachmentURL, return help message', async () => {
|
||||||
|
// Arrange
|
||||||
const args = ["--help"];
|
const args = ["--help"];
|
||||||
message.content = "pf;import --help";
|
message.content = "pf;import --help";
|
||||||
message.attachments.size = 0;
|
message.attachments.size = 0;
|
||||||
return commands.importCommand(message, args).then(() => {
|
// Act
|
||||||
|
await commands.importCommand(message, args)
|
||||||
|
// Assert
|
||||||
expect(message.reply).toHaveBeenCalledTimes(1);
|
expect(message.reply).toHaveBeenCalledTimes(1);
|
||||||
expect(message.reply).toHaveBeenCalledWith(enums.help.IMPORT);
|
expect(message.reply).toHaveBeenCalledWith(enums.help.IMPORT);
|
||||||
expect(importHelper.pluralKitImport).not.toHaveBeenCalled();
|
expect(importHelper.pluralKitImport).not.toHaveBeenCalled();
|
||||||
})
|
})
|
||||||
})
|
|
||||||
|
|
||||||
test('if no args and no attachmentURL, return help message', () => {
|
test('if no args and no attachmentURL, return help message', async () => {
|
||||||
|
// Arrange
|
||||||
const args = [""];
|
const args = [""];
|
||||||
message.content = 'pf;import'
|
message.content = 'pf;import'
|
||||||
message.attachments.size = 0;
|
message.attachments.size = 0;
|
||||||
return commands.importCommand(message, args).then(() => {
|
// Act
|
||||||
|
await commands.importCommand(message, args)
|
||||||
|
// Assert
|
||||||
expect(message.reply).toHaveBeenCalledTimes(1);
|
expect(message.reply).toHaveBeenCalledTimes(1);
|
||||||
expect(message.reply).toHaveBeenCalledWith(enums.help.IMPORT);
|
expect(message.reply).toHaveBeenCalledWith(enums.help.IMPORT);
|
||||||
expect(importHelper.pluralKitImport).not.toHaveBeenCalled();
|
expect(importHelper.pluralKitImport).not.toHaveBeenCalled();
|
||||||
})
|
})
|
||||||
})
|
|
||||||
|
|
||||||
test('if attachment URL, call pluralKitImport with correct arguments', async () => {
|
test('if attachment URL, call pluralKitImport with correct arguments', async () => {
|
||||||
// Arrange
|
// Arrange
|
||||||
@@ -195,7 +197,7 @@ describe('commands', () => {
|
|||||||
expect(message.reply).toHaveBeenCalledWith(expected);
|
expect(message.reply).toHaveBeenCalledWith(expected);
|
||||||
})
|
})
|
||||||
|
|
||||||
test('if pluralKitImport returns one error, reply with error', async() => {
|
test('if pluralKitImport returns one error, reply with error', async () => {
|
||||||
// Arrange
|
// Arrange
|
||||||
importHelper.pluralKitImport = jest.fn().mockImplementation(() => {
|
importHelper.pluralKitImport = jest.fn().mockImplementation(() => {
|
||||||
throw new Error('error');
|
throw new Error('error');
|
||||||
|
|||||||
Reference in New Issue
Block a user