2017-07-01 09:17:54 +00:00
|
|
|
import R from 'ramda'
|
|
|
|
import {expect} from 'chai'
|
2017-07-11 14:39:05 +00:00
|
|
|
import {rules as realRules, enrichRule} from '../source/engine/rules'
|
2017-11-28 11:45:06 +00:00
|
|
|
import {analyse, parseAll} from '../source/engine/traverse'
|
|
|
|
import {getNextSteps, collectMissingVariables} from '../source/engine/generateQuestions'
|
2017-07-01 09:17:54 +00:00
|
|
|
|
2017-07-07 08:35:40 +00:00
|
|
|
|
2017-11-07 18:46:40 +00:00
|
|
|
let stateSelector = (name) => null
|
2017-07-07 08:35:40 +00:00
|
|
|
|
2017-07-09 22:14:22 +00:00
|
|
|
|
|
|
|
describe('collectMissingVariables', function() {
|
|
|
|
|
2017-07-07 08:35:40 +00:00
|
|
|
it('should identify missing variables', function() {
|
|
|
|
let rawRules = [
|
2017-08-16 13:47:12 +00:00
|
|
|
{nom: "startHere", formule: 2, "non applicable si" : "sum . evt . ko", espace: "sum"},
|
2017-07-07 08:35:40 +00:00
|
|
|
{nom: "evt", espace: "sum", formule: {"une possibilité":["ko"]}, titre: "Truc", question:"?"},
|
|
|
|
{nom: "ko", espace: "sum . evt"}],
|
2017-11-28 11:45:06 +00:00
|
|
|
rules = parseAll(rawRules.map(enrichRule)),
|
2017-11-07 18:46:40 +00:00
|
|
|
analysis = analyse(rules,"startHere")(stateSelector),
|
|
|
|
result = collectMissingVariables(analysis.targets)
|
2017-07-07 08:35:40 +00:00
|
|
|
expect(result).to.have.property('sum . evt . ko')
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should identify missing variables mentioned in expressions', function() {
|
|
|
|
let rawRules = [
|
2017-08-16 13:47:12 +00:00
|
|
|
{nom: "startHere", formule: 2, "non applicable si" : "evt . nyet > evt . nope", espace: "sum"},
|
2017-07-07 08:35:40 +00:00
|
|
|
{nom: "nope", espace: "sum . evt"},
|
|
|
|
{nom: "nyet", espace: "sum . evt"}],
|
2017-11-28 11:45:06 +00:00
|
|
|
rules = parseAll(rawRules.map(enrichRule)),
|
2017-11-07 18:46:40 +00:00
|
|
|
analysis = analyse(rules,"startHere")(stateSelector),
|
|
|
|
result = collectMissingVariables(analysis.targets)
|
2017-07-07 08:35:40 +00:00
|
|
|
|
|
|
|
expect(result).to.have.property('sum . evt . nyet')
|
|
|
|
expect(result).to.have.property('sum . evt . nope')
|
|
|
|
});
|
|
|
|
|
2017-07-28 08:22:22 +00:00
|
|
|
it('should ignore missing variables in the formula if not applicable', function() {
|
|
|
|
let rawRules = [
|
2017-08-16 13:47:12 +00:00
|
|
|
{nom: "startHere", formule: "trois", "non applicable si" : "3 > 2", espace: "sum"},
|
2017-07-28 08:22:22 +00:00
|
|
|
{nom: "trois", espace: "sum"}],
|
2017-11-28 11:45:06 +00:00
|
|
|
rules = parseAll(rawRules.map(enrichRule)),
|
2017-11-07 18:46:40 +00:00
|
|
|
analysis = analyse(rules,"startHere")(stateSelector),
|
|
|
|
result = collectMissingVariables(analysis.targets)
|
2017-07-28 08:55:19 +00:00
|
|
|
|
2017-07-28 10:14:18 +00:00
|
|
|
expect(result).to.deep.equal({})
|
2017-07-28 08:55:19 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should not report missing variables when "one of these" short-circuits', function() {
|
|
|
|
let rawRules = [
|
2017-08-16 13:47:12 +00:00
|
|
|
{nom: "startHere", formule: "trois", "non applicable si" : {"une de ces conditions": ["3 > 2", "trois"]}, espace: "sum"},
|
2017-07-28 08:55:19 +00:00
|
|
|
{nom: "trois", espace: "sum"}],
|
2017-11-28 11:45:06 +00:00
|
|
|
rules = parseAll(rawRules.map(enrichRule)),
|
2017-11-07 18:46:40 +00:00
|
|
|
analysis = analyse(rules,"startHere")(stateSelector),
|
|
|
|
result = collectMissingVariables(analysis.targets)
|
2017-07-28 09:42:57 +00:00
|
|
|
|
2017-07-28 10:14:18 +00:00
|
|
|
expect(result).to.deep.equal({})
|
2017-07-28 09:42:57 +00:00
|
|
|
});
|
|
|
|
|
2017-09-08 10:06:23 +00:00
|
|
|
it('should report "une possibilité" as a missing variable even though it has a formula', function() {
|
|
|
|
let rawRules = [
|
|
|
|
{nom: "startHere", formule: "trois", espace: "top"},
|
|
|
|
{nom: "trois", formule: {"une possibilité":["ko"]}, espace: "top"}],
|
2017-11-28 11:45:06 +00:00
|
|
|
rules = parseAll(rawRules.map(enrichRule)),
|
2017-11-07 18:46:40 +00:00
|
|
|
analysis = analyse(rules,"startHere")(stateSelector),
|
|
|
|
result = collectMissingVariables(analysis.targets)
|
2017-09-08 10:06:23 +00:00
|
|
|
|
|
|
|
expect(result).to.have.property('top . trois')
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not report missing variables when "une possibilité" is inapplicable', function() {
|
|
|
|
let rawRules = [
|
|
|
|
{nom: "startHere", formule: "trois", espace: "top"},
|
|
|
|
{nom: "trois", formule: {"une possibilité":["ko"]}, "non applicable si": 1, espace: "top"}],
|
2017-11-28 11:45:06 +00:00
|
|
|
rules = parseAll(rawRules.map(enrichRule)),
|
2017-11-07 18:46:40 +00:00
|
|
|
analysis = analyse(rules,"startHere")(stateSelector),
|
|
|
|
result = collectMissingVariables(analysis.targets)
|
2017-09-08 10:06:23 +00:00
|
|
|
|
|
|
|
expect(result).to.deep.equal({})
|
|
|
|
});
|
|
|
|
|
2017-09-08 10:28:35 +00:00
|
|
|
it('should not report missing variables when "une possibilité" was answered', function() {
|
|
|
|
let mySelector = (name) => ({"top . trois":"ko"})[name]
|
|
|
|
|
|
|
|
let rawRules = [
|
|
|
|
{nom: "startHere", formule: "trois", espace: "top"},
|
|
|
|
{nom: "trois", formule: {"une possibilité":["ko"]}, espace: "top"}],
|
2017-11-28 11:45:06 +00:00
|
|
|
rules = parseAll(rawRules.map(enrichRule)),
|
2017-11-07 18:46:40 +00:00
|
|
|
analysis = analyse(rules,"startHere")(mySelector),
|
|
|
|
result = collectMissingVariables(analysis.targets)
|
2017-09-08 10:28:35 +00:00
|
|
|
|
|
|
|
expect(result).to.deep.equal({})
|
|
|
|
});
|
|
|
|
|
2017-07-28 09:42:57 +00:00
|
|
|
it('should report missing variables in switch statements', function() {
|
|
|
|
let rawRules = [
|
2017-08-16 13:47:12 +00:00
|
|
|
{ nom: "startHere", formule: {"aiguillage numérique": {
|
2017-07-28 09:42:57 +00:00
|
|
|
"11 > dix":"1000%",
|
|
|
|
"3 > dix":"1100%",
|
|
|
|
"1 > dix":"1200%"
|
|
|
|
}}, espace: "top"},
|
|
|
|
{nom: "dix", espace: "top"}],
|
2017-11-28 11:45:06 +00:00
|
|
|
rules = parseAll(rawRules.map(enrichRule)),
|
2017-11-07 18:46:40 +00:00
|
|
|
analysis = analyse(rules,"startHere")(stateSelector),
|
|
|
|
result = collectMissingVariables(analysis.targets)
|
2017-07-28 09:42:57 +00:00
|
|
|
|
|
|
|
expect(result).to.have.property('top . dix')
|
|
|
|
});
|
|
|
|
|
2017-07-28 13:33:35 +00:00
|
|
|
it('should report missing variables in variations', function() {
|
|
|
|
let rawRules = [
|
|
|
|
{nom: "startHere", formule: {somme: ["variations"]}, espace: "top"},
|
|
|
|
{nom: "variations", espace: "top", formule: {"barème": {
|
|
|
|
assiette:2008,
|
|
|
|
"multiplicateur des tranches":1000,
|
|
|
|
"variations":[
|
|
|
|
{si: "dix", "tranches":[{"en-dessous de":1, taux: 0.1},{de:1, "à": 2, taux: "deux"}, ,{"au-dessus de":2, taux: 10}]},
|
|
|
|
{si: "3 > 4", "tranches":[{"en-dessous de":1, taux: 0.1},{de:1, "à": 2, taux: 1.8}, ,{"au-dessus de":2, taux: 10}]},
|
|
|
|
]
|
|
|
|
}}},
|
|
|
|
{nom: "dix", espace: "top"},
|
|
|
|
{nom: "deux", espace: "top"}],
|
2017-11-28 11:45:06 +00:00
|
|
|
rules = parseAll(rawRules.map(enrichRule)),
|
2017-11-07 18:46:40 +00:00
|
|
|
analysis = analyse(rules,"startHere")(stateSelector),
|
|
|
|
result = collectMissingVariables(analysis.targets)
|
2017-07-28 13:33:35 +00:00
|
|
|
|
|
|
|
expect(result).to.have.property('top . dix')
|
|
|
|
// expect(result).to.have.property('top . deux') - this is a TODO
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not report missing variables in irrelevant variations', function() {
|
|
|
|
let rawRules = [
|
|
|
|
{nom: "startHere", formule: {somme: ["variations"]}, espace: "top"},
|
|
|
|
{nom: "variations", espace: "top", formule: {"barème": {
|
|
|
|
assiette:2008,
|
|
|
|
"multiplicateur des tranches":1000,
|
|
|
|
"variations":[
|
|
|
|
{si: "dix", "tranches":[{"en-dessous de":1, taux: 0.1},{de:1, "à": 2, taux: "deux"}, ,{"au-dessus de":2, taux: 10}]},
|
|
|
|
{si: "3 > 2", "tranches":[{"en-dessous de":1, taux: 0.1},{de:1, "à": 2, taux: 1.8}, ,{"au-dessus de":2, taux: 10}]},
|
|
|
|
]
|
|
|
|
}}},
|
2017-09-20 15:25:46 +00:00
|
|
|
{nom: "dix", espace: "top"},
|
|
|
|
{nom: "deux", espace: "top"}],
|
2017-11-28 11:45:06 +00:00
|
|
|
rules = parseAll(rawRules.map(enrichRule)),
|
2017-11-07 18:46:40 +00:00
|
|
|
analysis = analyse(rules,"startHere")(stateSelector),
|
|
|
|
result = collectMissingVariables(analysis.targets)
|
2017-07-28 13:33:35 +00:00
|
|
|
|
|
|
|
expect(result).to.deep.equal({})
|
|
|
|
});
|
|
|
|
|
2017-07-28 09:42:57 +00:00
|
|
|
it('should not report missing variables in switch for consequences of false conditions', function() {
|
|
|
|
let rawRules = [
|
2017-08-16 13:47:12 +00:00
|
|
|
{ nom: "startHere", formule: {"aiguillage numérique": {
|
2017-08-02 13:22:08 +00:00
|
|
|
"8 > 10":"1000%",
|
2017-07-28 09:42:57 +00:00
|
|
|
"1 > 2":"dix"
|
|
|
|
}}, espace: "top"},
|
|
|
|
{nom: "dix", espace: "top"}],
|
2017-11-28 11:45:06 +00:00
|
|
|
rules = parseAll(rawRules.map(enrichRule)),
|
2017-11-07 18:46:40 +00:00
|
|
|
analysis = analyse(rules,"startHere")(stateSelector),
|
|
|
|
result = collectMissingVariables(analysis.targets)
|
2017-07-28 09:42:57 +00:00
|
|
|
|
2017-07-28 10:14:18 +00:00
|
|
|
expect(result).to.deep.equal({})
|
2017-07-28 09:42:57 +00:00
|
|
|
});
|
|
|
|
|
2017-08-16 09:21:42 +00:00
|
|
|
it('should report missing variables in consequence when its condition is unresolved', function() {
|
2017-08-02 12:41:00 +00:00
|
|
|
let rawRules = [
|
2017-08-16 13:47:12 +00:00
|
|
|
{ nom: "startHere",
|
2017-08-02 12:41:00 +00:00
|
|
|
formule: {
|
2017-08-02 13:28:33 +00:00
|
|
|
"aiguillage numérique": {
|
2017-08-02 12:41:00 +00:00
|
|
|
"10 > 11": "1000%",
|
|
|
|
"3 > dix": {
|
|
|
|
"douze": "560%",
|
|
|
|
"1 > 2": "75015%" }
|
|
|
|
}
|
|
|
|
},
|
|
|
|
espace: "top"
|
|
|
|
},
|
|
|
|
{ nom: "douze", espace: "top" },
|
|
|
|
{ nom: "dix", espace: "top" }
|
|
|
|
],
|
2017-11-28 11:45:06 +00:00
|
|
|
rules = parseAll(rawRules.map(enrichRule)),
|
2017-11-07 18:46:40 +00:00
|
|
|
analysis = analyse(rules, "startHere")(stateSelector),
|
|
|
|
result = collectMissingVariables(analysis.targets)
|
2017-08-02 12:41:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
expect(result).to.have.property('top . dix')
|
|
|
|
expect(result).to.have.property('top . douze')
|
|
|
|
});
|
|
|
|
|
2017-07-28 09:42:57 +00:00
|
|
|
it('should not report missing variables when a switch short-circuits', function() {
|
|
|
|
let rawRules = [
|
2017-08-16 13:47:12 +00:00
|
|
|
{ nom: "startHere", formule: {"aiguillage numérique": {
|
2017-07-28 09:42:57 +00:00
|
|
|
"11 > 10":"1000%",
|
|
|
|
"3 > dix":"1100%",
|
|
|
|
"1 > dix":"1200%"
|
|
|
|
}}, espace: "top"},
|
|
|
|
{nom: "dix", espace: "top"}],
|
2017-11-28 11:45:06 +00:00
|
|
|
rules = parseAll(rawRules.map(enrichRule)),
|
2017-11-07 18:46:40 +00:00
|
|
|
analysis = analyse(rules,"startHere")(stateSelector),
|
|
|
|
result = collectMissingVariables(analysis.targets)
|
2017-07-28 08:22:22 +00:00
|
|
|
|
2017-07-28 10:14:18 +00:00
|
|
|
expect(result).to.deep.equal({})
|
2017-07-28 08:22:22 +00:00
|
|
|
});
|
|
|
|
|
2017-07-07 08:35:40 +00:00
|
|
|
});
|
|
|
|
|
2017-11-04 11:27:12 +00:00
|
|
|
describe('nextSteps', function() {
|
2017-07-01 09:17:54 +00:00
|
|
|
|
|
|
|
it('should generate questions', function() {
|
|
|
|
let rawRules = [
|
|
|
|
{nom: "sum", formule: {somme: [2, "deux"]}, espace: "top"},
|
2017-09-07 20:22:16 +00:00
|
|
|
{nom: "deux", formule: 2, "non applicable si" : "top . sum . evt = 'ko'", espace: "top"},
|
2017-07-01 09:17:54 +00:00
|
|
|
{nom: "evt", espace: "top . sum", formule: {"une possibilité":["ko"]}, titre: "Truc", question:"?"},
|
|
|
|
{nom: "ko", espace: "top . sum . evt"}],
|
2017-11-28 11:45:06 +00:00
|
|
|
rules = parseAll(rawRules.map(enrichRule)),
|
2017-11-07 18:46:40 +00:00
|
|
|
analysis = analyse(rules,"sum")(stateSelector),
|
2017-11-28 11:45:06 +00:00
|
|
|
result = getNextSteps(stateSelector, analysis)
|
2017-07-01 09:17:54 +00:00
|
|
|
|
|
|
|
expect(result).to.have.lengthOf(1)
|
2017-11-04 11:27:12 +00:00
|
|
|
expect(result[0]).to.equal("top . sum . evt")
|
2017-07-01 09:17:54 +00:00
|
|
|
});
|
|
|
|
|
2017-07-11 14:39:05 +00:00
|
|
|
it('should generate questions from the real rules', function() {
|
2017-11-28 11:45:06 +00:00
|
|
|
let rules = parseAll(realRules.map(enrichRule)),
|
2017-11-07 18:46:40 +00:00
|
|
|
analysis = analyse(rules,"surcoût CDD")(stateSelector),
|
|
|
|
missing = collectMissingVariables(analysis.targets),
|
2017-11-28 11:45:06 +00:00
|
|
|
result = getNextSteps(stateSelector, analysis)
|
2017-07-11 14:39:05 +00:00
|
|
|
|
2017-10-03 16:48:03 +00:00
|
|
|
// expect(objectives).to.have.lengthOf(4)
|
2017-09-07 14:52:14 +00:00
|
|
|
|
2017-10-03 16:48:03 +00:00
|
|
|
// expect(missing).to.have.property('contrat salarié . type de contrat')
|
|
|
|
// expect(missing).to.have.property('contrat salarié . CDD . événement')
|
|
|
|
// expect(missing).to.have.property('contrat salarié . CDD . motif')
|
|
|
|
// expect(missing).to.have.property('contrat salarié . salaire de base')
|
|
|
|
// expect(missing).to.have.property('contrat salarié . CDD . contrat jeune vacances')
|
|
|
|
// expect(missing).to.have.property('contrat salarié . CDD . durée contrat')
|
|
|
|
// expect(missing).to.have.property('contrat salarié . CDD . congés non pris')
|
2017-09-07 14:52:14 +00:00
|
|
|
|
|
|
|
// One question per missing variable !
|
2017-10-03 16:48:03 +00:00
|
|
|
// expect(R.keys(missing)).to.have.lengthOf(7)
|
|
|
|
// expect(result).to.have.lengthOf(7)
|
|
|
|
|
|
|
|
// expect(R.path(["question","props","label"])(result[0])).to.equal("Quelle est la nature du contrat de travail ?")
|
|
|
|
// expect(R.path(["question","props","label"])(result[1])).to.equal("Pensez-vous être confronté à l'un de ces événements au cours du contrat ?")
|
|
|
|
// expect(R.path(["question","props","label"])(result[2])).to.equal("Quel est le motif de recours au CDD ?")
|
|
|
|
// expect(R.path(["question","props","label"])(result[3])).to.equal("Quel est le salaire brut ?")
|
|
|
|
// expect(R.path(["question","props","label"])(result[4])).to.equal("Est-ce un contrat jeune vacances ?")
|
|
|
|
// expect(R.path(["question","props","label"])(result[5])).to.equal("Quelle est la durée du contrat ?")
|
|
|
|
// expect(R.path(["question","props","label"])(result[6])).to.equal("Combien de jours de congés ne seront pas pris ?")
|
2017-07-11 14:39:05 +00:00
|
|
|
});
|
|
|
|
|
2017-07-28 14:25:07 +00:00
|
|
|
it('should generate questions from the real rules, experimental version', function() {
|
2017-09-18 22:08:39 +00:00
|
|
|
let stateSelector = (name) => ({"contrat salarié . type de contrat":"CDI","entreprise . effectif":"50"})[name]
|
2017-07-28 14:25:07 +00:00
|
|
|
|
2017-11-28 11:45:06 +00:00
|
|
|
let rules = parseAll(realRules.map(enrichRule)),
|
2017-11-27 12:57:11 +00:00
|
|
|
analysis = analyse(rules,"salaire")(stateSelector),
|
2017-11-07 18:46:40 +00:00
|
|
|
missing = collectMissingVariables(analysis.targets),
|
2017-11-28 11:45:06 +00:00
|
|
|
result = getNextSteps(stateSelector, analysis)
|
2017-07-28 14:25:07 +00:00
|
|
|
|
2017-11-04 11:27:12 +00:00
|
|
|
expect(result[0]).to.equal("contrat salarié . salaire de base")
|
|
|
|
expect(result[1]).to.equal("contrat salarié . temps partiel")
|
2017-07-28 14:25:07 +00:00
|
|
|
});
|
|
|
|
|
2017-11-27 12:57:11 +00:00
|
|
|
it('should ask "motif CDD" if "CDD" applies', function() {
|
|
|
|
let stateSelector = (name) => ({"contrat salarié . type de contrat":"CDD","contrat salarié . salaire de base":"2300"})[name]
|
|
|
|
|
2017-11-28 11:45:06 +00:00
|
|
|
let rules = parseAll(realRules.map(enrichRule)),
|
2017-11-27 12:57:11 +00:00
|
|
|
analysis = analyse(rules,"salaire net")(stateSelector),
|
|
|
|
missing = collectMissingVariables(analysis.targets),
|
2017-11-28 11:45:06 +00:00
|
|
|
result = getNextSteps(stateSelector, analysis)
|
2017-11-27 12:57:11 +00:00
|
|
|
|
|
|
|
expect(result).to.include("contrat salarié . CDD . motif")
|
|
|
|
});
|
|
|
|
|
2017-07-01 09:17:54 +00:00
|
|
|
});
|