Skip to content

Commit

Permalink
Merge pull request CacheControl#64 from bjacobso/ben/add-facts
Browse files Browse the repository at this point in the history
Add factResults to condition json if available, increase auditability.
  • Loading branch information
CacheControl authored Jan 30, 2018
2 parents 48ee7b7 + 13f8e18 commit 3e35790
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/condition.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ export default class Condition {
props.operator = this.operator
props.value = this.value
props.fact = this.fact
if (this.factResult !== undefined) {
props.factResult = this.factResult
}
if (this.result !== undefined) {
props.result = this.result
}
if (this.params) {
props.params = this.params
}
Expand Down
2 changes: 1 addition & 1 deletion test/engine-event.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ describe('Engine: event', () => {
rule.on('success', successSpy)
await engine.run()
let ruleResult = successSpy.getCall(0).args[2]
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}'
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}'
expect(JSON.stringify(ruleResult)).to.equal(expected)
})
})
Expand Down

0 comments on commit 3e35790

Please sign in to comment.