diff --git a/package.json b/package.json index 7e9f35a7b..e4fdd267f 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "mon-entreprise", "license": "MIT", - "version": "1.2.1", + "version": "1.2.2", "description": "Library to compute the french social security contributions. Also a website that explains the calculations, and a generic engine to build cool forms that asks the question needed to compute an objective.", "main": "./dist/engine.js", "files": [ diff --git a/source/engine/index.js b/source/engine/index.js index 08c62c576..718f059b3 100644 --- a/source/engine/index.js +++ b/source/engine/index.js @@ -1,25 +1,20 @@ // This file exports the functions of the public computing library import { safeLoad } from 'js-yaml' -import { - collectDefaults, - enrichRule, - nestedSituationToPathMap, - rulesFr -} from './rules' +import { collectDefaults, enrichRule, rulesFr } from './rules' import { analyseMany, parseAll } from './traverse.js' // The public evaluation function takes a nested object of input values -let nestedSituationToStateSelector = rules => nestedSituation => dottedName => +let inputToStateSelector = rules => input => dottedName => ({ ...collectDefaults(rules), - ...nestedSituationToPathMap(nestedSituation) + ...input }[dottedName]) let enrichRules = input => (typeof input === 'string' ? safeLoad(input) : input).map(enrichRule) export default { - evaluate: (targetInput, nestedSituation, config) => { + evaluate: (targetInput, input, config) => { let rules = config ? [ ...(config.base ? enrichRules(config.base) : rulesFr), @@ -30,7 +25,7 @@ export default { let evaluation = analyseMany( parseAll(rules), Array.isArray(targetInput) ? targetInput : [targetInput] - )(nestedSituationToStateSelector(rules)(nestedSituation)) + )(inputToStateSelector(rules)(input)) if (config?.debug) return evaluation let values = evaluation.targets.map(t => t.nodeValue) diff --git a/test/library.test.js b/test/library.test.js index f931e4c8e..6d8b6cf09 100644 --- a/test/library.test.js +++ b/test/library.test.js @@ -7,7 +7,7 @@ describe('library', function() { it('should evaluate one target with no input data', function() { let target = 'contrat salarié . rémunération . net' let value = Lib.evaluate(target, { - 'contrat salarié': { rémunération: { 'brut de base': 2300 } } + 'contrat salarié . rémunération . brut de base': 2300 }) expect(value).to.be.within(1798, 1800) })