-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathsymbol.spec.js
47 lines (44 loc) · 1.09 KB
/
symbol.spec.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
const { Rools, Rule } = require('../src');
require('./setup');
describe('Rools.evaluate() / facts with symbol properties', () => {
let rools;
before(async () => {
rools = new Rools();
const foo = Symbol.for('foo');
const rule1 = new Rule({
name: 'symbol test rule 1',
when: (facts) => facts[foo].bar,
then: (facts) => {
facts[foo].baz = 'great';
},
});
const rule2 = new Rule({
name: 'symbol test rule 2',
when: (facts) => facts[foo].baz === 'great',
then: (facts) => {
facts[foo].qux = 'great';
},
});
await rools.register([rule1, rule2]);
});
it('should evaluate rules', async () => {
const foo = Symbol.for('foo');
const facts = {
[foo]: {
bar: true,
quux: false,
},
};
const { updated, fired } = await rools.evaluate(facts);
expect(facts).to.be.deep.equal({
[foo]: {
bar: true,
quux: false,
baz: 'great',
qux: 'great',
},
});
expect(updated).to.be.deep.equal([foo]);
expect(fired).to.be.equal(2);
});
});