2019-02-11 13:44:24 +00:00
|
|
|
import { expect } from 'chai'
|
2019-09-25 15:42:06 +00:00
|
|
|
import Lib from '../source/engine/index'
|
2020-02-04 16:05:59 +00:00
|
|
|
import co2 from './rules/co2.yaml'
|
|
|
|
import sasuRules from './rules/sasu.yaml'
|
2018-08-16 08:09:20 +00:00
|
|
|
|
|
|
|
describe('library', function() {
|
|
|
|
it('should evaluate one target with no input data', function() {
|
2019-08-27 14:16:51 +00:00
|
|
|
let target = 'contrat salarié . rémunération . net'
|
2019-09-25 15:42:06 +00:00
|
|
|
let value = Lib.evaluate(target, {
|
2019-10-02 15:43:15 +00:00
|
|
|
'contrat salarié . rémunération . brut de base': 2300
|
2018-08-16 08:09:20 +00:00
|
|
|
})
|
2018-12-30 10:09:07 +00:00
|
|
|
expect(value).to.be.within(1798, 1800)
|
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
|
|
|
`
|
|
|
|
|
2019-09-25 15:42:06 +00:00
|
|
|
let values = Lib.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 = `
|
2020-02-04 17:35:21 +00:00
|
|
|
yo:
|
2018-09-25 17:22:32 +00:00
|
|
|
formule: 1
|
2020-02-04 17:35:21 +00:00
|
|
|
ya:
|
2019-08-27 14:16:51 +00:00
|
|
|
formule: contrat salarié . rémunération . net + yo
|
2018-09-25 17:22:32 +00:00
|
|
|
`
|
|
|
|
|
2019-09-25 15:42:06 +00:00
|
|
|
let value = Lib.evaluate(
|
2018-09-26 15:47:15 +00:00
|
|
|
'ya',
|
2018-09-25 17:22:32 +00:00
|
|
|
{
|
2019-08-27 14:16:51 +00:00
|
|
|
'contrat salarié . rémunération . brut de base': 2300
|
2018-09-25 17:22:32 +00:00
|
|
|
},
|
|
|
|
{ extra: rules }
|
|
|
|
)
|
|
|
|
|
2018-12-30 10:09:07 +00:00
|
|
|
expect(value).to.be.closeTo(1799, 1)
|
2018-09-25 17:22:32 +00:00
|
|
|
})
|
2019-02-11 13:44:24 +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
|
2019-09-25 15:42:06 +00:00
|
|
|
let salaireTotal = Lib.evaluate(
|
2018-09-26 15:47:15 +00:00
|
|
|
'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
|
|
|
)
|
|
|
|
|
2019-09-25 15:42:06 +00:00
|
|
|
let salaireNetAprèsImpôt = Lib.evaluate(
|
2019-08-27 14:16:51 +00:00
|
|
|
'contrat salarié . rémunération . net après impôt',
|
2018-09-26 15:47:15 +00:00
|
|
|
{
|
2019-10-02 11:47:57 +00:00
|
|
|
'contrat salarié . prix du travail': salaireTotal
|
2018-09-26 15:47:15 +00:00
|
|
|
}
|
|
|
|
)
|
2019-09-25 15:42:06 +00:00
|
|
|
let [revenuDisponible, dividendes] = Lib.evaluate(
|
2020-02-04 17:35:21 +00:00
|
|
|
['contrat salarié . rémunération . net après impôt', 'dividendes . net'],
|
2018-09-26 15:47:15 +00:00
|
|
|
{
|
2019-08-27 14:16:51 +00:00
|
|
|
'contrat salarié . rémunération . 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-12-30 10:09:07 +00:00
|
|
|
|
2020-01-15 15:18:03 +00:00
|
|
|
expect(revenuDisponible).to.be.closeTo(2324, 1)
|
2018-12-30 10:09:07 +00:00
|
|
|
expect(dividendes).to.be.closeTo(2507, 1)
|
2019-09-06 08:53:40 +00:00
|
|
|
}).timeout(5000)
|
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 ?
|
2019-07-05 13:00:24 +00:00
|
|
|
unité: €
|
2018-10-08 15:10:39 +00:00
|
|
|
|
|
|
|
- nom: revenu abattu
|
|
|
|
formule:
|
|
|
|
allègement:
|
|
|
|
assiette: revenu imposable
|
|
|
|
abattement: 10%
|
|
|
|
|
|
|
|
|
|
|
|
- nom: impôt sur le revenu
|
|
|
|
formule:
|
|
|
|
barème:
|
|
|
|
assiette: revenu abattu
|
|
|
|
tranches:
|
2020-02-19 16:47:21 +00:00
|
|
|
- taux: 0%
|
|
|
|
plafond: 9807
|
|
|
|
- taux: 14%
|
|
|
|
plafond: 27086
|
|
|
|
- taux: 30%
|
|
|
|
plafond: 72617
|
|
|
|
- taux: 41%
|
|
|
|
plafond: 153783
|
|
|
|
- taux: 45%
|
2018-10-08 15:10:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
- nom: impôt sur le revenu à payer
|
|
|
|
formule:
|
|
|
|
allègement:
|
|
|
|
assiette: impôt sur le revenu
|
|
|
|
décote:
|
|
|
|
taux: 75%
|
2020-02-19 16:47:21 +00:00
|
|
|
plafond: 1177
|
2018-10-08 15:10:39 +00:00
|
|
|
`
|
|
|
|
|
|
|
|
let target = 'impôt sur le revenu à payer'
|
|
|
|
|
2019-09-25 15:42:06 +00:00
|
|
|
let value = Lib.evaluate(
|
2018-10-08 15:10:39 +00:00
|
|
|
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() {
|
2018-11-07 16:55:42 +00:00
|
|
|
let targets = 'impact'
|
2018-10-19 14:36:38 +00:00
|
|
|
|
2019-09-25 15:42:06 +00:00
|
|
|
let value = Lib.evaluate(
|
2018-10-23 10:58:27 +00:00
|
|
|
targets,
|
2018-10-19 14:36:38 +00:00
|
|
|
{
|
|
|
|
'nombre de douches': 30,
|
|
|
|
'chauffage . type': 'gaz',
|
2018-10-23 10:58:27 +00:00
|
|
|
'durée de la douche': 10
|
2018-10-19 14:36:38 +00:00
|
|
|
},
|
2018-11-07 16:55:42 +00:00
|
|
|
{ base: co2, debug: false }
|
2018-10-19 14:36:38 +00:00
|
|
|
)
|
2018-11-07 16:55:42 +00:00
|
|
|
//console.log(JSON.stringify(value.targets[0], null, 4))
|
2019-02-01 12:31:57 +00:00
|
|
|
expect(value).to.be.within(20, 21)
|
2018-10-19 14:36:38 +00:00
|
|
|
})
|
2018-08-16 08:09:20 +00:00
|
|
|
})
|