Charger de nouvelles règles dans la lib pour les évaluer
parent
f679bede03
commit
4deb5a83a7
|
@ -1,8 +1,14 @@
|
|||
// This file exports the functions of the public computing library
|
||||
import { analyseMany, parseAll } from './traverse.js'
|
||||
import { rulesFr, collectDefaults, nestedSituationToPathMap } from './rules'
|
||||
import {
|
||||
rulesFr,
|
||||
collectDefaults,
|
||||
nestedSituationToPathMap,
|
||||
enrichRule
|
||||
} from './rules'
|
||||
import yaml from 'js-yaml'
|
||||
|
||||
let parsedRules = parseAll(rulesFr)
|
||||
let defaultRules = parseAll(rulesFr)
|
||||
|
||||
// The public evaluation function takes a nested object of input values
|
||||
let nestedSituationToStateSelector = nestedSituation => dottedName =>
|
||||
|
@ -12,9 +18,13 @@ let nestedSituationToStateSelector = nestedSituation => dottedName =>
|
|||
}[dottedName])
|
||||
|
||||
export default {
|
||||
eval: (targetNames, nestedSituation) =>
|
||||
analyseMany(parsedRules, targetNames)(
|
||||
evaluate: (targetNames, nestedSituation, rulesYaml) => {
|
||||
let rules = rulesYaml
|
||||
? (rules = parseAll(yaml.safeLoad(rulesYaml).map(enrichRule)))
|
||||
: defaultRules
|
||||
|
||||
return analyseMany(rules, targetNames)(
|
||||
nestedSituationToStateSelector(nestedSituation)
|
||||
),
|
||||
a: () => 7
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
import { expect } from 'chai'
|
||||
import evaluate from '../source/engine/index'
|
||||
import Syso from '../source/engine/index'
|
||||
import { propEq } from 'ramda'
|
||||
import dedent from 'dedent-js'
|
||||
console.log(Syso)
|
||||
|
||||
describe('library', function() {
|
||||
it('should evaluate one target with no input data', function() {
|
||||
let target = 'contrat salarié . salaire . net'
|
||||
let evaluated = evaluate([target], {
|
||||
let evaluated = Syso.evaluate([target], {
|
||||
'contrat salarié': { salaire: { 'brut de base': 2300 } }
|
||||
})
|
||||
let evaluatedTarget = evaluated.targets.find(propEq('dottedName', target))
|
||||
|
@ -13,4 +15,17 @@ describe('library', function() {
|
|||
.to.have.property('nodeValue')
|
||||
.to.be.within(1779, 1780)
|
||||
})
|
||||
|
||||
it('should let the user replace the default rules', function() {
|
||||
let newRules = `
|
||||
- nom: yo
|
||||
formule: 90890
|
||||
- nom: ya
|
||||
formule: yo + 1
|
||||
`
|
||||
|
||||
let evaluated = Syso.evaluate(['ya'], {}, newRules)
|
||||
|
||||
expect(evaluated.targets[0].nodeValue).to.equal(90891)
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue