Skip to content

Commit

Permalink
refactor(optim): add the missing 'grille' mecanism for serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
EmileRolley committed Jan 17, 2024
1 parent fed1c1e commit f93551a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
5 changes: 3 additions & 2 deletions source/serializeParsedRules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,9 @@ function serializeASTNode(node: ASTNode): SerializedRule {
}
}

case 'taux progressif':
case 'barème': {
case 'barème':
case 'grille':
case 'taux progressif': {
const serializedNode = {
assiette: serializeASTNode(node.explanation.assiette),
tranches: node.explanation.tranches.map((tranche) => {
Expand Down
29 changes: 29 additions & 0 deletions test/serializeParsedRules.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,35 @@ describe('API > mecanisms list', () => {
expect(serializedRules).toStrictEqual(rules)
})

it('should serialize rule with [grille]', () => {
const rules = {
'SMIC horaire': {
valeur: '10 €/heures',
},
'revenu cotisé': {
valeur: '1900 €/an',
},
'trimestres validés': {
unité: 'trimestres validés/an',
grille: {
assiette: 'revenu cotisé',
multiplicateur: 'SMIC horaire',
tranches: [
{ montant: 0, plafond: '150 heures/an' },
{ montant: 1, plafond: '300 heures/an' },
{ montant: 2, plafond: '450 heures/an' },
{ montant: 3, plafond: '600 heures/an' },
{ montant: 4 },
],
},
},
}
const serializedRules = serializeParsedRules(
new Engine(rules).getParsedRules(),
)
expect(serializedRules).toStrictEqual(rules)
})

it("should serialize rule with [barème] and a custom 'multiplicateur'", () => {
const rules = {
'revenu imposable': {
Expand Down

0 comments on commit f93551a

Please sign in to comment.