2022-05-17 08:45:25 +00:00
|
|
|
import rules from 'modele-social'
|
2020-05-08 10:04:00 +00:00
|
|
|
import Engine from 'publicodes'
|
2022-05-17 08:45:25 +00:00
|
|
|
import { describe, expect, it } from 'vitest'
|
2022-11-03 16:32:04 +00:00
|
|
|
|
2023-02-28 14:05:28 +00:00
|
|
|
import { getNextQuestions } from '../source/hooks/useNextQuestion'
|
2018-06-18 10:12:08 +00:00
|
|
|
|
2020-12-01 09:17:27 +00:00
|
|
|
describe('conversation', function () {
|
|
|
|
it('should start with the first missing variable', function () {
|
2020-04-23 07:30:03 +00:00
|
|
|
const missingVariables = new Engine({
|
2020-03-26 15:03:19 +00:00
|
|
|
// TODO - this won't work without the indirection, figure out why
|
2020-12-01 09:17:27 +00:00
|
|
|
top: 'oui',
|
2020-04-23 07:30:03 +00:00
|
|
|
'top . startHere': { formule: { somme: ['a', 'b'] } },
|
2022-05-17 08:45:25 +00:00
|
|
|
'top . a': { question: '?', titre: 'a', unité: '€' },
|
|
|
|
'top . b': { question: '?', titre: 'b', unité: '€' },
|
2020-04-23 07:30:03 +00:00
|
|
|
}).evaluate('top . startHere').missingVariables
|
2024-02-23 10:31:44 +00:00
|
|
|
expect(getNextQuestions(missingVariables)[0]).toBe('top . a')
|
2018-06-18 10:12:08 +00:00
|
|
|
})
|
2020-12-01 09:17:27 +00:00
|
|
|
it('should first ask for questions without defaults, then those with defaults', function () {
|
2020-04-23 07:30:03 +00:00
|
|
|
const engine = new Engine({
|
2020-03-26 15:03:19 +00:00
|
|
|
net: { formule: 'brut - cotisation' },
|
|
|
|
brut: {
|
2020-04-23 07:30:03 +00:00
|
|
|
question: 'Quel est le salaire brut ?',
|
2020-12-01 09:17:27 +00:00
|
|
|
unité: '€/an',
|
2020-03-26 15:03:19 +00:00
|
|
|
},
|
|
|
|
cotisation: {
|
|
|
|
formule: {
|
2023-12-14 09:54:17 +00:00
|
|
|
produit: [
|
|
|
|
'brut',
|
|
|
|
{
|
|
|
|
variations: [
|
|
|
|
{
|
|
|
|
si: 'cadre',
|
|
|
|
alors: '77%',
|
2020-12-01 09:17:27 +00:00
|
|
|
},
|
2023-12-14 09:54:17 +00:00
|
|
|
{
|
|
|
|
sinon: '80%',
|
2020-12-01 09:17:27 +00:00
|
|
|
},
|
2023-12-14 09:54:17 +00:00
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
2020-12-01 09:17:27 +00:00
|
|
|
},
|
2020-03-26 15:03:19 +00:00
|
|
|
},
|
|
|
|
cadre: {
|
|
|
|
question: 'Est-ce un cadre ?',
|
2020-12-01 09:17:27 +00:00
|
|
|
},
|
2020-04-02 16:54:41 +00:00
|
|
|
})
|
|
|
|
|
2024-02-23 10:31:44 +00:00
|
|
|
expect(getNextQuestions(engine.evaluate('net').missingVariables)[0]).toBe(
|
|
|
|
'brut'
|
|
|
|
)
|
2020-04-21 13:49:48 +00:00
|
|
|
|
2020-04-23 07:30:03 +00:00
|
|
|
engine.setSituation({
|
2020-12-01 09:17:27 +00:00
|
|
|
brut: 2300,
|
2020-04-23 07:30:03 +00:00
|
|
|
})
|
|
|
|
|
2024-02-23 10:31:44 +00:00
|
|
|
expect(getNextQuestions(engine.evaluate('net').missingVariables)[0]).toBe(
|
|
|
|
'cadre'
|
|
|
|
)
|
2018-06-19 08:30:43 +00:00
|
|
|
})
|
2020-05-08 10:04:00 +00:00
|
|
|
|
2020-12-01 09:17:27 +00:00
|
|
|
it('should ask "motif CDD" if "CDD" applies', function () {
|
2020-05-08 10:04:00 +00:00
|
|
|
const result = Object.keys(
|
|
|
|
new Engine(rules)
|
|
|
|
.setSituation({
|
2022-05-24 17:00:18 +00:00
|
|
|
salarié: 'oui',
|
2022-05-24 12:31:22 +00:00
|
|
|
'salarié . contrat . CDD': 'oui',
|
|
|
|
'salarié . contrat . salaire brut': '2300',
|
2020-05-08 10:04:00 +00:00
|
|
|
})
|
2022-05-24 17:00:18 +00:00
|
|
|
.evaluate('salarié . rémunération . net . à payer avant impôt')
|
|
|
|
.missingVariables
|
2020-05-08 10:04:00 +00:00
|
|
|
)
|
|
|
|
|
2024-02-23 10:31:44 +00:00
|
|
|
expect(result).toContain('salarié . contrat . CDD . motif')
|
2020-05-08 10:04:00 +00:00
|
|
|
})
|
|
|
|
})
|