(fix) attack handler, more tests. (#30)

This commit is contained in:
2021-05-01 09:12:07 +02:00
committed by GitHub
parent f22df0dec1
commit 351c90577f
3 changed files with 84 additions and 13 deletions

View File

@ -130,16 +130,81 @@ it('returns false ', () => {
}); });
// main function // main function
/*
it('should abort with a message', () => { it('should abort with a message: no entry found', () => {
const reply = jest.fn(str => str);
const message = { const message = {
reply: function (e) { reply: reply,
throw new Error(e);
},
}; };
const err = 'error';
const handleAttack = rewireUtils.__get__('handleAttack'); const handleAttack = rewireUtils.__get__('handleAttack');
expect(handleAttack(err)).toThrowError(); //expect(handleAttack(err)).toThrowError();
//expect(handleAttack(null, [])).toThrowError(); expect(handleAttack(null, [], { message: message })).toEqual(
'Sorry, für dich habe ich leider keinen Eintrag 😥'
);
});
it('should abort with a message: No such weapon', () => {
const reply = jest.fn(str => str);
const message = {
reply: reply,
};
const handleAttack = rewireUtils.__get__('handleAttack');
const args = [''];
expect(handleAttack(null, [{ character: {} }], { message: message, args: args })).toEqual(
'Diese Waffe gibt es nicht.'
);
});
it('complete run with melee weapon', () => {
const reply = jest.fn(str => str);
const message = {
reply: reply,
};
const character = {
attributes: [
{ id: 'mut', level: 10 },
{ id: 'fingerfertigkeit', level: 10 },
{ id: 'klugheit', level: 10 },
{ id: 'intuition', level: 10 },
{ id: 'charisma', level: 10 },
{ id: 'gewandtheit', level: 16 },
{ id: 'konstitution', level: 10 },
{ id: 'koerperkraft', level: 10 },
],
combattechniques: [{ id: 'dolche', level: 8 }],
};
const handleAttack = rewireUtils.__get__('handleAttack');
const args = ['messer'];
expect(
handleAttack(null, [{ character: character }], { message: message, args: args })
).toEqual(expect.any(String));
});
it('complete run with ranged weapon', () => {
const reply = jest.fn(str => str);
const message = {
reply: reply,
};
const character = {
attributes: [
{ id: 'mut', level: 10 },
{ id: 'fingerfertigkeit', level: 14 },
{ id: 'klugheit', level: 10 },
{ id: 'intuition', level: 10 },
{ id: 'charisma', level: 10 },
{ id: 'gewandtheit', level: 16 },
{ id: 'konstitution', level: 10 },
{ id: 'koerperkraft', level: 10 },
],
combattechniques: [{ id: 'boegen', level: 8 }],
};
const handleAttack = rewireUtils.__get__('handleAttack');
const args = ['langbogen'];
expect(
handleAttack(null, [{ character: character }], { message: message, args: args })
).toEqual(expect.any(String));
}); });
*/

View File

@ -13,14 +13,16 @@ module.exports = {
async exec(message, args) { async exec(message, args) {
try { try {
db.find({ user: message.author.tag }, (err, docs) => handleAttack(err, docs, message)); db.find({ user: message.author.tag }, (err, docs) =>
handleAttack(err, docs, { message: message, args: args })
);
} catch (e) { } catch (e) {
throw e; throw e;
} }
}, },
}; };
function handleAttack(err, docs, message) { function handleAttack(err, docs, { message: message, args: args }) {
if (docs.length === 0) { if (docs.length === 0) {
return message.reply(findMessage('NOENTRY')); return message.reply(findMessage('NOENTRY'));
} }
@ -76,7 +78,11 @@ function handleAttack(err, docs, message) {
Damage = AttackResult.DoubleDamage ? (Damage *= 2) : Damage; Damage = AttackResult.DoubleDamage ? (Damage *= 2) : Damage;
Reply += '\n\nHier aufklappen, wenn der Gegner nicht parieren/Ausweichen konnte:\n'; Reply += '\n\nHier aufklappen, wenn der Gegner nicht parieren/Ausweichen konnte:\n';
Reply += `|| ${Weapon.name} (${Weapon.dice}W6+${Weapon.diemodificator}) richtet ${Damage} schaden an.`; Reply += `|| ${Weapon.name} (${Weapon.dice}W6+${
Weapon.diemodificator
}) richtet ${Damage} schaden an. ${
AttackBonus ? `(+${AttackBonus} Bonus auf Leiteigenschaft)` : ''
}`;
Reply += '\nDeine 🎲: ` ' + DamageDice.join(',') + ' `.||\n'; Reply += '\nDeine 🎲: ` ' + DamageDice.join(',') + ' `.||\n';
} }

View File

@ -1,6 +1,6 @@
{ {
"name": "dsabot", "name": "dsabot",
"version": "1.5.0", "version": "1.5.2",
"description": "", "description": "",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {