allowUndefinedFacts not working when the facts type are string
Here's my example, you can reproduce the issue with the code:
const customAttributeRule = { "name": "allowUndefinedFacts-test", "attributes": [ { "name": "Astring", "type": "string" }, { "name": "Bnumber", "type": "number" } ], "decisions": [ { "conditions": { "all": [ { "fact": "Astring", "operator": "notEqual", "value": "string" } ] }, "event": { "type": "Astring", "params": { "value": "1", "description": "Astring test" } } }, { "conditions": { "all": [ { "fact": "Bnumber", "operator": "lessThan", "value": 5 } ] }, "event": { "type": "Bnumber", "params": { "value": "1", "description": "Bnumber test" } } } ] }
let facts = {}
const engine = new Engine(customAttributeRule.decisions, {allowUndefinedFacts: true}); engine.on('success', event => { console.log(event) });
let result = engine .run(facts)
The engine output is
{ type: 'Astring', params: { value: '1', description: 'Astring test' } }
However, the allowUndefinedFacts works when then fact type is number
Since the engine treat undefined facts as undefined, so I added another condition that { "fact": "Astring", "operator": "notEqual", "value": "undefined" }, but it still does not work as expected
I believe the issue lies not with the string or number, but with the operator and how it evaluates the facts.
For instance, when I pass the condition
{ "fact": "Bnumber", "operator": "notEqual", "value": 5 },
it still returns the rule with this condition, as it assumes that if the fact is not provided, undefined is not equal to 5, which is correct.
However, with other operators like equal, lessThan, or in, the behaviour is as expected: they do not match undefined with any condition and do not return the rules.