diff --git a/source/engine/traverse.js b/source/engine/traverse.js index 047b45b58..ec595e73a 100644 --- a/source/engine/traverse.js +++ b/source/engine/traverse.js @@ -337,10 +337,11 @@ let mecanismSelection = (recurse,k,v) => { let explanation = recurse(v['cherche']) let evaluate = (situationGate, parsedRules, node) => { - let collectMissing = node => node.explanation.nodeValue ? [] : collectNodeMissing(node.explanation), + let collectMissing = node => collectNodeMissing(node.explanation), + explanation = evaluateNode(situationGate, parsedRules, node.explanation), dataSource = findRuleByName(parsedRules, dataSourceName), - dataKey = evaluateNode(situationGate, parsedRules, explanation).nodeValue, data = dataSource ? dataSource['data'] : null, + dataKey = explanation.nodeValue, dataItems = (data && dataKey && dataSearchField) ? R.filter(item => item[dataSearchField] == dataKey, data) : null, dataItemValues = dataItems ? R.values(dataItems) : null, // TODO - over-specific! transform the JSON instead @@ -363,6 +364,7 @@ let mecanismSelection = (recurse,k,v) => { return { evaluate, + explanation, jsx } } diff --git a/test/generateQuestions.test.js b/test/generateQuestions.test.js index 851cb586e..a3e1b0a98 100644 --- a/test/generateQuestions.test.js +++ b/test/generateQuestions.test.js @@ -265,16 +265,16 @@ describe('buildNextSteps', function() { }); it('should generate questions from the real rules, experimental version', function() { - let stateSelector = (name) => ({"contrat salarié . type de contrat":"CDI"})[name] + let stateSelector = (name) => ({"contrat salarié . type de contrat":"CDI","entreprise . effectif":"50"})[name] let rules = realRules.map(enrichRule), situation = analyseTopDown(rules,"Salaire")(stateSelector), objectives = getObjectives(stateSelector, situation.root, situation.parsedRules), + missing = collectMissingVariables()(stateSelector,situation), result = buildNextSteps(stateSelector, rules, situation) expect(R.path(["question","props","label"])(result[0])).to.equal("Quel est le salaire brut ?") expect(R.path(["question","props","label"])(result[1])).to.equal("Le salarié a-t-il le statut cadre ?") - expect(R.path(["question","props","label"])(result[2])).to.equal("Quel est l'effectif de l'entreprise ?") }); });