Skip to content

Commit

Permalink
implemented #463
Browse files Browse the repository at this point in the history
  • Loading branch information
jcolson committed Nov 29, 2021
1 parent e0da0f5 commit 8aea17e
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 1 deletion.
78 changes: 78 additions & 0 deletions __test__/handlers/roll.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,21 @@ test('handleDiceRoll static 20', async () => {
);
});

test('handleDiceRoll error', async () => {
let msg = {};
let sendDirectOrFallbackToChannelError = jest.spyOn(utils, 'sendDirectOrFallbackToChannelError').mockImplementation((error, msg) => {
// console.debug('sendDirectOrFallbackToChannelError:', error);
});
jest.spyOn(utils, 'deleteMessage').mockImplementation((msg) => {
});
let diceParam = [{ 'value': 'x4d' }];
await testables.handleDiceRoll(msg, diceParam);
expect(sendDirectOrFallbackToChannelError).toHaveBeenCalledWith(
expect.objectContaining({ message: 'Expected "(", "-", "abs", "ceil", "cos", "d", "d%", "dF", "exp", "floor", "log", "max", "min", "pow", "round", "sign", "sin", "sqrt", "tan", "{", [0-9], or [1-9] but "x" found.' })
, msg
);
});

test('handleDiceRoll 1d20 default', async () => {
let msg = {};
let sendDirectOrFallbackToChannelEmbeds = jest.spyOn(utils, 'sendDirectOrFallbackToChannelEmbeds').mockImplementation((embedsArray, msg, user, skipDM) => {
Expand Down Expand Up @@ -77,7 +92,55 @@ test('handleDiceRoll 2d100', async () => {
expect.objectContaining({
'name': `Total`,
'value': expect.stringMatching(/^`\d*`$/)
})
])
})
]), msg, undefined, true
);
});

test('handleDiceRoll soooo many dice', async () => {
let msg = {};
let sendDirectOrFallbackToChannelEmbeds = jest.spyOn(utils, 'sendDirectOrFallbackToChannelEmbeds').mockImplementation((embedsArray, msg, user, skipDM) => {
// console.debug(embedsArray[0].fields, msg, user, skipDM);
});
jest.spyOn(utils, 'deleteMessage').mockImplementation((msg) => {
});
let diceParam = [{ 'value': '999d9999999999' }];
await testables.handleDiceRoll(msg, diceParam);
expect(sendDirectOrFallbackToChannelEmbeds).toHaveBeenCalledWith(
expect.arrayContaining([
expect.objectContaining({
'fields':
expect.arrayContaining([
expect.objectContaining({
'name': `${utils.EMOJIS.DICE}${diceParam[0].value}${utils.EMOJIS.DICE}`,
'value': expect.stringMatching(/^`\[(\d*(, )?)*(\])?`$/)
})
])
})
]), msg, undefined, true
);
expect(sendDirectOrFallbackToChannelEmbeds).toHaveBeenCalledWith(
expect.arrayContaining([
expect.objectContaining({
'fields':
expect.arrayContaining([
expect.objectContaining({
'value': expect.stringMatching(/^`... sooooo many dice! ...`$/)
})
])
})
]), msg, undefined, true
);
expect(sendDirectOrFallbackToChannelEmbeds).toHaveBeenCalledWith(
expect.arrayContaining([
expect.objectContaining({
'fields':
expect.arrayContaining([
expect.objectContaining({
'name': `Total`,
'value': expect.stringMatching(/^`\d*`$/)
})
])
})
Expand Down Expand Up @@ -201,4 +264,19 @@ test('handleDiceRollStats', async () => {
})
]), msg, undefined, true
);
});

test('handleDiceRollStats error', async () => {
let msg = { guild: 'error' };
let sendDirectOrFallbackToChannelError = jest.spyOn(utils, 'sendDirectOrFallbackToChannelError').mockImplementation((error, msg) => {
// console.debug('sendDirectOrFallbackToChannelError:', error);
});
jest.spyOn(utils, 'deleteMessage').mockImplementation((msg) => {
});
let diceParam = [{ 'value': 'x4d' }];
await testables.handleDiceRollStats(msg);
expect(sendDirectOrFallbackToChannelError).toHaveBeenCalledWith(
expect.objectContaining({ message: 'msg.guild?.iconURL is not a function' })
, msg
);
});
2 changes: 1 addition & 1 deletion handlers/roll.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ async function handleDiceRollStats(msg) {
.setColor(utils.COLORS.GREEN)
.setTitle(`${utils.EMOJIS.DICE}D&D 5E Stats Roll${utils.EMOJIS.DICE}`)
.setAuthor('D&D Vault', Config.dndVaultIcon, `${Config.httpServerURL}/?guildID=${msg.guild?.id}`)
.setThumbnail(msg.guild.iconURL());
.setThumbnail(msg.guild?.iconURL());
let statRollString = '';
let total = 0;
const DiceRoll = (await rpgdiceroller).DiceRoll;
Expand Down

0 comments on commit 8aea17e

Please sign in to comment.