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-09-26 09:35:29 +00:00
|
|
|
import sasuRules from '../source/règles/sasu.yaml'
|
2018-10-19 14:36:38 +00:00
|
|
|
import co2 from '../source/règles/co2.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-26 15:47:15 +00:00
|
|
|
let value = Syso.evaluate(target, {
|
2018-08-16 08:09:20 +00:00
|
|
|
'contrat salarié': { salaire: { 'brut de base': 2300 } }
|
|
|
|
})
|
2018-10-01 15:47:20 +00:00
|
|
|
expect(value).to.be.within(1800, 1803)
|
2018-08-16 08:09:20 +00:00
|
|
|
})
|
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
|
2018-09-26 15:47:15 +00:00
|
|
|
formule: 200
|
2018-09-24 16:27:43 +00:00
|
|
|
- nom: ya
|
|
|
|
formule: yo + 1
|
2018-09-26 15:47:15 +00:00
|
|
|
- nom: yi
|
|
|
|
formule: yo + 2
|
2018-09-24 16:27:43 +00:00
|
|
|
`
|
|
|
|
|
2018-09-26 15:47:15 +00:00
|
|
|
let values = Syso.evaluate(['ya', 'yi'], {}, { base: rules })
|
2018-09-24 16:27:43 +00:00
|
|
|
|
2018-09-26 15:47:15 +00:00
|
|
|
expect(values[0]).to.equal(201)
|
|
|
|
expect(values[1]).to.equal(202)
|
2018-09-24 16:27:43 +00:00
|
|
|
})
|
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
|
|
|
|
`
|
|
|
|
|
2018-09-26 15:47:15 +00:00
|
|
|
let value = Syso.evaluate(
|
|
|
|
'ya',
|
2018-09-25 17:22:32 +00:00
|
|
|
{
|
|
|
|
'contrat salarié . salaire . brut de base': 2300
|
|
|
|
},
|
|
|
|
{ extra: rules }
|
|
|
|
)
|
|
|
|
|
2018-10-01 15:47:20 +00:00
|
|
|
expect(value).to.be.closeTo(1802, 1)
|
2018-09-25 17:22:32 +00:00
|
|
|
})
|
|
|
|
it('should let the user extend the rules constellation in a serious manner', function() {
|
2018-10-01 19:03:27 +00:00
|
|
|
let CA = 550 * 16
|
2018-09-26 15:47:15 +00:00
|
|
|
let salaireTotal = Syso.evaluate(
|
|
|
|
'salaire total',
|
2018-09-25 17:22:32 +00:00
|
|
|
{
|
2018-10-01 19:03:27 +00:00
|
|
|
'chiffre affaires': CA
|
2018-09-25 17:22:32 +00:00
|
|
|
},
|
2018-09-26 09:35:29 +00:00
|
|
|
{ extra: sasuRules }
|
2018-09-25 17:22:32 +00:00
|
|
|
)
|
|
|
|
|
2018-10-01 19:03:27 +00:00
|
|
|
console.log({ salaireTotal })
|
2018-09-26 15:47:15 +00:00
|
|
|
let salaireNetAprèsImpôt = Syso.evaluate(
|
|
|
|
'contrat salarié . salaire . net après impôt',
|
|
|
|
{
|
|
|
|
'contrat salarié': { rémunération: { total: salaireTotal } }
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2018-10-01 19:03:27 +00:00
|
|
|
console.log({ salaireNetAprèsImpôt })
|
2018-09-26 15:47:15 +00:00
|
|
|
|
2018-10-01 19:03:27 +00:00
|
|
|
let [revenuDisponible, dividendes] = Syso.evaluate(
|
|
|
|
['revenu disponible', 'dividendes . net'],
|
2018-09-26 15:47:15 +00:00
|
|
|
{
|
|
|
|
'net après impôt': salaireNetAprèsImpôt,
|
2018-10-01 19:03:27 +00:00
|
|
|
'chiffre affaires': CA
|
2018-09-26 15:47:15 +00:00
|
|
|
},
|
|
|
|
{ extra: sasuRules }
|
|
|
|
)
|
2018-10-01 19:03:27 +00:00
|
|
|
console.log({ revenuDisponible, dividendes })
|
2018-09-25 17:22:32 +00:00
|
|
|
})
|
2018-10-08 15:10:39 +00:00
|
|
|
|
2018-10-17 13:52:32 +00:00
|
|
|
it('should let the user define a simplified revenue tax system', function() {
|
2018-10-08 15:10:39 +00:00
|
|
|
let règles = `
|
|
|
|
- nom: revenu imposable
|
|
|
|
question: Quel est votre revenu imposable ?
|
|
|
|
format: euros
|
|
|
|
|
|
|
|
- nom: revenu abattu
|
|
|
|
formule:
|
|
|
|
allègement:
|
|
|
|
assiette: revenu imposable
|
|
|
|
abattement: 10%
|
|
|
|
|
|
|
|
|
|
|
|
- nom: impôt sur le revenu
|
|
|
|
formule:
|
|
|
|
barème:
|
|
|
|
assiette: revenu abattu
|
|
|
|
tranches:
|
|
|
|
- en-dessous de: 9807
|
|
|
|
taux: 0%
|
|
|
|
- de: 9807
|
|
|
|
à: 27086
|
|
|
|
taux: 14%
|
|
|
|
- de: 27086
|
|
|
|
à: 72617
|
|
|
|
taux: 30%
|
|
|
|
- de: 72617
|
|
|
|
à: 153783
|
|
|
|
taux: 41%
|
|
|
|
- au-dessus de: 153783
|
|
|
|
taux: 45%
|
|
|
|
|
|
|
|
|
|
|
|
- nom: impôt sur le revenu à payer
|
|
|
|
formule:
|
|
|
|
allègement:
|
|
|
|
assiette: impôt sur le revenu
|
|
|
|
décote:
|
|
|
|
plafond: 1177
|
|
|
|
taux: 75%
|
|
|
|
`
|
|
|
|
|
|
|
|
let target = 'impôt sur le revenu à payer'
|
|
|
|
|
|
|
|
let value = Syso.evaluate(
|
|
|
|
target,
|
|
|
|
{ 'revenu imposable': '48000' },
|
2018-10-17 13:52:32 +00:00
|
|
|
{ base: règles }
|
2018-10-08 15:10:39 +00:00
|
|
|
)
|
2018-10-17 13:52:32 +00:00
|
|
|
expect(value).to.equal(7253.26)
|
2018-10-08 15:10:39 +00:00
|
|
|
})
|
2018-10-19 14:36:38 +00:00
|
|
|
it('should let let user define a rule base on a completely different subject', function() {
|
|
|
|
let target = 'impact'
|
|
|
|
|
|
|
|
let value = Syso.evaluate(
|
|
|
|
target,
|
|
|
|
{
|
|
|
|
'nombre de douches': 30,
|
|
|
|
'chauffage . type': 'gaz',
|
|
|
|
'durée de la douche': 7
|
|
|
|
},
|
|
|
|
{ base: co2 }
|
|
|
|
)
|
|
|
|
expect(value).to.equal(7253.26)
|
|
|
|
})
|
2018-08-16 08:09:20 +00:00
|
|
|
})
|