-
Notifications
You must be signed in to change notification settings - Fork 488
/
Copy pathengine-not.test.js
54 lines (49 loc) · 1.18 KB
/
engine-not.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
'use strict'
import sinon from 'sinon'
import engineFactory from '../src/index'
describe('Engine: "not" conditions', () => {
let engine
let sandbox
before(() => {
sandbox = sinon.createSandbox()
})
afterEach(() => {
sandbox.restore()
})
describe('supports a single "not" condition', () => {
const event = {
type: 'ageTrigger',
params: {
demographic: 'under50'
}
}
const conditions = {
not: {
fact: 'age',
operator: 'greaterThanInclusive',
value: 50
}
}
let eventSpy
let ageSpy
beforeEach(() => {
eventSpy = sandbox.spy()
ageSpy = sandbox.stub()
const rule = factories.rule({ conditions, event })
engine = engineFactory()
engine.addRule(rule)
engine.addFact('age', ageSpy)
engine.on('success', eventSpy)
})
it('emits when the condition is met', async () => {
ageSpy.returns(10)
await engine.run()
expect(eventSpy).to.have.been.calledWith(event)
})
it('does not emit when the condition fails', () => {
ageSpy.returns(75)
engine.run()
expect(eventSpy).to.not.have.been.calledWith(event)
})
})
})