Files
DiceCloud/app/imports/api/engine/action/applyProperties/applyAdjustmentProperty.test.ts
2025-01-25 14:29:26 +02:00

166 lines
3.9 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { assert } from 'chai';
import {
allMutations,
createTestCreature,
getRandomIds,
removeAllCreaturesAndProps,
runActionById,
TestCreature
} from '/imports/api/engine/action/functions/actionEngineTest.testFn';
const [
creatureId, targetCreatureId, targetCreature2Id, adjustmentToTargetId, adjustmentToSelfId, targetCreatureStrengthId, targetCreature2StrengthId, selfDexterityId
] = getRandomIds(100);
const actionTestCreature: TestCreature = {
_id: creatureId,
props: [
{
_id: adjustmentToTargetId,
type: 'adjustment',
target: 'target',
stat: 'strength',
operation: 'increment',
amount: { calculation: '2' }
},
{
_id: adjustmentToSelfId,
type: 'adjustment',
target: 'self',
stat: 'dexterity',
operation: 'set',
amount: { calculation: '11' }
},
{
_id: selfDexterityId,
type: 'attribute',
name: 'Dexterity',
attributeType: 'ability',
variableName: 'dexterity',
baseValue: { calculation: '13' },
},
],
}
const actionTargetCreature: TestCreature = {
_id: targetCreatureId,
props: [
{
_id: targetCreatureStrengthId,
type: 'attribute',
attributeType: 'ability',
variableName: 'strength',
baseValue: { calculation: '12' },
}
]
}
const actionTargetCreature2: TestCreature = {
_id: targetCreature2Id,
props: [
{
_id: targetCreature2StrengthId,
type: 'attribute',
attributeType: 'ability',
variableName: 'strength',
baseValue: { calculation: '18' },
}
]
}
describe('Apply Adjustment Properties', function () {
// Increase timeout
this.timeout(8000);
before(async function () {
await removeAllCreaturesAndProps();
await createTestCreature(actionTestCreature);
await createTestCreature(actionTargetCreature);
await createTestCreature(actionTargetCreature2);
});
it('Adjusts the attributes of self', async function () {
const action = await runActionById(adjustmentToSelfId);
assert.exists(action);
assert.deepEqual(allMutations(action), [{
contents: [
{
inline: true,
name: 'Attribute damage',
value: 'Dexterity set from 13 to 11',
}
],
targetIds: [creatureId],
updates: [
{
propId: selfDexterityId,
type: 'attribute',
set: { damage: 2, value: 11 },
},
],
}]);
});
it('Adjusts the attributes of a single target', async function () {
const action = await runActionById(adjustmentToTargetId, [targetCreatureId]);
assert.exists(action);
assert.deepEqual(allMutations(action), [{
contents: [
{
inline: true,
name: 'Ability damaged',
value: '2 Attribute',
}
],
targetIds: [targetCreatureId],
updates: [
{
propId: targetCreatureStrengthId,
type: 'attribute',
inc: { damage: 2, value: -2 },
},
],
}]);
});
it('Adjusts the attributes of multiple targets', async function () {
const action = await runActionById(adjustmentToTargetId, [
targetCreatureId, targetCreature2Id
]);
assert.exists(action);
assert.deepEqual(allMutations(action), [{
contents: [
{
inline: true,
name: 'Ability damaged',
value: '2 Attribute',
}
],
targetIds: [targetCreatureId],
updates: [
{
propId: targetCreatureStrengthId,
type: 'attribute',
inc: { damage: 2, value: -2 },
},
],
}, {
contents: [
{
inline: true,
name: 'Ability damaged',
value: '2 Attribute',
}
],
targetIds: [targetCreature2Id],
updates: [
{
propId: targetCreature2StrengthId,
type: 'attribute',
inc: { damage: 2, value: -2 },
},
],
}]);
});
});