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)
|
||||
}
|
||||
catch(e) {
|
||||
console.log(e);
|
||||
await message.reply(e.message);
|
||||
}
|
||||
|
||||
|
||||
@@ -127,7 +127,8 @@ describe('bot', () => {
|
||||
bot: false
|
||||
}
|
||||
}
|
||||
jest.spyOn(global.console, 'error').mockImplementation(() => {})
|
||||
jest.spyOn(global.console, 'error').mockImplementation(() => {
|
||||
})
|
||||
// Act
|
||||
await handleMessageCreate(message);
|
||||
// Assert
|
||||
@@ -223,7 +224,7 @@ describe('bot', () => {
|
||||
expect(commands.aliasesMap.get).toHaveBeenCalledWith('m');
|
||||
})
|
||||
|
||||
test("if command exists, call command.execute", () => {
|
||||
test("if command exists, call command.execute", async () => {
|
||||
// Arrange
|
||||
const message = {
|
||||
content: "pf;member test",
|
||||
@@ -240,7 +241,7 @@ describe('bot', () => {
|
||||
command.execute = jest.fn().mockResolvedValue();
|
||||
|
||||
// Act
|
||||
return handleMessageCreate(message).then(() => {
|
||||
await handleMessageCreate(message)
|
||||
// Assert
|
||||
expect(command.execute).toHaveBeenCalledTimes(1);
|
||||
expect(command.execute).toHaveBeenCalledWith(message, ['test']);
|
||||
@@ -264,7 +265,8 @@ describe('bot', () => {
|
||||
},
|
||||
reply: jest.fn()
|
||||
}
|
||||
jest.spyOn(global.console, 'error').mockImplementation(() => {})
|
||||
jest.spyOn(global.console, 'error').mockImplementation(() => {
|
||||
})
|
||||
// Act
|
||||
await handleMessageCreate(message);
|
||||
// Assert
|
||||
@@ -289,7 +291,6 @@ describe('bot', () => {
|
||||
expect(message.reply).toHaveBeenCalledWith(enums.err.COMMAND_NOT_RECOGNIZED);
|
||||
expect(message.reply).toHaveBeenCalledTimes(1);
|
||||
})
|
||||
})
|
||||
|
||||
test('login calls client.login with correct argument', async () => {
|
||||
// Arrange
|
||||
|
||||
@@ -72,28 +72,28 @@ describe('commands', () => {
|
||||
describe('memberCommand', () => {
|
||||
|
||||
|
||||
test('calls parseMemberCommand with the correct arguments', () => {
|
||||
test('calls parseMemberCommand with the correct arguments', async () => {
|
||||
// Arrange
|
||||
memberHelper.parseMemberCommand = jest.fn().mockResolvedValue("parsed command");
|
||||
// Act
|
||||
return commands.memberCommand(message, args).then(() => {
|
||||
await commands.memberCommand(message, args)
|
||||
// Assert
|
||||
expect(memberHelper.parseMemberCommand).toHaveBeenCalledTimes(1);
|
||||
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
|
||||
memberHelper.parseMemberCommand = jest.fn().mockImplementation(() => {
|
||||
throw new Error('error')
|
||||
});
|
||||
// Act
|
||||
return commands.memberCommand(message, args).catch(() => {
|
||||
await commands.memberCommand(message, args)
|
||||
// Assert
|
||||
expect(message.reply).toHaveBeenCalledTimes(1);
|
||||
expect(message.reply).toHaveBeenCalledWith('error');
|
||||
expect(console.error).toHaveBeenCalledWith(new Error('error'));
|
||||
});
|
||||
})
|
||||
|
||||
test('if parseMemberCommand returns embed, reply with embed', async () => {
|
||||
// Arrange
|
||||
@@ -105,7 +105,7 @@ describe('commands', () => {
|
||||
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
|
||||
const reply = {
|
||||
errors: ['error', 'error2'],
|
||||
@@ -114,39 +114,41 @@ describe('commands', () => {
|
||||
}
|
||||
memberHelper.parseMemberCommand = jest.fn().mockResolvedValue(reply);
|
||||
// Act
|
||||
return commands.memberCommand(message, args).catch(() => {
|
||||
await commands.memberCommand(message, args);
|
||||
// Assert
|
||||
expect(message.reply).toHaveBeenCalledTimes(1);
|
||||
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]
|
||||
})
|
||||
});
|
||||
})
|
||||
})
|
||||
|
||||
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"];
|
||||
message.content = "pf;import --help";
|
||||
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).toHaveBeenCalledWith(enums.help.IMPORT);
|
||||
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 = [""];
|
||||
message.content = 'pf;import'
|
||||
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).toHaveBeenCalledWith(enums.help.IMPORT);
|
||||
expect(importHelper.pluralKitImport).not.toHaveBeenCalled();
|
||||
})
|
||||
})
|
||||
|
||||
test('if attachment URL, call pluralKitImport with correct arguments', async () => {
|
||||
// Arrange
|
||||
|
||||
Reference in New Issue
Block a user