-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathrefraction.spec.js
40 lines (34 loc) · 1 KB
/
refraction.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
const { Rools, Rule } = require('..');
require('./setup');
describe('Rools.evaluate() / refraction', () => {
const spy = sinon.spy();
const rule1 = new Rule({
name: 'rule1',
when: (facts) => facts.fact1,
then: (facts) => { facts.fact1 = false; facts.fact1 = true; spy(); },
priority: 10,
});
const rule2 = new Rule({
name: 'rule2',
when: (facts) => facts.fact2,
then: (facts) => { facts.fact1 = false; facts.fact1 = true; },
});
const facts = {
fact1: true,
fact2: true,
};
it('should fire each rule only once / recursive', async () => {
spy.resetHistory();
const rools = new Rools();
await rools.register([rule1]);
await rools.evaluate(facts);
expect(spy.calledOnce).to.be.equal(true);
});
it('should fire each rule only once / transitive', async () => {
spy.resetHistory();
const rools = new Rools();
await rools.register([rule1, rule2]);
await rools.evaluate(facts);
expect(spy.calledOnce).to.be.equal(true);
});
});