add some spell related tests

This commit is contained in:
Phillip Thelen
2024-05-17 11:35:14 +02:00
parent 33181c0ac4
commit 709a14fd51
3 changed files with 64 additions and 2 deletions

View File

@@ -0,0 +1,63 @@
import {
generateUser,
} from '../helpers/common.helper';
import spells from '../../website/common/script/content/spells';
import {
expectValidTranslationString,
} from '../helpers/content.helper';
import { TRANSFORMATION_DEBUFFS_LIST } from '../../website/common/script/constants';
// TODO complete the test suite...
describe('shared.ops.spells', () => {
let user;
let target;
beforeEach(() => {
user = generateUser();
target = generateUser();
});
it('all spells have required properties', () => {
for (const category of Object.values(spells)) {
for (const spell of Object.values(category)) {
expectValidTranslationString(spell.text, spell.key);
expectValidTranslationString(spell.notes);
expect(spell.target, spell.key).to.be.oneOf(['self', 'party', 'task', 'tasks', 'user']);
}
}
});
it('all special spells have a working cast method', async () => {
for (const s of Object.values(spells.special)) {
user.items.special[s.key] = 1;
s.cast(user, target, { language: 'en' });
}
});
it('all debuff spells cost 5 gold', () => {
for (const s of Object.values(spells.special)) {
if (s.purchaseType === 'debuffPotion') {
user.stats.gp = 5;
s.cast(user);
expect(user.stats.gp).to.equal(0);
}
}
});
it('all debuff spells remove the buff', () => {
const debuffMapping = {};
Object.keys(TRANSFORMATION_DEBUFFS_LIST).forEach(key => {
debuffMapping[TRANSFORMATION_DEBUFFS_LIST[key]] = key;
});
for (const s of Object.values(spells.special)) {
if (s.purchaseType === 'debuffPotion') {
user.stats.gp = 5;
user.stats.buffs[debuffMapping[s.key]] = true;
expect(user.stats.buffs[debuffMapping[s.key]]).to.equal(true);
s.cast(user);
expect(user.stats.buffs[debuffMapping[s.key]]).to.equal(false);
}
}
});
});

View File

@@ -59,6 +59,7 @@ export const REPEATING_EVENTS = {
items: [ items: [
'virtualpet', 'virtualpet',
'waffle', 'waffle',
'fungi',
], ],
}, },
{ {

View File

@@ -1,12 +1,10 @@
import each from 'lodash/each'; import each from 'lodash/each';
import moment from 'moment';
import t from './translation'; import t from './translation';
import { NotAuthorized, BadRequest } from '../libs/errors'; import { NotAuthorized, BadRequest } from '../libs/errors';
import statsComputed from '../libs/statsComputed'; // eslint-disable-line import/no-cycle import statsComputed from '../libs/statsComputed'; // eslint-disable-line import/no-cycle
import setDebuffPotionItems from '../libs/setDebuffPotionItems'; // eslint-disable-line import/no-cycle import setDebuffPotionItems from '../libs/setDebuffPotionItems'; // eslint-disable-line import/no-cycle
import crit from '../fns/crit'; // eslint-disable-line import/no-cycle import crit from '../fns/crit'; // eslint-disable-line import/no-cycle
import updateStats from '../fns/updateStats'; import updateStats from '../fns/updateStats';
import { EVENTS } from './constants';
/* /*
--------------------------------------------------------------- ---------------------------------------------------------------