Skip to content

Commit cb5f3c7

Browse files
there are no condition references in the result
1 parent c688692 commit cb5f3c7

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

test/engine-event.test.js

+33
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ describe('Engine: event', () => {
2020
canOrderDrinks: true
2121
}
2222
}
23+
24+
const awesomeEvent = {
25+
type: 'awesome'
26+
}
2327
/**
2428
* sets up a simple 'any' rule with 2 conditions
2529
*/
@@ -92,6 +96,26 @@ describe('Engine: event', () => {
9296
engine.addFact('gender', 'male') // gender succeeds
9397
}
9498

99+
function setupWithConditionReference () {
100+
const conditionName = 'awesomeCondition'
101+
const conditions = {
102+
any: [{ condition: conditionName }]
103+
}
104+
engine = engineFactory()
105+
const ruleOptions = { conditions, event: awesomeEvent, priority: 100 }
106+
const rule = factories.rule(ruleOptions)
107+
engine.addRule(rule)
108+
engine.setCondition(conditionName, {
109+
all: [{
110+
name: 'over 21',
111+
fact: 'age',
112+
operator: 'greaterThanInclusive',
113+
value: 21
114+
}]
115+
})
116+
engine.addFact('age', 21)
117+
}
118+
95119
context('engine events: simple', () => {
96120
beforeEach(() => simpleSetup())
97121

@@ -602,4 +626,13 @@ describe('Engine: event', () => {
602626
expect(JSON.stringify(ruleResult)).to.equal(expected)
603627
})
604628
})
629+
630+
context('rule events: json serializing with condition reference', () => {
631+
beforeEach(() => setupWithConditionReference())
632+
it('serializes properties', async () => {
633+
const { results: [ruleResult] } = await engine.run()
634+
const expected = '{"conditions":{"priority":1,"any":[{"priority":1,"all":[{"name":"over 21","operator":"greaterThanInclusive","value":21,"fact":"age","factResult":21,"result":true}]}]},"event":{"type":"awesome"},"priority":100,"result":true}'
635+
expect(JSON.stringify(ruleResult)).to.equal(expected)
636+
})
637+
})
605638
})

types/index.d.ts

-2
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,6 @@ type ConditionReference = {
229229
name?: string;
230230
priority?: number;
231231
};
232-
type ConditionReferenceResult = ConditionReference & ConditionResultProperties;
233232
export type TopLevelCondition =
234233
| AllConditions
235234
| AnyConditions
@@ -239,4 +238,3 @@ export type TopLevelConditionResult =
239238
| AllConditionsResult
240239
| AnyConditionsResult
241240
| NotConditionsResult
242-
| ConditionReferenceResult

0 commit comments

Comments
 (0)