⚙️ Charge des données arbitraires dans les règles
parent
7c586fd0e8
commit
814c3a1f01
File diff suppressed because it is too large
Load Diff
|
@ -16,9 +16,10 @@
|
|||
|
||||
- espace: etablissement
|
||||
nom: taux versement transport
|
||||
données: 'taux_versement_transport'
|
||||
formule:
|
||||
sélection:
|
||||
- données: 'taux_versement_transport'
|
||||
données: taux versement transport
|
||||
clé: code INSEE
|
||||
composantes:
|
||||
- nom: aot
|
||||
|
|
|
@ -5,16 +5,20 @@ import R from 'ramda'
|
|||
import possibleVariableTypes from './possibleVariableTypes.yaml'
|
||||
import marked from './marked'
|
||||
|
||||
// TODO - should be in UI, not engine
|
||||
import taux_versement_transport from '../../règles/rémunération-travail/cotisations/ok/taux.json'
|
||||
|
||||
// console.log('rawRules', rawRules.map(({espace, nom}) => espace + nom))
|
||||
/***********************************
|
||||
Méthodes agissant sur une règle */
|
||||
|
||||
// Enrichissement de la règle avec des informations évidentes pour un lecteur humain
|
||||
export let enrichRule = rule => {
|
||||
export let enrichRule = (rule, sharedData = {}) => {
|
||||
let
|
||||
type = possibleVariableTypes.find(t => R.has(t, rule)),
|
||||
name = rule['nom'],
|
||||
ns = rule['espace'],
|
||||
data = rule['données'] ? sharedData[rule['données']] : null,
|
||||
dottedName = ns ? [
|
||||
ns,
|
||||
name
|
||||
|
@ -22,7 +26,7 @@ export let enrichRule = rule => {
|
|||
subquestionMarkdown = rule['sous-question'],
|
||||
subquestion = subquestionMarkdown && marked(subquestionMarkdown)
|
||||
|
||||
return {...rule, type, name, ns, dottedName, subquestion}
|
||||
return {...rule, type, name, ns, data, dottedName, subquestion}
|
||||
}
|
||||
|
||||
export let hasKnownRuleType = rule => rule && enrichRule(rule).type
|
||||
|
@ -64,7 +68,7 @@ export let disambiguateRuleReference = (allRules, {ns, name}, partialName) => {
|
|||
}
|
||||
|
||||
// On enrichit la base de règles avec des propriétés dérivées de celles du YAML
|
||||
export let rules = rawRules.map(enrichRule)
|
||||
export let rules = rawRules.map(enrichRule, {taux_versement_transport})
|
||||
|
||||
|
||||
/****************************************
|
||||
|
|
|
@ -12,6 +12,12 @@ describe('enrichRule', function() {
|
|||
expect(enrichRule(rule)).to.have.property('type','cotisation')
|
||||
});
|
||||
|
||||
it('should load external data into the rule', function() {
|
||||
let data = {taux_versement_transport: {one: "two"}}
|
||||
let rule = {cotisation:{}, données: 'taux_versement_transport'}
|
||||
expect(enrichRule(rule, data)).to.have.deep.property('data',{one: "two"})
|
||||
});
|
||||
|
||||
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')
|
||||
|
@ -22,4 +28,5 @@ describe('enrichRule', function() {
|
|||
let rule = {"sous-question":"**wut**"}
|
||||
expect(enrichRule(rule)).to.have.property('subquestion','<p><strong>wut</strong></p>\n')
|
||||
});
|
||||
|
||||
});
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue