(options = {})
| 59 | } |
| 60 | |
| 61 | function setup (options = {}) { |
| 62 | const engine = new Engine() |
| 63 | highPrioritySpy = sandbox.spy() |
| 64 | lowPrioritySpy = sandbox.spy() |
| 65 | |
| 66 | engine.addRule({ |
| 67 | name: 'first', |
| 68 | priority: 10, |
| 69 | conditions: { |
| 70 | all: [{ |
| 71 | fact: 'high-priority', |
| 72 | params: { |
| 73 | factParam |
| 74 | }, |
| 75 | operator: 'contains', |
| 76 | path: '$.values', |
| 77 | value: options.highPriorityValue |
| 78 | }, { |
| 79 | fact: 'low-priority', |
| 80 | operator: 'in', |
| 81 | value: options.lowPriorityValue |
| 82 | }] |
| 83 | }, |
| 84 | event: event1, |
| 85 | onSuccess: async (event, almanac, ruleResults) => { |
| 86 | expect(ruleResults.name).to.equal('first') |
| 87 | expect(ruleResults.event).to.deep.equal(event1) |
| 88 | expect(ruleResults.priority).to.equal(10) |
| 89 | expect(ruleResults.conditions).to.deep.equal(expectedFirstRuleResult) |
| 90 | |
| 91 | return delay(almanac.addRuntimeFact('rule-created-fact', { array: options.highPriorityValue })) |
| 92 | } |
| 93 | }) |
| 94 | |
| 95 | engine.addRule({ |
| 96 | name: 'second', |
| 97 | priority: 1, |
| 98 | conditions: { |
| 99 | all: [{ |
| 100 | fact: 'high-priority', |
| 101 | params: { |
| 102 | factParam |
| 103 | }, |
| 104 | operator: 'containsDivisibleValuesOf', |
| 105 | path: '$.values', |
| 106 | value: { |
| 107 | fact: 'rule-created-fact', |
| 108 | path: '$.array' // set by 'success' of first rule |
| 109 | } |
| 110 | }] |
| 111 | }, |
| 112 | event: event2 |
| 113 | }) |
| 114 | |
| 115 | engine.addOperator('containsDivisibleValuesOf', (factValue, jsonValue) => { |
| 116 | return factValue.some(v => v % jsonValue === 0) |
| 117 | }) |
| 118 |
no test coverage detected
searching dependent graphs…