-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
80d4cbe
commit 09f86d6
Showing
2 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
const Rools = require('..'); | ||
require('./setup'); | ||
|
||
describe('Rules.evaluate() / refraction', () => { | ||
const spy = sinon.spy(); | ||
|
||
const rule1 = { | ||
name: 'rule1', | ||
when: facts => facts.fact1, | ||
then: (facts) => { facts.fact1 = false; facts.fact1 = true; spy(); }, | ||
priority: 10, | ||
}; | ||
|
||
const rule2 = { | ||
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); | ||
}); | ||
}); |