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

Commit

Permalink
fix: type error
Browse files Browse the repository at this point in the history
  • Loading branch information
Clemog committed May 16, 2024
1 parent bcb13ba commit 460a4c1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
25 changes: 12 additions & 13 deletions source/migration/migrateSituation/handleSpecialCases.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { DottedName, Situation } from '../migrateSituation'
import { DottedName, NodeValue, Situation } from '../migrateSituation'

type Props = {
ruleName: DottedName
// Should be fixed
nodeValue: any
nodeValue: NodeValue
situation: Situation
}

Expand Down Expand Up @@ -35,21 +34,21 @@ export function handleSpecialCases({ ruleName, nodeValue, situation }: Props) {

// Special case : wrong value format, legacy from previous publicodes version
// handle the case where valeur is a string "2.33"
if (nodeValue && nodeValue.valeur !== undefined) {
if (nodeValue && nodeValue['valeur'] !== undefined) {
situationUpdated[ruleName] =
typeof nodeValue.valeur === 'string' &&
!isNaN(parseFloat(nodeValue.valeur))
? parseFloat(nodeValue.valeur)
: (nodeValue.valeur as number)
typeof nodeValue['valeur'] === 'string' &&
!isNaN(parseFloat(nodeValue['valeur']))
? parseFloat(nodeValue['valeur'])
: (nodeValue['valeur'] as number)
}
// Special case : other wrong value format, legacy from previous publicodes version
// handle the case where nodeValue is a string "2.33"
if (nodeValue && nodeValue.nodeValue !== undefined) {
if (nodeValue && nodeValue['valeur'] !== undefined) {
situationUpdated[ruleName] =
typeof nodeValue.nodeValue === 'string' &&
!isNaN(parseFloat(nodeValue.nodeValue))
? parseFloat(nodeValue.nodeValue)
: (nodeValue.nodeValue as number)
typeof nodeValue['valeur'] === 'string' &&
!isNaN(parseFloat(nodeValue['valeur']))
? parseFloat(nodeValue['valeur'])
: (nodeValue['valeur'] as number)
}

return situationUpdated
Expand Down
12 changes: 12 additions & 0 deletions test/migration/migrateSituation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,17 @@ describe('migrateSituation', () => {
foldedStepsMigrated: [],
situationMigrated: {},
})
}),
it('should support old situations', () => {
expect(
migrateSituation({
situation: { âge: { valeur: 27, unité: 'an' } },
foldedSteps: ['âge'],
migrationInstructions,
}),
).toEqual({
foldedStepsMigrated: ['âge'],
situationMigrated: { âge: 27 },
})
})
})

0 comments on commit 460a4c1

Please sign in to comment.