From 00a70297c033b5e94055f33108d0e9d776f1eecb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment?= Date: Thu, 16 May 2024 11:15:16 +0200 Subject: [PATCH 1/2] fix: special case --- .../migrateSituation/handleSpecialCases.ts | 10 ++++---- test/migration/migrateSituation.test.ts | 23 ++++++++++++++++++- 2 files changed, 27 insertions(+), 6 deletions(-) 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 }, + }) }) }) From 75a3747f67487b8b203eb2eac6722388f4d9b470 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment?= Date: Thu, 16 May 2024 11:18:01 +0200 Subject: [PATCH 2/2] v1.1.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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": {