From 7955ec158079061fcb29a6f7852bf4dc0b83818d Mon Sep 17 00:00:00 2001 From: mama Date: Mon, 20 Nov 2017 17:25:08 +0100 Subject: [PATCH] =?UTF-8?q?:white=5Fcheck=5Fmark:=20Test=20:=20pas=20de=20?= =?UTF-8?q?variables=20d'entr=C3=A9e=20sans=20d=C3=A9faut?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/engine/rules.js | 5 +-- test/rules.test.js | 70 ++++++++++++++++++++++++++++-------------- 2 files changed, 50 insertions(+), 25 deletions(-) diff --git a/source/engine/rules.js b/source/engine/rules.js index 8b20cf718..b714e42e8 100644 --- a/source/engine/rules.js +++ b/source/engine/rules.js @@ -26,9 +26,10 @@ export let enrichRule = (rule, sharedData = {}) => { name ].join(' . ') : name, subquestionMarkdown = rule['sous-question'], - subquestion = subquestionMarkdown && marked(subquestionMarkdown) + subquestion = subquestionMarkdown && marked(subquestionMarkdown), + defaultValue = rule['par défaut'] - return {...rule, type, name, title, ns, data, dottedName, subquestion} + return {...rule, type, name, title, ns, data, dottedName, subquestion, defaultValue} } export let hasKnownRuleType = rule => rule && enrichRule(rule).type diff --git a/test/rules.test.js b/test/rules.test.js index 6ae6fd334..ca977c157 100644 --- a/test/rules.test.js +++ b/test/rules.test.js @@ -1,31 +1,55 @@ -import R from 'ramda' -import {expect} from 'chai' -import {rules, enrichRule, findVariantsAndRecords} from '../source/engine/rules' +import R from "ramda" +import { expect } from "chai" +import { + rules, + enrichRule, + findVariantsAndRecords +} from "../source/engine/rules" let stateSelector = (state, name) => null -describe('enrichRule', function() { +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") + }) - it('should extract the type of the rule', function() { - let rule = {nom: 'retraite', cotisation:{}} - 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 = { + nom: "retraite", + cotisation: {}, + données: "taux_versement_transport" + } + expect(enrichRule(rule, data)).to.have.deep.property("data", { one: "two" }) + }) - 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"}) - }); + 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" + ) + }) - 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') - }); + it("should render Markdown in sub-questions", function() { + let rule = { nom: "quoi", "sous-question": "**wut**" } + expect(enrichRule(rule)).to.have.property( + "subquestion", + "

wut

\n" + ) + }) +}) - it('should render Markdown in sub-questions', function() { - let rule = {nom: 'quoi', "sous-question":"**wut**"} - expect(enrichRule(rule)).to.have.property('subquestion','

wut

\n') - }); +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 + ) -}); + rulesNeedingDefault.map(r => console.log('yo', r.dottedName)) + expect(rulesNeedingDefault).to.be.empty + }) +})