diff --git a/package.json b/package.json index 28a69d0..a4b99d0 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/source/migration/migrateSituation/handleSpecialCases.ts b/source/migration/migrateSituation/handleSpecialCases.ts index 0c9ad87..ace4870 100644 --- a/source/migration/migrateSituation/handleSpecialCases.ts +++ b/source/migration/migrateSituation/handleSpecialCases.ts @@ -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 diff --git a/test/migration/migrateSituation.test.ts b/test/migration/migrateSituation.test.ts index 67c26d7..9eae08e 100644 --- a/test/migration/migrateSituation.test.ts +++ b/test/migration/migrateSituation.test.ts @@ -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' } }, @@ -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 }, + }) }) })