2018-01-03 15:54:19 +00:00
|
|
|
import R from 'ramda'
|
|
|
|
import { expect } from 'chai'
|
2017-11-20 16:25:08 +00:00
|
|
|
import {
|
2018-01-03 15:54:19 +00:00
|
|
|
rules,
|
|
|
|
enrichRule,
|
|
|
|
findVariantsAndRecords
|
|
|
|
} from '../source/engine/rules'
|
2017-06-28 14:12:10 +00:00
|
|
|
|
|
|
|
let stateSelector = (state, name) => null
|
2017-06-27 13:14:30 +00:00
|
|
|
|
2018-01-03 15:54:19 +00:00
|
|
|
describe('enrichRule', function() {
|
|
|
|
it('should extract the type of the rule', function() {
|
|
|
|
let rule = { nom: 'retraite', cotisation: {} }
|
|
|
|
expect(enrichRule(rule)).to.have.property('type', 'cotisation')
|
|
|
|
})
|
2017-06-27 13:14:30 +00:00
|
|
|
|
2018-01-03 15:54:19 +00:00
|
|
|
it('should load external data into the rule', function() {
|
|
|
|
let data = { taux_versement_transport: { one: 'two' } }
|
|
|
|
let rule = {
|
|
|
|
nom: 'retraite',
|
|
|
|
cotisation: {},
|
|
|
|
données: 'taux_versement_transport'
|
|
|
|
}
|
|
|
|
expect(enrichRule(rule, data)).to.have.deep.property('data', { one: 'two' })
|
|
|
|
})
|
2017-06-27 13:14:30 +00:00
|
|
|
|
2018-01-03 15:54:19 +00:00
|
|
|
it('should extract the dotted name of the rule', function() {
|
|
|
|
let rule = { espace: 'contrat salarié', nom: 'CDD' }
|
|
|
|
expect(enrichRule(rule)).to.have.property('name', 'CDD')
|
|
|
|
expect(enrichRule(rule)).to.have.property(
|
|
|
|
'dottedName',
|
|
|
|
'contrat salarié . CDD'
|
|
|
|
)
|
|
|
|
})
|
2017-09-18 07:29:26 +00:00
|
|
|
|
2018-01-03 15:54:19 +00:00
|
|
|
it('should render Markdown in sub-questions', function() {
|
|
|
|
let rule = { nom: 'quoi', 'sous-question': '**wut**' }
|
|
|
|
expect(enrichRule(rule)).to.have.property(
|
|
|
|
'subquestion',
|
|
|
|
'<p><strong>wut</strong></p>\n'
|
|
|
|
)
|
|
|
|
})
|
2017-11-20 16:25:08 +00:00
|
|
|
})
|
2017-06-27 13:14:30 +00:00
|
|
|
|
2018-01-03 15:54:19 +00:00
|
|
|
describe('rule checks', function() {
|
|
|
|
it('most input rules should have defaults', function() {
|
|
|
|
let rulesNeedingDefault = rules.filter(
|
|
|
|
r =>
|
|
|
|
r.espace &&
|
|
|
|
!r.simulateur &&
|
|
|
|
(!r.formule || r.formule['une possibilité']) &&
|
|
|
|
r.defaultValue == null
|
|
|
|
)
|
2017-09-18 07:29:26 +00:00
|
|
|
|
2018-02-22 18:17:59 +00:00
|
|
|
rulesNeedingDefault.map(r =>
|
|
|
|
console.log(
|
|
|
|
'cette règle, ',
|
|
|
|
r.dottedName,
|
|
|
|
'devrait avoir une valeur par défaut'
|
|
|
|
)
|
|
|
|
)
|
2018-01-03 15:54:19 +00:00
|
|
|
expect(rulesNeedingDefault).to.be.empty
|
|
|
|
})
|
2017-11-20 16:25:08 +00:00
|
|
|
})
|