2018-08-16 08:09:20 +00:00
|
|
|
import { expect } from 'chai'
|
2018-09-24 16:27:43 +00:00
|
|
|
import Syso from '../source/engine/index'
|
2018-08-16 08:09:20 +00:00
|
|
|
import { propEq } from 'ramda'
|
2018-09-24 16:27:43 +00:00
|
|
|
import dedent from 'dedent-js'
|
2018-09-25 17:22:32 +00:00
|
|
|
import sasuYaml from 'yaml-loader!../source/règles/sasu.yaml'
|
2018-08-16 08:09:20 +00:00
|
|
|
|
|
|
|
describe('library', function() {
|
|
|
|
it('should evaluate one target with no input data', function() {
|
|
|
|
let target = 'contrat salarié . salaire . net'
|
2018-09-24 16:27:43 +00:00
|
|
|
let evaluated = Syso.evaluate([target], {
|
2018-08-16 08:09:20 +00:00
|
|
|
'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)
|
|
|
|
})
|
2018-09-24 16:27:43 +00:00
|
|
|
|
|
|
|
it('should let the user replace the default rules', function() {
|
2018-09-25 17:22:32 +00:00
|
|
|
let rules = `
|
2018-09-24 16:27:43 +00:00
|
|
|
- nom: yo
|
|
|
|
formule: 90890
|
|
|
|
- nom: ya
|
|
|
|
formule: yo + 1
|
|
|
|
`
|
|
|
|
|
2018-09-25 17:22:32 +00:00
|
|
|
let evaluated = Syso.evaluate(['ya'], {}, { base: rules })
|
2018-09-24 16:27:43 +00:00
|
|
|
|
|
|
|
expect(evaluated.targets[0].nodeValue).to.equal(90891)
|
|
|
|
})
|
2018-09-25 17:22:32 +00:00
|
|
|
it('should let the user add rules to the default ones', function() {
|
|
|
|
let rules = `
|
|
|
|
- nom: yo
|
|
|
|
formule: 1
|
|
|
|
- nom: ya
|
|
|
|
formule: contrat salarié . salaire . net + yo
|
|
|
|
`
|
|
|
|
|
|
|
|
let evaluated = Syso.evaluate(
|
|
|
|
['ya'],
|
|
|
|
{
|
|
|
|
'contrat salarié . salaire . brut de base': 2300
|
|
|
|
},
|
|
|
|
{ extra: rules }
|
|
|
|
)
|
|
|
|
|
|
|
|
expect(evaluated.targets[0].nodeValue).to.be.closeTo(1780.41, 1)
|
|
|
|
})
|
|
|
|
it('should let the user extend the rules constellation in a serious manner', function() {
|
|
|
|
let evaluated = Syso.evaluate(
|
|
|
|
['ya'],
|
|
|
|
{
|
|
|
|
'contrat salarié . salaire . brut de base': 2300
|
|
|
|
},
|
|
|
|
{ extra: sasuYaml }
|
|
|
|
)
|
|
|
|
|
|
|
|
expect(evaluated.targets[0].nodeValue).to.be.closeTo(1780.41, 1)
|
|
|
|
})
|
2018-08-16 08:09:20 +00:00
|
|
|
})
|