mon-entreprise/site/test/conversation.test.ts

78 lines
1.9 KiB
TypeScript
Raw Permalink Normal View History

import rules from 'modele-social'
import Engine from 'publicodes'
import { describe, expect, it } from 'vitest'
2022-11-03 16:32:04 +00:00
import { getNextQuestions } from '../source/components/utils/useNextQuestion'
describe('conversation', function () {
it('should start with the first missing variable', function () {
const missingVariables = new Engine({
2020-03-26 15:03:19 +00:00
// TODO - this won't work without the indirection, figure out why
top: 'oui',
'top . startHere': { formule: { somme: ['a', 'b'] } },
'top . a': { question: '?', titre: 'a', unité: '€' },
'top . b': { question: '?', titre: 'b', unité: '€' },
}).evaluate('top . startHere').missingVariables
expect(getNextQuestions(missingVariables)[0]).to.equal('top . a')
})
it('should first ask for questions without defaults, then those with defaults', function () {
const engine = new Engine({
2020-03-26 15:03:19 +00:00
net: { formule: 'brut - cotisation' },
brut: {
question: 'Quel est le salaire brut ?',
unité: '€/an',
2020-03-26 15:03:19 +00:00
},
cotisation: {
formule: {
produit: {
assiette: 'brut',
variations: [
{
si: 'cadre',
alors: {
taux: '77%',
},
2020-03-26 15:03:19 +00:00
},
{
sinon: {
taux: '80%',
},
},
],
},
},
2020-03-26 15:03:19 +00:00
},
cadre: {
question: 'Est-ce un cadre ?',
},
})
expect(
getNextQuestions(engine.evaluate('net').missingVariables)[0]
).to.equal('brut')
engine.setSituation({
brut: 2300,
})
expect(
getNextQuestions(engine.evaluate('net').missingVariables)[0]
).to.equal('cadre')
})
it('should ask "motif CDD" if "CDD" applies', function () {
const result = Object.keys(
new Engine(rules)
.setSituation({
salarié: 'oui',
'salarié . contrat . CDD': 'oui',
'salarié . contrat . salaire brut': '2300',
})
.evaluate('salarié . rémunération . net . à payer avant impôt')
.missingVariables
)
expect(result).to.include('salarié . contrat . CDD . motif')
})
})