Simplification de l'usage de la librairie
Plus besoin de passer plusieurs objectif et elle renvoit directement la valeur, pas les objets compliquésco2
parent
c2964feb09
commit
66a5439337
|
@ -19,7 +19,7 @@ let enrichRules = input =>
|
|||
(typeof input === 'string' ? yaml.safeLoad(input) : input).map(enrichRule)
|
||||
|
||||
export default {
|
||||
evaluate: (targetNames, nestedSituation, rulesConfig) => {
|
||||
evaluate: (targetInput, nestedSituation, rulesConfig) => {
|
||||
let rules = rulesConfig
|
||||
? do {
|
||||
let { base, extra } = rulesConfig
|
||||
|
@ -30,8 +30,12 @@ export default {
|
|||
}
|
||||
: rulesFr
|
||||
|
||||
return analyseMany(parseAll(rules), targetNames)(
|
||||
nestedSituationToStateSelector(rules)(nestedSituation)
|
||||
)
|
||||
let evaluation = analyseMany(
|
||||
parseAll(rules),
|
||||
Array.isArray(targetInput) ? targetInput : [targetInput]
|
||||
)(nestedSituationToStateSelector(rules)(nestedSituation))
|
||||
|
||||
let values = evaluation.targets.map(t => t.nodeValue)
|
||||
return Array.isArray(targetInput) ? values : values[0]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,10 +55,11 @@
|
|||
- nom: salaire total
|
||||
formule: chiffre affaires * répartition salaire sur dividendes
|
||||
|
||||
#-> on en deduit le net car le total a une valeur
|
||||
- nom: net après impôt
|
||||
format: euros
|
||||
|
||||
- nom: revenu disponible
|
||||
formule: contrat salarié . salaire . net après impôt + dividendes . net
|
||||
formule: net après impôt + dividendes . net
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -6,26 +6,26 @@ import sasuRules from '../source/règles/sasu.yaml'
|
|||
describe('library', function() {
|
||||
it('should evaluate one target with no input data', function() {
|
||||
let target = 'contrat salarié . salaire . net'
|
||||
let evaluated = Syso.evaluate([target], {
|
||||
let value = Syso.evaluate(target, {
|
||||
'contrat salarié': { salaire: { 'brut de base': 2300 } }
|
||||
})
|
||||
let evaluatedTarget = evaluated.targets.find(propEq('dottedName', target))
|
||||
expect(evaluatedTarget)
|
||||
.to.have.property('nodeValue')
|
||||
.to.be.within(1779, 1780)
|
||||
expect(value).to.be.within(1779, 1780)
|
||||
})
|
||||
|
||||
it('should let the user replace the default rules', function() {
|
||||
let rules = `
|
||||
- nom: yo
|
||||
formule: 90890
|
||||
formule: 200
|
||||
- nom: ya
|
||||
formule: yo + 1
|
||||
- nom: yi
|
||||
formule: yo + 2
|
||||
`
|
||||
|
||||
let evaluated = Syso.evaluate(['ya'], {}, { base: rules })
|
||||
let values = Syso.evaluate(['ya', 'yi'], {}, { base: rules })
|
||||
|
||||
expect(evaluated.targets[0].nodeValue).to.equal(90891)
|
||||
expect(values[0]).to.equal(201)
|
||||
expect(values[1]).to.equal(202)
|
||||
})
|
||||
it('should let the user add rules to the default ones', function() {
|
||||
let rules = `
|
||||
|
@ -35,25 +35,43 @@ describe('library', function() {
|
|||
formule: contrat salarié . salaire . net + yo
|
||||
`
|
||||
|
||||
let evaluated = Syso.evaluate(
|
||||
['ya'],
|
||||
let value = Syso.evaluate(
|
||||
'ya',
|
||||
{
|
||||
'contrat salarié . salaire . brut de base': 2300
|
||||
},
|
||||
{ extra: rules }
|
||||
)
|
||||
|
||||
expect(evaluated.targets[0].nodeValue).to.be.closeTo(1780.41, 1)
|
||||
expect(value).to.be.closeTo(1780.41, 1)
|
||||
})
|
||||
it('should let the user extend the rules constellation in a serious manner', function() {
|
||||
let evaluated = Syso.evaluate(
|
||||
['dividendes . net'],
|
||||
let salaireTotal = Syso.evaluate(
|
||||
'salaire total',
|
||||
{
|
||||
'chiffre affaires': 5000
|
||||
},
|
||||
{ extra: sasuRules }
|
||||
)
|
||||
|
||||
expect(evaluated.targets[0].nodeValue).to.be.closeTo(1500, 1)
|
||||
console.log(salaireTotal)
|
||||
let salaireNetAprèsImpôt = Syso.evaluate(
|
||||
'contrat salarié . salaire . net après impôt',
|
||||
{
|
||||
'contrat salarié': { rémunération: { total: salaireTotal } }
|
||||
}
|
||||
)
|
||||
|
||||
console.log(salaireNetAprèsImpôt)
|
||||
|
||||
let revenuDisponible = Syso.evaluate(
|
||||
'revenu disponible',
|
||||
{
|
||||
'net après impôt': salaireNetAprèsImpôt,
|
||||
'chiffre affaires': 5000
|
||||
},
|
||||
{ extra: sasuRules }
|
||||
)
|
||||
console.log(revenuDisponible)
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue