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