✅ Test des controles bloquants
parent
323ae72bf0
commit
94db43c0bf
|
@ -193,20 +193,24 @@ export let treatRuleRoot = (rules, rule) => {
|
|||
}
|
||||
})(rule)
|
||||
|
||||
let evaluateControl = () => {
|
||||
let controls = rule['contrôles']
|
||||
if (!controls) return null
|
||||
//parse Expression
|
||||
//test if cited variable is this
|
||||
//evaluate with situation
|
||||
//return message or null
|
||||
}
|
||||
// let evaluateControl = () => {
|
||||
//evaluate with situation
|
||||
//return message or null
|
||||
//}
|
||||
let controls =
|
||||
rule['contrôles'] &&
|
||||
rule['contrôles'].map(control => {
|
||||
let testExpression = treatString(rules, rule)(control.si)
|
||||
console.log(testExpression)
|
||||
return { ...control, testExpression }
|
||||
})
|
||||
|
||||
return {
|
||||
// Pas de propriété explanation et jsx ici car on est parti du (mauvais) principe que 'non applicable si' et 'formule' sont particuliers, alors qu'ils pourraient être rangé avec les autres mécanismes
|
||||
...parsedRoot,
|
||||
evaluate,
|
||||
parsed: true
|
||||
parsed: true,
|
||||
controls
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
import { expect } from 'chai'
|
||||
import { enrichRule } from '../source/engine/rules'
|
||||
import { parseAll, analyseMany } from '../source/engine/traverse'
|
||||
|
||||
describe('controls', function() {
|
||||
let rawRules = [
|
||||
{
|
||||
nom: 'net',
|
||||
formule: 'brut - cotisation'
|
||||
},
|
||||
{ nom: 'cotisation', formule: 235 },
|
||||
{
|
||||
nom: 'brut',
|
||||
format: 'euro',
|
||||
question: 'Quel est le salaire brut ?',
|
||||
contrôles: [
|
||||
{
|
||||
si: 'brut < 300',
|
||||
niveau: 'bloquant',
|
||||
message:
|
||||
'Malheureux, je crois que vous vous êtes trompé dans votre saisie.'
|
||||
},
|
||||
{
|
||||
si: 'brut < 1000',
|
||||
niveau: 'bloquant',
|
||||
message: 'Toujours pas, nous avons des standards en France !'
|
||||
},
|
||||
|
||||
{
|
||||
si: 'brut < 1500',
|
||||
niveau: 'avertissement',
|
||||
message: 'Toujours pas, nous avons des standards en France !'
|
||||
},
|
||||
{
|
||||
si: 'brut > 100000',
|
||||
niveau: 'information',
|
||||
message: 'Oulah ! Oulah !'
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
rules = rawRules.map(enrichRule),
|
||||
parsedRules = parseAll(rules)
|
||||
|
||||
it('Should parse blocking controls', function() {
|
||||
let controls = parsedRules.find(r => r.controls).controls
|
||||
expect(
|
||||
controls.filter(
|
||||
({ level, isInputControl }) => level == 'bloquant' && isInputControl
|
||||
)
|
||||
).to.have.lengthOf(2)
|
||||
})
|
||||
|
||||
it('Should block the engine evaluation if blocking input controls trigger', function() {
|
||||
let situationGate = dottedName => ({ brut: 400 }[dottedName]),
|
||||
{ blockingInputControls } = analyseMany(parsedRules, ['net'])(
|
||||
situationGate
|
||||
)
|
||||
|
||||
expect(blockingInputControls).to.have.lengthOf(1)
|
||||
})
|
||||
it('Should not block the engine evaluation if no blocking input controls trigger', function() {
|
||||
let situationGate = dottedName => ({ brut: 1200 }[dottedName]),
|
||||
{ blockingInputControls } = analyseMany(parsedRules, ['net'])(
|
||||
situationGate
|
||||
)
|
||||
|
||||
expect(blockingInputControls).to.be.undefined
|
||||
})
|
||||
})
|
Loading…
Reference in New Issue