Files
DiceCloud/app/imports/api/engine/computation/buildComputation/tests/linkCalculationDependencies.testFn.js
Stefan Zermatten 1a14393031 Parsed calculations are now cached between calculations
Parsing is one of the more expensive computations done to characters, so 
the parser results are now stored on the DB and only updated if they are 
dirty. A hash is used to determine if the calculation has changed since 
the last computation
2021-10-03 20:59:04 +02:00

64 lines
1.7 KiB
JavaScript

import { buildComputationFromProps } from '/imports/api/engine/computation/buildCreatureComputation.js';
import { assert } from 'chai';
import clean from '../../utility/cleanProp.testFn.js';
export default function(){
const computation = buildComputationFromProps(testProperties);
const hasLink = computation.dependencyGraph.hasLink;
const prop = (id) => computation.propsById[id];
assert.isTrue(
!!hasLink('childId', 'spellListId'),
'Ancestor references of parent in inline calculations should create dependency'
);
assert.isTrue(
!!hasLink('grandchildId', 'spellListId'),
'References to higher ancestor should create dependency'
);
assert.isTrue(
!!hasLink('grandchildId', 'strength'),
'Variable references create dependencies'
);
assert.isTrue(
!!hasLink('grandchildId', 'wisdom'),
'Variable references create dependencies even if the attributes don\'t exist'
);
assert.equal(
prop('strengthId').baseValue.parseError.message, 'Unexpected end of input',
'Parse errors should be stored on the calculation doc'
);
}
var testProperties = [
clean({
_id: 'spellListId',
type: 'spellList',
ancestors: [{id: 'charId'}],
}),
clean({
_id: 'childId',
type: 'spell',
description: {
text: 'DC {#spellList.dc} save or suck'
},
ancestors: [{id: 'charId'}, {id: 'spellListId'}],
}),
clean({
_id: 'grandchildId',
type: 'savingThrow',
dc: {
calculation: '#spellList.dc + strength + wisdom.modifier'
},
ancestors: [{id: 'charId'}, {id: 'spellListId'}, {id: 'childId'}],
}),
clean({
_id: 'strengthId',
type: 'attribute',
variableName: 'strength',
baseValue: {
calculation: '15 + ',
},
ancestors: [{id: 'charId'}],
}),
];