From 9fb17b9049625a5dbe96a97bc9975cf82541b6f7 Mon Sep 17 00:00:00 2001 From: Jen Jones Arnesen Date: Wed, 22 May 2019 14:55:39 +0200 Subject: [PATCH] chore: use level uuids rather than level numbers (#26) Part of fix for [DHIS2-6990] The api has supported use of uid since 2.31 [DHIS2- 4889] --- .../OrgUnitDimension/OrgUnitDimension.js | 2 +- src/modules/__tests__/orgUnitDimension.spec.js | 15 +++++++++++++++ src/modules/orgUnitDimensions.js | 8 ++------ 3 files changed, 18 insertions(+), 7 deletions(-) create mode 100644 src/modules/__tests__/orgUnitDimension.spec.js diff --git a/src/components/OrgUnitDimension/OrgUnitDimension.js b/src/components/OrgUnitDimension/OrgUnitDimension.js index 3e75df5d9..076a79fe9 100644 --- a/src/components/OrgUnitDimension/OrgUnitDimension.js +++ b/src/components/OrgUnitDimension/OrgUnitDimension.js @@ -87,7 +87,7 @@ class OrgUnitDimension extends Component { return { ...levelOu, - id: `${LEVEL_ID_PREFIX}-${levelOu.level}`, + id: `${LEVEL_ID_PREFIX}-${levelOu.id}`, } }), ], diff --git a/src/modules/__tests__/orgUnitDimension.spec.js b/src/modules/__tests__/orgUnitDimension.spec.js new file mode 100644 index 000000000..67ed62e83 --- /dev/null +++ b/src/modules/__tests__/orgUnitDimension.spec.js @@ -0,0 +1,15 @@ +import { getLevelsFromIds } from '../orgUnitDimensions' + +const levelOptions = [{ id: 'fluttershy' }, { id: 'rarity' }] + +describe('orgUnitDimension module', () => { + it('returns array with id when level-id received', () => { + expect(getLevelsFromIds(['abc', 'LEVEL-rarity'], levelOptions)).toEqual( + ['rarity'] + ) + }) + + it('returns empty array when level-id not received', () => { + expect(getLevelsFromIds(['abc', 'rarity'], levelOptions)).toEqual([]) + }) +}) diff --git a/src/modules/orgUnitDimensions.js b/src/modules/orgUnitDimensions.js index 9f5b7e1c4..eb0e97af4 100644 --- a/src/modules/orgUnitDimensions.js +++ b/src/modules/orgUnitDimensions.js @@ -86,12 +86,8 @@ export const getLevelsFromIds = (ids, levelOptions) => { return ids .filter(isLevelId) .map(id => id.substr(LEVEL_ID_PREFIX.length + 1)) - .map( - level => - levelOptions.find( - option => Number(option.level) === Number(level) - ).id - ) + .map(id => levelOptions.find(option => option.id === id)) + .map(level => level.id) } /**