-
Notifications
You must be signed in to change notification settings - Fork 488
/
Copy pathengine-custom-properties.test.js
65 lines (59 loc) · 2.05 KB
/
engine-custom-properties.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
'use strict'
import engineFactory, { Fact, Rule } from '../src/index'
describe('Engine: custom properties', () => {
let engine
const event = { type: 'generic' }
describe('all conditions', () => {
it('preserves custom properties set on fact', () => {
engine = engineFactory()
const fact = new Fact('age', 12)
fact.customId = 'uuid'
engine.addFact(fact)
expect(engine.facts.get('age')).to.have.property('customId')
expect(engine.facts.get('age').customId).to.equal(fact.customId)
})
describe('conditions', () => {
it('preserves custom properties set on boolean conditions', () => {
engine = engineFactory()
const conditions = {
customId: 'uuid1',
all: [{
fact: 'age',
operator: 'greaterThanInclusive',
value: 18
}]
}
const rule = factories.rule({ conditions, event })
engine.addRule(rule)
expect(engine.rules[0].conditions).to.have.property('customId')
})
it('preserves custom properties set on regular conditions', () => {
engine = engineFactory()
const conditions = {
all: [{
customId: 'uuid',
fact: 'age',
operator: 'greaterThanInclusive',
value: 18
}]
}
const rule = factories.rule({ conditions, event })
engine.addRule(rule)
expect(engine.rules[0].conditions.all[0]).to.have.property('customId')
expect(engine.rules[0].conditions.all[0].customId).equal('uuid')
})
})
it('preserves custom properties set on regular conditions', () => {
engine = engineFactory()
const rule = new Rule()
const ruleProperties = factories.rule()
rule.setPriority(ruleProperties.priority)
.setConditions(ruleProperties.conditions)
.setEvent(ruleProperties.event)
rule.customId = 'uuid'
engine.addRule(rule)
expect(engine.rules[0]).to.have.property('customId')
expect(engine.rules[0].customId).equal('uuid')
})
})
})