2018-01-03 15:54:19 +00:00
|
|
|
import { expect } from 'chai'
|
2019-10-11 15:01:11 +00:00
|
|
|
import { getSituationValue } from '../source/engine/getSituationValue'
|
2017-07-06 10:30:29 +00:00
|
|
|
|
2018-09-07 15:30:50 +00:00
|
|
|
describe('getSituationValue', function() {
|
2018-01-03 15:54:19 +00:00
|
|
|
it('should directly return the value of any rule that specifies a format (i.e currency, duration)', function() {
|
2019-07-05 13:00:24 +00:00
|
|
|
let rule = { unité: '€' },
|
2018-01-03 15:54:19 +00:00
|
|
|
state = { salaire: '2300' },
|
|
|
|
situationGate = name => state[name]
|
2017-07-06 10:30:29 +00:00
|
|
|
|
2018-09-07 15:30:50 +00:00
|
|
|
expect(getSituationValue(situationGate, 'salaire', rule)).to.equal('2300')
|
2018-01-03 15:54:19 +00:00
|
|
|
})
|
2017-07-06 10:30:29 +00:00
|
|
|
|
2018-01-03 15:54:19 +00:00
|
|
|
it("should interpret rules without a formula as boolean-valued, with 'oui' for true", function() {
|
2017-07-06 10:30:29 +00:00
|
|
|
let rule = {},
|
2018-01-03 15:54:19 +00:00
|
|
|
state = { condition: 'oui' },
|
|
|
|
situationGate = name => state[name]
|
2017-07-06 10:30:29 +00:00
|
|
|
|
2018-09-07 15:30:50 +00:00
|
|
|
expect(getSituationValue(situationGate, 'condition', rule)).to.be.true
|
2018-01-03 15:54:19 +00:00
|
|
|
})
|
2017-07-06 10:30:29 +00:00
|
|
|
|
2018-09-04 19:14:56 +00:00
|
|
|
it("should interpret rules without a formula as boolean-valued, with 'non' meaning false", function() {
|
2017-07-06 10:30:29 +00:00
|
|
|
let rule = {},
|
2018-09-04 19:14:56 +00:00
|
|
|
state = { condition: 'non' },
|
2018-01-03 15:54:19 +00:00
|
|
|
situationGate = name => state[name]
|
|
|
|
|
2018-09-07 15:30:50 +00:00
|
|
|
expect(getSituationValue(situationGate, 'condition', rule)).to.be.false
|
2018-01-03 15:54:19 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it("should interpret rules with 'one of these', with 'oui' for true", function() {
|
|
|
|
let rule = { formule: { 'une possibilité': ['noir', 'blanc'] } },
|
|
|
|
state = { condition: 'oui' },
|
|
|
|
situationGate = name => state[name]
|
|
|
|
|
2018-09-07 15:30:50 +00:00
|
|
|
expect(getSituationValue(situationGate, 'condition', rule)).to.be.true
|
2018-01-03 15:54:19 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should walk up the namespace chain until it finds the tail as the value', function() {
|
|
|
|
let rule = { formule: { 'une possibilité': ['noir', 'blanc'] } },
|
|
|
|
state = {
|
|
|
|
'contrat salarié . CDD . motif': 'classique . accroissement activité'
|
|
|
|
},
|
|
|
|
situationGate = name => state[name]
|
|
|
|
|
|
|
|
expect(
|
2018-09-07 15:30:50 +00:00
|
|
|
getSituationValue(
|
2018-01-03 15:54:19 +00:00
|
|
|
situationGate,
|
|
|
|
'contrat salarié . CDD . motif . classique . accroissement activité',
|
|
|
|
rule
|
|
|
|
)
|
|
|
|
).to.be.true
|
|
|
|
})
|
|
|
|
|
|
|
|
it("should return null if a value isn't found for the name given", function() {
|
|
|
|
let rule = { formule: { 'une possibilité': ['noir', 'blanc'] } },
|
|
|
|
state = { condition: 'classique . accroissement activité' },
|
|
|
|
situationGate = name => state[name]
|
|
|
|
|
|
|
|
expect(
|
2018-09-07 15:30:50 +00:00
|
|
|
getSituationValue(
|
2018-01-03 15:54:19 +00:00
|
|
|
situationGate,
|
|
|
|
'contrat salarié . CDD . motif . classique . accroissement activité',
|
|
|
|
rule
|
|
|
|
)
|
|
|
|
).to.be.null
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should set the value of variants to false if one of them is true', function() {
|
|
|
|
let rule = {
|
2019-10-11 15:01:11 +00:00
|
|
|
nom: 'univers . ici',
|
2018-01-03 15:54:19 +00:00
|
|
|
formule: { 'une possibilité': ['noir', 'blanc'] }
|
|
|
|
},
|
|
|
|
state = { 'univers . ici': 'blanc' },
|
|
|
|
situationGate = name => state[name]
|
|
|
|
|
2018-09-07 15:30:50 +00:00
|
|
|
expect(getSituationValue(situationGate, 'univers . ici . noir', rule)).to.be
|
2018-01-03 15:54:19 +00:00
|
|
|
.false
|
|
|
|
})
|
|
|
|
})
|