Skip to content

Commit

Permalink
fix: handle empty input in extractDimensionIdParts
Browse files Browse the repository at this point in the history
  • Loading branch information
martinkrulltott committed Mar 5, 2024
1 parent 5ee3906 commit 45ed729
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
34 changes: 34 additions & 0 deletions src/modules/__tests__/dimensionId.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,40 @@ describe('formatDimensionId', () => {
})

describe('extractDimensionIdParts', () => {
it('returns correct result for: null', () => {
const output = extractDimensionIdParts(null)

expect(output.dimensionId).toEqual('')
expect(output.programStageId).toEqual('')
expect(output.programId).toBeUndefined()
expect(output.repetitionIndex).toBeUndefined()
})
it('returns correct result for Tracked Entity: null', () => {
const inputType = OUTPUT_TYPE_TRACKED_ENTITY
const output = extractDimensionIdParts(null, inputType)

expect(output.dimensionId).toEqual('')
expect(output.programStageId).toEqual('')
expect(output.programId).toBeUndefined()
expect(output.repetitionIndex).toBeUndefined()
})
it('returns correct result for: undefined', () => {
const output = extractDimensionIdParts()

expect(output.dimensionId).toEqual('')
expect(output.programStageId).toEqual('')
expect(output.programId).toBeUndefined()
expect(output.repetitionIndex).toBeUndefined()
})
it('returns correct result for Tracked Entity: undefined', () => {
const inputType = OUTPUT_TYPE_TRACKED_ENTITY
const output = extractDimensionIdParts(undefined, inputType)

expect(output.dimensionId).toEqual('')
expect(output.programStageId).toEqual('')
expect(output.programId).toBeUndefined()
expect(output.repetitionIndex).toBeUndefined()
})
it('returns correct result for: dimensionId', () => {
const id = 'did'
const output = extractDimensionIdParts(id)
Expand Down
2 changes: 1 addition & 1 deletion src/modules/dimensionId.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const formatDimensionId = ({

export const extractDimensionIdParts = (id, inputType) => {
let rawStageId
const [dimensionId, part2, part3] = id.split('.').reverse()
const [dimensionId, part2, part3] = (id || '').split('.').reverse()
let programId = part3
if (part3 || inputType !== OUTPUT_TYPE_TRACKED_ENTITY) {
rawStageId = part2
Expand Down

0 comments on commit 45ed729

Please sign in to comment.