Added failing test case for #316 trigger match bug
This commit is contained in:
@@ -35,7 +35,7 @@ export function applyTrigger(trigger, prop, actionContext) {
|
||||
if (trigger.inactive) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Prevent triggers from firing if their condition is false
|
||||
if (trigger.condition?.parseNode) {
|
||||
recalculateCalculation(trigger.condition, actionContext);
|
||||
@@ -61,11 +61,11 @@ export function applyTrigger(trigger, prop, actionContext) {
|
||||
value: trigger.description,
|
||||
inline: false,
|
||||
}
|
||||
if (trigger.description?.text){
|
||||
if (trigger.description?.text) {
|
||||
recalculateInlineCalculations(trigger.description, actionContext);
|
||||
content.value = trigger.description.value;
|
||||
}
|
||||
if(!trigger.silent) actionContext.addLog(content);
|
||||
if (!trigger.silent) actionContext.addLog(content);
|
||||
|
||||
// Get all the trigger's properties and apply them
|
||||
const properties = getPropertyDecendants(actionContext.creature._id, trigger._id);
|
||||
@@ -78,7 +78,7 @@ export function applyTrigger(trigger, prop, actionContext) {
|
||||
trigger.firing = false;
|
||||
}
|
||||
|
||||
function triggerMatchTags(trigger, prop) {
|
||||
export function triggerMatchTags(trigger, prop) {
|
||||
let matched = false;
|
||||
const propTags = getEffectivePropTags(prop);
|
||||
// Check the target tags
|
||||
|
||||
67
app/imports/api/engine/actions/applyTriggers.testFn.js
Normal file
67
app/imports/api/engine/actions/applyTriggers.testFn.js
Normal file
@@ -0,0 +1,67 @@
|
||||
import { triggerMatchTags } from '/imports/api/engine/actions/applyTriggers.js';
|
||||
import clean from '/imports/api/engine/computation/utility/cleanProp.testFn.js';
|
||||
import { assert } from 'chai';
|
||||
|
||||
export default function () {
|
||||
const prop = clean({
|
||||
id: 'propWithTags',
|
||||
type: 'action',
|
||||
tags: ['yes1', 'notUsed', 'no1', 'yes2', 'no2', 'or1', 'or2'],
|
||||
});
|
||||
const positiveProp = clean({
|
||||
id: 'propWithTags',
|
||||
type: 'action',
|
||||
tags: ['yes1', 'notUsed', 'yes2', 'or1', 'or2'],
|
||||
});
|
||||
assert.isTrue(
|
||||
triggerMatchTags(clean({
|
||||
type: 'trigger',
|
||||
targetTags: ['yes1'],
|
||||
}), prop),
|
||||
'Trigger matches on a single target tag'
|
||||
);
|
||||
assert.isTrue(
|
||||
triggerMatchTags(clean({
|
||||
type: 'trigger',
|
||||
targetTags: ['yes1', 'yes2'],
|
||||
}), prop),
|
||||
'Trigger matches on a multiple target tags'
|
||||
);
|
||||
assert.isFalse(
|
||||
triggerMatchTags(clean({
|
||||
type: 'trigger',
|
||||
targetTags: ['yes1'],
|
||||
extraTags: [{ operation: 'NOT', tags: ['no1'] }]
|
||||
}), prop),
|
||||
'Trigger correctly fails to match when not tags are present'
|
||||
);
|
||||
assert.isFalse(
|
||||
triggerMatchTags(clean({
|
||||
type: 'trigger',
|
||||
extraTags: [{ operation: 'NOT', tags: ['no1'] }]
|
||||
}), prop),
|
||||
'Trigger correctly fails to match when only not tags are present'
|
||||
);
|
||||
assert.isTrue(
|
||||
triggerMatchTags(clean({
|
||||
type: 'trigger',
|
||||
extraTags: [{ operation: 'NOT', tags: ['no1'] }]
|
||||
}), positiveProp),
|
||||
'Trigger matches when only not tags are present'
|
||||
);
|
||||
assert.isTrue(
|
||||
triggerMatchTags(clean({
|
||||
type: 'trigger',
|
||||
extraTags: [{ operation: 'Or', tags: ['or1'] }]
|
||||
}), positiveProp),
|
||||
'Trigger matches when OR tags are present'
|
||||
);
|
||||
assert.isTrue(
|
||||
triggerMatchTags(clean({
|
||||
type: 'trigger',
|
||||
targetTags: ['missing1'],
|
||||
extraTags: [{ operation: 'Or', tags: ['or1'] }]
|
||||
}), positiveProp),
|
||||
'Trigger matches when only OR tags are present'
|
||||
);
|
||||
}
|
||||
@@ -1,16 +1,17 @@
|
||||
import '/imports/api/simpleSchemaConfig.js';
|
||||
//import testTypes from './testTypes/index.js';
|
||||
import applyTriggers from '/imports/api/engine/actions/applyTriggers.testFn.js';
|
||||
import { doActionWork } from './doAction.js';
|
||||
import { CreatureLogSchema } from '/imports/api/creature/log/CreatureLogs.js';
|
||||
import CreatureProperties from '/imports/api/creature/creatureProperties/CreatureProperties.js';
|
||||
import Creatures from '/imports/api/creature/creatures/Creatures.js';
|
||||
|
||||
function cleanProp(prop){
|
||||
function cleanProp(prop) {
|
||||
let schema = CreatureProperties.simpleSchema(prop);
|
||||
return schema.clean(prop);
|
||||
}
|
||||
|
||||
function cleanCreature(creature){
|
||||
function cleanCreature(creature) {
|
||||
let schema = Creatures.simpleSchema(creature);
|
||||
return schema.clean(creature);
|
||||
}
|
||||
@@ -28,7 +29,7 @@ const testActionContext = {
|
||||
}),
|
||||
scope: {},
|
||||
addLog(content) {
|
||||
if (content.name || content.value){
|
||||
if (content.name || content.value) {
|
||||
this.log.content.push(content);
|
||||
}
|
||||
},
|
||||
@@ -40,8 +41,8 @@ const action = cleanProp({
|
||||
});
|
||||
const actionAncestors = [];
|
||||
|
||||
describe('Do Action', function(){
|
||||
it('Does an empty action', function(){
|
||||
describe('Do Action', function () {
|
||||
it('Does an empty action', function () {
|
||||
doActionWork({
|
||||
properties: [action],
|
||||
ancestors: actionAncestors,
|
||||
@@ -51,3 +52,7 @@ describe('Do Action', function(){
|
||||
});
|
||||
//testTypes.forEach(test => it(test.text, test.fn));
|
||||
});
|
||||
|
||||
describe('Action utility functions', function () {
|
||||
it('Triggers match tags', applyTriggers);
|
||||
})
|
||||
|
||||
28
app/package-lock.json
generated
28
app/package-lock.json
generated
@@ -178,6 +178,12 @@
|
||||
"integrity": "sha512-wOuvG1SN4Us4rez+tylwwwCV1psiNVOkJeM3AUWUNWg/jDQY2+HE/444y5gc+jBmRqASOm2Oeh5c1axHobwRKQ==",
|
||||
"dev": true
|
||||
},
|
||||
"@types/mocha": {
|
||||
"version": "10.0.1",
|
||||
"resolved": "https://registry.npmjs.org/@types/mocha/-/mocha-10.0.1.tgz",
|
||||
"integrity": "sha512-/fvYntiO1GeICvqbQ3doGDIP97vWmvFt83GKguJ6prmQM2iXZfFcq6YE8KteFyRtX2/h5Hf91BYvPodJKFYv5Q==",
|
||||
"dev": true
|
||||
},
|
||||
"@types/semver": {
|
||||
"version": "7.3.13",
|
||||
"resolved": "https://registry.npmjs.org/@types/semver/-/semver-7.3.13.tgz",
|
||||
@@ -585,9 +591,9 @@
|
||||
"integrity": "sha512-DMD0KiN46eipeziST1LPP/STfDU0sufISXmjSgvVsoU2tqxctQeASejWcfNtxYKqETM1UxQ8sp2OrSBWpHY6sw=="
|
||||
},
|
||||
"aws-sdk": {
|
||||
"version": "2.1326.0",
|
||||
"resolved": "https://registry.npmjs.org/aws-sdk/-/aws-sdk-2.1326.0.tgz",
|
||||
"integrity": "sha512-LSGiO4RSooupHnkvYbPOuOYqwAxmcnYinwIxBz4P1YI8ulhZZ/pypOj/HKqC629UyhY1ndSMtlM1l56U74UclA==",
|
||||
"version": "2.1358.0",
|
||||
"resolved": "https://registry.npmjs.org/aws-sdk/-/aws-sdk-2.1358.0.tgz",
|
||||
"integrity": "sha512-ZolqFlnm0mDNgub7FGrVi7r5A1rw+58zZziKhlis3IxOtIpHdx4BQU5pH4htAMuD0Ct557p/dC/wmnZH/1Rc9Q==",
|
||||
"requires": {
|
||||
"buffer": "4.9.2",
|
||||
"events": "1.1.1",
|
||||
@@ -598,7 +604,7 @@
|
||||
"url": "0.10.3",
|
||||
"util": "^0.12.4",
|
||||
"uuid": "8.0.0",
|
||||
"xml2js": "0.4.19"
|
||||
"xml2js": "0.5.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"uuid": {
|
||||
@@ -3830,18 +3836,18 @@
|
||||
"integrity": "sha512-kQ/dHIzuLrS6Je9+uv81ueZomEwH0qVYstcAQ4/Z93K8zeko9gtAbttJWzoC5ukqXY1PpoouV3+VSOqEAFt5wg=="
|
||||
},
|
||||
"xml2js": {
|
||||
"version": "0.4.19",
|
||||
"resolved": "https://registry.npmjs.org/xml2js/-/xml2js-0.4.19.tgz",
|
||||
"integrity": "sha512-esZnJZJOiJR9wWKMyuvSE1y6Dq5LCuJanqhxslH2bxM6duahNZ+HMpCLhBQGZkbX6xRf8x1Y2eJlgt2q3qo49Q==",
|
||||
"version": "0.5.0",
|
||||
"resolved": "https://registry.npmjs.org/xml2js/-/xml2js-0.5.0.tgz",
|
||||
"integrity": "sha512-drPFnkQJik/O+uPKpqSgr22mpuFHqKdbS835iAQrUC73L2F5WkboIRd63ai/2Yg6I1jzifPFKH2NTK+cfglkIA==",
|
||||
"requires": {
|
||||
"sax": ">=0.6.0",
|
||||
"xmlbuilder": "~9.0.1"
|
||||
"xmlbuilder": "~11.0.0"
|
||||
}
|
||||
},
|
||||
"xmlbuilder": {
|
||||
"version": "9.0.7",
|
||||
"resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-9.0.7.tgz",
|
||||
"integrity": "sha512-7YXTQc3P2l9+0rjaUbLwMKRhtmwg1M1eDf6nag7urC7pIPYLD9W/jmzQ4ptRSUbodw5S0jfoGTflLemQibSpeQ=="
|
||||
"version": "11.0.1",
|
||||
"resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-11.0.1.tgz",
|
||||
"integrity": "sha512-fDlsI/kFEx7gLvbecc0/ohLG50fugQp8ryHzMTuW9vSa1GJ0XYWKnhsUx7oie3G98+r56aTQIUB4kht42R3JvA=="
|
||||
},
|
||||
"yallist": {
|
||||
"version": "4.0.0",
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
"@babel/runtime": "^7.21.0",
|
||||
"@chenfengyuan/vue-countdown": "^1.1.5",
|
||||
"@tozd/vue-observer-utils": "^0.5.0",
|
||||
"aws-sdk": "^2.1326.0",
|
||||
"aws-sdk": "^2.1358.0",
|
||||
"bcrypt": "^5.1.0",
|
||||
"chroma-js": "^2.4.2",
|
||||
"css-box-shadow": "^1.0.0-3",
|
||||
@@ -58,6 +58,7 @@
|
||||
"vuex": "^3.1.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/mocha": "^10.0.1",
|
||||
"@typescript-eslint/eslint-plugin": "^5.54.0",
|
||||
"@typescript-eslint/parser": "^5.54.0",
|
||||
"@vue/compiler-dom": "^3.2.47",
|
||||
|
||||
Reference in New Issue
Block a user