Skip to content

Commit 86f046e

Browse files
#419 add test for 'wrong' way to set conditions
1 parent 8a01446 commit 86f046e

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

test/engine.test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,20 @@ describe('Engine', () => {
102102
expect(rule2.conditions.all.length).to.equal(2)
103103
})
104104

105+
it('updates rule incorrectly', async () => {
106+
const rule1 = new Rule(factories.rule({ name: 'rule1' }))
107+
engine.addRule(rule1)
108+
109+
rule1.conditions = { all: [] } // Rule.conditions should not be set to a value that is not an instance of Condition
110+
engine.updateRule(rule1)
111+
112+
const successSpy = sandbox.spy()
113+
rule1.on('success', successSpy)
114+
await engine.run()
115+
const ruleResult = successSpy.getCall(0).args[2]
116+
expect(() => JSON.stringify(ruleResult)).to.throw(/toJSON is not a function/)
117+
})
118+
105119
it('should throw error if rule not found', () => {
106120
const rule1 = new Rule(factories.rule({ name: 'rule1' }))
107121
engine.addRule(rule1)

0 commit comments

Comments
 (0)