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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -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
|
||||||
@@ -289,7 +291,6 @@ 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
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user