Skip to content

Commit

Permalink
Merge pull request #41 from publicodes/fix-special-case-migration
Browse files Browse the repository at this point in the history
fix: special case
  • Loading branch information
Clemog authored May 16, 2024
2 parents 813101c + 75a3747 commit 3b48325
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@publicodes/tools",
"version": "1.1.1",
"version": "1.1.2",
"description": "A set of utility functions to build tools around Publicodes models",
"type": "module",
"scripts": {
Expand Down
10 changes: 5 additions & 5 deletions source/migration/migrateSituation/handleSpecialCases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ export function handleSpecialCases({ ruleName, nodeValue, situation }: Props) {
}
// Special case : other wrong value format, legacy from previous publicodes version
// handle the case where nodeValue is a string "2.33"
if (nodeValue && nodeValue['valeur'] !== undefined) {
if (nodeValue && nodeValue['nodeValue'] !== undefined) {
situationUpdated[ruleName] =
typeof nodeValue['valeur'] === 'string' &&
!isNaN(parseFloat(nodeValue['valeur']))
? parseFloat(nodeValue['valeur'])
: (nodeValue['valeur'] as number)
typeof nodeValue['nodeValue'] === 'string' &&
!isNaN(parseFloat(nodeValue['nodeValue']))
? parseFloat(nodeValue['nodeValue'])
: (nodeValue['nodeValue'] as number)
}

return situationUpdated
Expand Down
23 changes: 22 additions & 1 deletion test/migration/migrateSituation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe('migrateSituation', () => {
situationMigrated: {},
})
}),
it('should support old situations', () => {
it('should support old situations (1)', () => {
expect(
migrateSituation({
situation: { âge: { valeur: 27, unité: 'an' } },
Expand All @@ -62,5 +62,26 @@ describe('migrateSituation', () => {
foldedStepsMigrated: ['âge'],
situationMigrated: { âge: 27 },
})
}),
it('should support old situations (2)', () => {
expect(
migrateSituation({
situation: {
âge: {
type: 'number',
fullPrecision: true,
isNullable: false,
nodeValue: 27,
nodeKind: 'constant',
rawNode: 27,
},
},
foldedSteps: ['âge'],
migrationInstructions,
}),
).toEqual({
foldedStepsMigrated: ['âge'],
situationMigrated: { âge: 27 },
})
})
})

0 comments on commit 3b48325

Please sign in to comment.