Skip to content
This repository has been archived by the owner on Feb 14, 2025. It is now read-only.

Commit

Permalink
fix: special case
Browse files Browse the repository at this point in the history
  • Loading branch information
Clemog committed May 16, 2024
1 parent 813101c commit 00a7029
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
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 00a7029

Please sign in to comment.