Skip to content

Commit 3e35790

Browse files
authored
Merge pull request #64 from bjacobso/ben/add-facts
Add factResults to condition json if available, increase auditability.
2 parents 48ee7b7 + 13f8e18 commit 3e35790

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/condition.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ export default class Condition {
4949
props.operator = this.operator
5050
props.value = this.value
5151
props.fact = this.fact
52+
if (this.factResult !== undefined) {
53+
props.factResult = this.factResult
54+
}
55+
if (this.result !== undefined) {
56+
props.result = this.result
57+
}
5258
if (this.params) {
5359
props.params = this.params
5460
}

test/engine-event.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ describe('Engine: event', () => {
305305
rule.on('success', successSpy)
306306
await engine.run()
307307
let ruleResult = successSpy.getCall(0).args[2]
308-
let expected = '{"conditions":{"priority":1,"any":[{"operator":"greaterThanInclusive","value":21,"fact":"age"},{"operator":"equal","value":true,"fact":"qualified"}]},"event":{"type":"setDrinkingFlag","params":{"canOrderDrinks":true}},"priority":100,"result":true}'
308+
let expected = '{"conditions":{"priority":1,"any":[{"operator":"greaterThanInclusive","value":21,"fact":"age","factResult":21,"result":true},{"operator":"equal","value":true,"fact":"qualified","factResult":false,"result":false}]},"event":{"type":"setDrinkingFlag","params":{"canOrderDrinks":true}},"priority":100,"result":true}'
309309
expect(JSON.stringify(ruleResult)).to.equal(expected)
310310
})
311311
})

0 commit comments

Comments
 (0)