Skip to content
This repository was archived by the owner on Feb 14, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 },
})
})
})