diff --git a/packages/report-server/src/__tests__/reportBuilder/transform/aliases.test.ts b/packages/report-server/src/__tests__/reportBuilder/transform/aliases.test.ts index 8ce40d503b..3050cee4c9 100644 --- a/packages/report-server/src/__tests__/reportBuilder/transform/aliases.test.ts +++ b/packages/report-server/src/__tests__/reportBuilder/transform/aliases.test.ts @@ -17,7 +17,7 @@ import { buildTransform, TransformTable } from '../../../reportBuilder/transform describe('aliases', () => { it('keyValueByDataElementName', () => { const transform = buildTransform(['keyValueByDataElementName']); - expect(transform(TransformTable.fromRows(MULTIPLE_ANALYTICS))).toEqual( + expect(transform(TransformTable.fromRows(MULTIPLE_ANALYTICS))).toStrictEqual( TransformTable.fromRows([ { period: '20200101', organisationUnit: 'TO', BCD1: 4 }, { period: '20200102', organisationUnit: 'TO', BCD1: 2 }, @@ -28,7 +28,7 @@ describe('aliases', () => { it('keyValueByOrgUnit', () => { const transform = buildTransform(['keyValueByOrgUnit']); - expect(transform(TransformTable.fromRows(MULTIPLE_ANALYTICS))).toEqual( + expect(transform(TransformTable.fromRows(MULTIPLE_ANALYTICS))).toStrictEqual( TransformTable.fromRows([ { period: '20200101', dataElement: 'BCD1', TO: 4 }, { period: '20200102', dataElement: 'BCD1', TO: 2 }, @@ -39,7 +39,7 @@ describe('aliases', () => { it('keyValueByPeriod', () => { const transform = buildTransform(['keyValueByPeriod']); - expect(transform(TransformTable.fromRows(MULTIPLE_ANALYTICS))).toEqual( + expect(transform(TransformTable.fromRows(MULTIPLE_ANALYTICS))).toStrictEqual( TransformTable.fromRows( [ { organisationUnit: 'TO', dataElement: 'BCD1', '20200101': 4 }, @@ -53,7 +53,7 @@ describe('aliases', () => { it('mostRecentValuePerOrgUnit', () => { const transform = buildTransform(['mostRecentValuePerOrgUnit']); - expect(transform(TransformTable.fromRows(MERGEABLE_ANALYTICS))).toEqual( + expect(transform(TransformTable.fromRows(MERGEABLE_ANALYTICS))).toStrictEqual( TransformTable.fromRows([ { period: '20200103', organisationUnit: 'TO', BCD1: 5, BCD2: 0 }, { period: '20200103', organisationUnit: 'PG', BCD1: 2, BCD2: -1 }, @@ -63,7 +63,7 @@ describe('aliases', () => { it('firstValuePerPeriodPerOrgUnit', () => { const transform = buildTransform(['firstValuePerPeriodPerOrgUnit']); - expect(transform(TransformTable.fromRows(MULTIPLE_MERGEABLE_ANALYTICS))).toEqual( + expect(transform(TransformTable.fromRows(MULTIPLE_MERGEABLE_ANALYTICS))).toStrictEqual( TransformTable.fromRows([ { period: '20200101', organisationUnit: 'TO', BCD1: 4, BCD2: 11 }, { period: '20200102', organisationUnit: 'TO', BCD1: 2, BCD2: 1 }, @@ -77,7 +77,7 @@ describe('aliases', () => { it('lastValuePerPeriodPerOrgUnit', () => { const transform = buildTransform(['lastValuePerPeriodPerOrgUnit']); - expect(transform(TransformTable.fromRows(MULTIPLE_MERGEABLE_ANALYTICS))).toEqual( + expect(transform(TransformTable.fromRows(MULTIPLE_MERGEABLE_ANALYTICS))).toStrictEqual( TransformTable.fromRows([ { period: '20200101', organisationUnit: 'TO', BCD1: 7, BCD2: 4 }, { period: '20200102', organisationUnit: 'TO', BCD1: 12, BCD2: 18 }, @@ -91,14 +91,14 @@ describe('aliases', () => { it('convertPeriodToWeek', () => { const transform = buildTransform(['convertPeriodToWeek']); - expect(transform(TransformTable.fromRows(SINGLE_ANALYTIC))).toEqual( + expect(transform(TransformTable.fromRows(SINGLE_ANALYTIC))).toStrictEqual( TransformTable.fromRows([{ ...SINGLE_ANALYTIC[0], period: '2020W01' }]), ); }); it('convertEventDateToWeek', () => { const transform = buildTransform(['convertEventDateToWeek']); - expect(transform(TransformTable.fromRows(SINGLE_EVENT))).toEqual( + expect(transform(TransformTable.fromRows(SINGLE_EVENT))).toStrictEqual( TransformTable.fromRows([{ ...SINGLE_EVENT[0], period: '2020W01' }]), ); }); @@ -107,7 +107,7 @@ describe('aliases', () => { const transform = buildTransform(['insertNumberOfFacilitiesColumn'], { facilityCountByOrgUnit: { TO: 14 }, }); - expect(transform(TransformTable.fromRows(SINGLE_ANALYTIC))).toEqual( + expect(transform(TransformTable.fromRows(SINGLE_ANALYTIC))).toStrictEqual( TransformTable.fromRows([{ ...SINGLE_ANALYTIC[0], numberOfFacilities: 14 }]), ); }); @@ -116,7 +116,7 @@ describe('aliases', () => { describe('insertSummaryRowAndColumn', () => { it('inserts a summary row and summary column', () => { const transform = buildTransform(['insertSummaryRowAndColumn']); - expect(transform(TransformTable.fromRows(TRANSFORMED_SUMMARY_BINARY))).toEqual( + expect(transform(TransformTable.fromRows(TRANSFORMED_SUMMARY_BINARY))).toStrictEqual( TransformTable.fromRows([ { dataElement: 'Male condoms', TO: 'N', FJ: 'N', NR: 'Y', KI: 'N', summaryColumn: '75.0%' }, { @@ -140,7 +140,7 @@ describe('insertSummaryRowAndColumn', () => { it('only summarises columns that have only Y | N | undefined values', () => { const transform = buildTransform(['insertSummaryRowAndColumn']); - expect(transform(TransformTable.fromRows(TRANSFORMED_SUMMARY_VARIOUS))).toEqual( + expect(transform(TransformTable.fromRows(TRANSFORMED_SUMMARY_VARIOUS))).toStrictEqual( TransformTable.fromRows([ { dataElement: 'Male condoms', diff --git a/packages/report-server/src/__tests__/reportBuilder/transform/excludeColumns.test.ts b/packages/report-server/src/__tests__/reportBuilder/transform/excludeColumns.test.ts index f5e1bd106c..be1d33c0fc 100644 --- a/packages/report-server/src/__tests__/reportBuilder/transform/excludeColumns.test.ts +++ b/packages/report-server/src/__tests__/reportBuilder/transform/excludeColumns.test.ts @@ -14,7 +14,7 @@ describe('excludeColumns', () => { columns: '*', }, ]); - expect(transform(TransformTable.fromRows(SINGLE_ANALYTIC))).toEqual( + expect(transform(TransformTable.fromRows(SINGLE_ANALYTIC))).toStrictEqual( TransformTable.fromRows([{}]), ); }); @@ -26,7 +26,7 @@ describe('excludeColumns', () => { columns: ['organisationUnit', 'value'], }, ]); - expect(transform(TransformTable.fromRows(MULTIPLE_ANALYTICS))).toEqual( + expect(transform(TransformTable.fromRows(MULTIPLE_ANALYTICS))).toStrictEqual( TransformTable.fromRows([ { period: '20200101', dataElement: 'BCD1' }, { period: '20200102', dataElement: 'BCD1' }, diff --git a/packages/report-server/src/__tests__/reportBuilder/transform/excludeRows.test.ts b/packages/report-server/src/__tests__/reportBuilder/transform/excludeRows.test.ts index 038c58a08c..3d55871373 100644 --- a/packages/report-server/src/__tests__/reportBuilder/transform/excludeRows.test.ts +++ b/packages/report-server/src/__tests__/reportBuilder/transform/excludeRows.test.ts @@ -14,7 +14,7 @@ describe('excludeRows', () => { where: '=$BCD1 < 6', }, ]); - expect(transform(TransformTable.fromRows(EXCLUDEABLE_ANALYTICS))).toEqual( + expect(transform(TransformTable.fromRows(EXCLUDEABLE_ANALYTICS))).toStrictEqual( TransformTable.fromRows([ { period: '20200101', organisationUnit: 'PG', BCD1: 7 }, { period: '20200102', organisationUnit: 'PG', BCD1: 8 }, diff --git a/packages/report-server/src/__tests__/reportBuilder/transform/gatherColumns.test.ts b/packages/report-server/src/__tests__/reportBuilder/transform/gatherColumns.test.ts index b9639f59f6..c6d78995ec 100644 --- a/packages/report-server/src/__tests__/reportBuilder/transform/gatherColumns.test.ts +++ b/packages/report-server/src/__tests__/reportBuilder/transform/gatherColumns.test.ts @@ -13,7 +13,7 @@ describe('gatherColumns', () => { transform: 'gatherColumns', }, ]); - expect(transform(TransformTable.fromRows(SINGLE_ANALYTIC))).toEqual( + expect(transform(TransformTable.fromRows(SINGLE_ANALYTIC))).toStrictEqual( TransformTable.fromRows([ { value: '20200101', columnName: 'period' }, { value: 'TO', columnName: 'organisationUnit' }, @@ -30,7 +30,7 @@ describe('gatherColumns', () => { keep: 'organisationUnit', }, ]); - expect(transform(TransformTable.fromRows(SINGLE_ANALYTIC))).toEqual( + expect(transform(TransformTable.fromRows(SINGLE_ANALYTIC))).toStrictEqual( TransformTable.fromRows([ { organisationUnit: 'TO', value: '20200101', columnName: 'period' }, { organisationUnit: 'TO', value: 'BCD1', columnName: 'dataElement' }, @@ -46,7 +46,7 @@ describe('gatherColumns', () => { keep: ['organisationUnit', 'period'], }, ]); - expect(transform(TransformTable.fromRows(SINGLE_ANALYTIC))).toEqual( + expect(transform(TransformTable.fromRows(SINGLE_ANALYTIC))).toStrictEqual( TransformTable.fromRows([ { period: '20200101', organisationUnit: 'TO', value: 'BCD1', columnName: 'dataElement' }, { period: '20200101', organisationUnit: 'TO', value: 4, columnName: 'value' }, @@ -61,7 +61,7 @@ describe('gatherColumns', () => { keep: ['period'], }, ]); - expect(transform(TransformTable.fromRows(MULTIPLE_ANALYTICS))).toEqual( + expect(transform(TransformTable.fromRows(MULTIPLE_ANALYTICS))).toStrictEqual( TransformTable.fromRows([ { period: '20200101', value: 'TO', columnName: 'organisationUnit' }, { period: '20200101', value: 'BCD1', columnName: 'dataElement' }, diff --git a/packages/report-server/src/__tests__/reportBuilder/transform/insertColumns.test.ts b/packages/report-server/src/__tests__/reportBuilder/transform/insertColumns.test.ts index 385806d686..c865cf38e0 100644 --- a/packages/report-server/src/__tests__/reportBuilder/transform/insertColumns.test.ts +++ b/packages/report-server/src/__tests__/reportBuilder/transform/insertColumns.test.ts @@ -18,7 +18,7 @@ describe('insertColumns', () => { }, }, ]); - expect(transform(TransformTable.fromRows(SINGLE_ANALYTIC))).toEqual( + expect(transform(TransformTable.fromRows(SINGLE_ANALYTIC))).toStrictEqual( TransformTable.fromRows([{ ...SINGLE_ANALYTIC[0], number: 1, string: 'Hi', boolean: false }]), ); }); @@ -32,7 +32,7 @@ describe('insertColumns', () => { }, }, ]); - expect(transform(TransformTable.fromRows(SINGLE_ANALYTIC))).toEqual( + expect(transform(TransformTable.fromRows(SINGLE_ANALYTIC))).toStrictEqual( TransformTable.fromRows([{ ...SINGLE_ANALYTIC[0], dataElementValue: 4 }]), ); }); @@ -46,7 +46,7 @@ describe('insertColumns', () => { }, }, ]); - expect(transform(TransformTable.fromRows(SINGLE_ANALYTIC))).toEqual( + expect(transform(TransformTable.fromRows(SINGLE_ANALYTIC))).toStrictEqual( TransformTable.fromRows([{ ...SINGLE_ANALYTIC[0], BCD1: 4 }]), ); }); @@ -60,7 +60,7 @@ describe('insertColumns', () => { }, }, ]); - expect(transform(TransformTable.fromRows(SINGLE_ANALYTIC))).toEqual( + expect(transform(TransformTable.fromRows(SINGLE_ANALYTIC))).toStrictEqual( TransformTable.fromRows([{ ...SINGLE_ANALYTIC[0], period: '1st Jan 2020' }]), ); }); @@ -75,7 +75,7 @@ describe('insertColumns', () => { }, }, ]); - expect(transform(TransformTable.fromRows(MULTIPLE_ANALYTICS))).toEqual( + expect(transform(TransformTable.fromRows(MULTIPLE_ANALYTICS))).toStrictEqual( TransformTable.fromRows([ { ...MULTIPLE_ANALYTICS[0], period: '1st Jan 2020', BCD1: 4 }, { ...MULTIPLE_ANALYTICS[1], period: '2nd Jan 2020', BCD1: 2 }, @@ -94,7 +94,7 @@ describe('insertColumns', () => { }, }, ]); - expect(transform(TransformTable.fromRows(MERGEABLE_ANALYTICS))).toEqual( + expect(transform(TransformTable.fromRows(MERGEABLE_ANALYTICS))).toStrictEqual( TransformTable.fromRows( [ { ...MERGEABLE_ANALYTICS[0], newVal: 8 }, diff --git a/packages/report-server/src/__tests__/reportBuilder/transform/insertRows.test.ts b/packages/report-server/src/__tests__/reportBuilder/transform/insertRows.test.ts index f3386367ef..12e5ad01b4 100644 --- a/packages/report-server/src/__tests__/reportBuilder/transform/insertRows.test.ts +++ b/packages/report-server/src/__tests__/reportBuilder/transform/insertRows.test.ts @@ -19,7 +19,7 @@ describe('insertRows', () => { }, }, ]); - expect(transform(TransformTable.fromRows(SINGLE_ANALYTIC))).toEqual( + expect(transform(TransformTable.fromRows(SINGLE_ANALYTIC))).toStrictEqual( TransformTable.fromRows([...SINGLE_ANALYTIC, { number: 1, string: 'Hi', boolean: false }]), ); }); @@ -33,7 +33,7 @@ describe('insertRows', () => { }, }, ]); - expect(transform(TransformTable.fromRows(SINGLE_ANALYTIC))).toEqual( + expect(transform(TransformTable.fromRows(SINGLE_ANALYTIC))).toStrictEqual( TransformTable.fromRows([...SINGLE_ANALYTIC, { dataElementValue: 4 }]), ); }); @@ -47,7 +47,7 @@ describe('insertRows', () => { }, }, ]); - expect(transform(TransformTable.fromRows(SINGLE_ANALYTIC))).toEqual( + expect(transform(TransformTable.fromRows(SINGLE_ANALYTIC))).toStrictEqual( TransformTable.fromRows([...SINGLE_ANALYTIC, { BCD1: 4 }]), ); }); @@ -61,7 +61,7 @@ describe('insertRows', () => { }, }, ]); - expect(transform(TransformTable.fromRows(SINGLE_ANALYTIC))).toEqual( + expect(transform(TransformTable.fromRows(SINGLE_ANALYTIC))).toStrictEqual( TransformTable.fromRows([...SINGLE_ANALYTIC, { period: '1st Jan 2020' }]), ); }); @@ -80,7 +80,7 @@ describe('insertRows', () => { }, }, ]); - expect(transform(TransformTable.fromRows(MULTIPLE_ANALYTICS))).toEqual( + expect(transform(TransformTable.fromRows(MULTIPLE_ANALYTICS))).toStrictEqual( TransformTable.fromRows( [ { number: 1, string: 'Hi', boolean: false }, @@ -105,7 +105,7 @@ describe('insertRows', () => { }, }, ]); - expect(transform(TransformTable.fromRows(MULTIPLE_ANALYTICS))).toEqual( + expect(transform(TransformTable.fromRows(MULTIPLE_ANALYTICS))).toStrictEqual( TransformTable.fromRows([ { period: '20200101', organisationUnit: 'TO', dataElement: 'BCD1', value: 4 }, { period: '20200102', organisationUnit: 'TO', dataElement: 'BCD1', value: 2 }, @@ -124,7 +124,7 @@ describe('insertRows', () => { }, }, ]); - expect(transform(TransformTable.fromRows(MULTIPLE_ANALYTICS))).toEqual( + expect(transform(TransformTable.fromRows(MULTIPLE_ANALYTICS))).toStrictEqual( TransformTable.fromRows([ { period: '20200101', organisationUnit: 'TO', dataElement: 'BCD1', value: 4 }, { dataElementValue: 4 }, @@ -146,7 +146,7 @@ describe('insertRows', () => { position: 'before', }, ]); - expect(transform(TransformTable.fromRows(MULTIPLE_ANALYTICS))).toEqual( + expect(transform(TransformTable.fromRows(MULTIPLE_ANALYTICS))).toStrictEqual( TransformTable.fromRows( [ { dataElementValue: 4 }, @@ -171,7 +171,7 @@ describe('insertRows', () => { position: 'start', }, ]); - expect(transform(TransformTable.fromRows(MULTIPLE_ANALYTICS))).toEqual( + expect(transform(TransformTable.fromRows(MULTIPLE_ANALYTICS))).toStrictEqual( TransformTable.fromRows( [ { dataElementValue: 4 }, @@ -197,7 +197,7 @@ describe('insertRows', () => { where: "=not(eq($period, '20200101'))", }, ]); - expect(transform(TransformTable.fromRows(MULTIPLE_ANALYTICS))).toEqual( + expect(transform(TransformTable.fromRows(MULTIPLE_ANALYTICS))).toStrictEqual( TransformTable.fromRows([ { period: '20200101', organisationUnit: 'TO', dataElement: 'BCD1', value: 4 }, { period: '20200102', organisationUnit: 'TO', dataElement: 'BCD1', value: 2 }, @@ -219,7 +219,7 @@ describe('insertRows', () => { }, }, ]); - expect(transform(TransformTable.fromRows(MULTIPLE_ANALYTICS))).toEqual( + expect(transform(TransformTable.fromRows(MULTIPLE_ANALYTICS))).toStrictEqual( TransformTable.fromRows([ { period: '20200101', organisationUnit: 'TO', dataElement: 'BCD1', value: 4 }, { period: '20200102', organisationUnit: 'TO', dataElement: 'BCD1', value: 2 }, @@ -242,7 +242,7 @@ describe('insertRows', () => { }, }, ]); - expect(transform(TransformTable.fromRows(MERGEABLE_ANALYTICS))).toEqual( + expect(transform(TransformTable.fromRows(MERGEABLE_ANALYTICS))).toStrictEqual( TransformTable.fromRows([ { period: '20200101', organisationUnit: 'TO', BCD1: 4 }, { period: '20200102', organisationUnit: 'TO', BCD1: 2 }, diff --git a/packages/report-server/src/__tests__/reportBuilder/transform/mergeRows.test.ts b/packages/report-server/src/__tests__/reportBuilder/transform/mergeRows.test.ts index 8f390b4b77..407bc95249 100644 --- a/packages/report-server/src/__tests__/reportBuilder/transform/mergeRows.test.ts +++ b/packages/report-server/src/__tests__/reportBuilder/transform/mergeRows.test.ts @@ -30,7 +30,7 @@ describe('mergeRows', () => { groupBy: 'period', }, ]); - expect(transform(TransformTable.fromRows(SINGLE_MERGEABLE_ANALYTICS))).toEqual( + expect(transform(TransformTable.fromRows(SINGLE_MERGEABLE_ANALYTICS))).toStrictEqual( TransformTable.fromRows([{ period: '20200101', BCD1: 4, BCD2: 4, BCD3: 4 }]), ); }); @@ -40,15 +40,15 @@ describe('mergeRows', () => { { transform: 'mergeRows', using: { - organisationUnit: 'exclude', - period: 'exclude', + organisationUnit: 'first', + period: 'first', '*': 'sum', }, }, ]); - expect(transform(TransformTable.fromRows(MERGEABLE_ANALYTICS))).toEqual( + expect(transform(TransformTable.fromRows(MERGEABLE_ANALYTICS))).toStrictEqual( TransformTable.fromRows([ - { period: undefined, organisationUnit: undefined, BCD1: 28, BCD2: 123 }, + { period: '20200101', organisationUnit: 'TO', BCD1: 28, BCD2: 123 }, ]), ); }); @@ -61,7 +61,7 @@ describe('mergeRows', () => { using: 'last', }, ]); - expect(transform(TransformTable.fromRows(MERGEABLE_ANALYTICS))).toEqual( + expect(transform(TransformTable.fromRows(MERGEABLE_ANALYTICS))).toStrictEqual( TransformTable.fromRows([ { period: '20200103', organisationUnit: 'TO', BCD1: 5, BCD2: 0 }, { period: '20200103', organisationUnit: 'PG', BCD1: 2, BCD2: -1 }, @@ -77,7 +77,7 @@ describe('mergeRows', () => { using: 'sum', }, ]); - expect(transform(TransformTable.fromRows(MERGEABLE_ANALYTICS))).toEqual( + expect(transform(TransformTable.fromRows(MERGEABLE_ANALYTICS))).toStrictEqual( TransformTable.fromRows([ { period: '20200101', organisationUnit: 'TO', BCD1: 4, BCD2: 11 }, { period: '20200102', organisationUnit: 'TO', BCD1: 2, BCD2: 1 }, @@ -101,7 +101,7 @@ describe('mergeRows', () => { }, }, ]); - expect(transform(TransformTable.fromRows(MERGEABLE_ANALYTICS))).toEqual( + expect(transform(TransformTable.fromRows(MERGEABLE_ANALYTICS))).toStrictEqual( TransformTable.fromRows([ { period: '20200103', organisationUnit: 'TO', BCD1: 11, BCD2: 0 }, { period: '20200103', organisationUnit: 'PG', BCD1: 17, BCD2: -1 }, @@ -116,15 +116,15 @@ describe('mergeRows', () => { transform: 'mergeRows', groupBy: 'organisationUnit', using: { - period: 'exclude', + period: 'first', '*': 'sum', }, }, ]); - expect(transform(TransformTable.fromRows(MERGEABLE_ANALYTICS))).toEqual( + expect(transform(TransformTable.fromRows(MERGEABLE_ANALYTICS))).toStrictEqual( TransformTable.fromRows([ - { period: undefined, organisationUnit: 'TO', BCD1: 11, BCD2: 12 }, - { period: undefined, organisationUnit: 'PG', BCD1: 17, BCD2: 111 }, + { period: '20200101', organisationUnit: 'TO', BCD1: 11, BCD2: 12 }, + { period: '20200101', organisationUnit: 'PG', BCD1: 17, BCD2: 111 }, ]), ); }); @@ -135,7 +135,7 @@ describe('mergeRows', () => { transform: 'mergeRows', groupBy: 'organisationUnit', using: { - period: 'exclude', + period: 'first', '*': 'sum', }, }, @@ -147,10 +147,10 @@ describe('mergeRows', () => { ...MERGEABLE_ANALYTICS_WITH_NULL_VALUES, ]), ), - ).toEqual( + ).toStrictEqual( TransformTable.fromRows([ - { period: undefined, organisationUnit: 'TO', BCD1: 11, BCD2: 12 }, - { period: undefined, organisationUnit: 'PG', BCD1: 17, BCD2: 111 }, + { period: '20200101', organisationUnit: 'TO', BCD1: 11, BCD2: 12 }, + { period: '20200101', organisationUnit: 'PG', BCD1: 17, BCD2: 111 }, ]), ); }); @@ -161,15 +161,15 @@ describe('mergeRows', () => { transform: 'mergeRows', groupBy: 'organisationUnit', using: { - period: 'exclude', + period: 'first', '*': 'average', }, }, ]); - expect(transform(TransformTable.fromRows(MERGEABLE_ANALYTICS))).toEqual( + expect(transform(TransformTable.fromRows(MERGEABLE_ANALYTICS))).toStrictEqual( TransformTable.fromRows([ - { period: undefined, organisationUnit: 'TO', BCD1: 3.6666666666666665, BCD2: 4 }, - { period: undefined, organisationUnit: 'PG', BCD1: 5.666666666666667, BCD2: 37 }, + { period: '20200101', organisationUnit: 'TO', BCD1: 3.6666666666666665, BCD2: 4 }, + { period: '20200101', organisationUnit: 'PG', BCD1: 5.666666666666667, BCD2: 37 }, ]), ); }); @@ -182,7 +182,7 @@ describe('mergeRows', () => { using: 'count', }, ]); - expect(transform(TransformTable.fromRows(MERGEABLE_ANALYTICS))).toEqual( + expect(transform(TransformTable.fromRows(MERGEABLE_ANALYTICS))).toStrictEqual( TransformTable.fromRows([ { period: '20200101', organisationUnit: 4, BCD1: 2, BCD2: 2 }, { period: '20200102', organisationUnit: 4, BCD1: 2, BCD2: 2 }, @@ -199,7 +199,7 @@ describe('mergeRows', () => { using: 'max', }, ]); - expect(transform(TransformTable.fromRows(MERGEABLE_ANALYTICS))).toEqual( + expect(transform(TransformTable.fromRows(MERGEABLE_ANALYTICS))).toStrictEqual( TransformTable.fromRows([ { period: '20200103', organisationUnit: 'TO', BCD1: 5, BCD2: 11 }, { period: '20200103', organisationUnit: 'PG', BCD1: 8, BCD2: 99 }, @@ -215,7 +215,7 @@ describe('mergeRows', () => { using: 'min', }, ]); - expect(transform(TransformTable.fromRows(MERGEABLE_ANALYTICS))).toEqual( + expect(transform(TransformTable.fromRows(MERGEABLE_ANALYTICS))).toStrictEqual( TransformTable.fromRows([ { period: '20200101', organisationUnit: 'PG', BCD1: 4, BCD2: 11 }, { period: '20200102', organisationUnit: 'PG', BCD1: 2, BCD2: 1 }, @@ -239,7 +239,7 @@ describe('mergeRows', () => { ...MERGEABLE_ANALYTICS_WITH_NULL_VALUES, ]), ), - ).toEqual( + ).toStrictEqual( TransformTable.fromRows([ { period: '20200101', organisationUnit: 'PG', BCD1: null, BCD2: null }, { period: '20200102', organisationUnit: 'PG', BCD1: 2, BCD2: 1 }, @@ -256,7 +256,7 @@ describe('mergeRows', () => { using: 'unique', }, ]); - expect(transform(TransformTable.fromRows(UNIQUE_MERGEABLE_ANALYTICS))).toEqual( + expect(transform(TransformTable.fromRows(UNIQUE_MERGEABLE_ANALYTICS))).toStrictEqual( TransformTable.fromRows([ { period: 'NO_UNIQUE_VALUE', @@ -282,12 +282,11 @@ describe('mergeRows', () => { using: 'exclude', }, ]); - expect(transform(TransformTable.fromRows(MERGEABLE_ANALYTICS))).toEqual( - TransformTable.fromRows([ - { period: '20200101', organisationUnit: undefined, BCD1: undefined, BCD2: undefined }, - { period: '20200102', organisationUnit: undefined, BCD1: undefined, BCD2: undefined }, - { period: '20200103', organisationUnit: undefined, BCD1: undefined, BCD2: undefined }, - ]), + expect(transform(TransformTable.fromRows(MERGEABLE_ANALYTICS))).toStrictEqual( + TransformTable.fromRows( + [{ period: '20200101' }, { period: '20200102' }, { period: '20200103' }], + ['period', 'organisationUnit', 'BCD1', 'BCD2'], // excludes values, but keeps columns + ), ); }); @@ -299,7 +298,7 @@ describe('mergeRows', () => { using: 'first', }, ]); - expect(transform(TransformTable.fromRows(MERGEABLE_ANALYTICS))).toEqual( + expect(transform(TransformTable.fromRows(MERGEABLE_ANALYTICS))).toStrictEqual( TransformTable.fromRows([ { period: '20200101', organisationUnit: 'TO', BCD1: 4, BCD2: 11 }, { period: '20200101', organisationUnit: 'PG', BCD1: 7, BCD2: 13 }, @@ -315,7 +314,7 @@ describe('mergeRows', () => { using: 'last', }, ]); - expect(transform(TransformTable.fromRows(MERGEABLE_ANALYTICS))).toEqual( + expect(transform(TransformTable.fromRows(MERGEABLE_ANALYTICS))).toStrictEqual( TransformTable.fromRows([ { period: '20200101', organisationUnit: 'PG', BCD1: 7, BCD2: 13 }, { period: '20200102', organisationUnit: 'PG', BCD1: 8, BCD2: 99 }, @@ -344,7 +343,7 @@ describe('mergeRows', () => { using: 'single', }, ]); - expect(transform(TransformTable.fromRows(SINGLE_MERGEABLE_ANALYTICS))).toEqual( + expect(transform(TransformTable.fromRows(SINGLE_MERGEABLE_ANALYTICS))).toStrictEqual( TransformTable.fromRows([{ period: '20200101', BCD1: 4, BCD2: 4, BCD3: 4 }]), ); }); diff --git a/packages/report-server/src/__tests__/reportBuilder/transform/parser/parser.test.ts b/packages/report-server/src/__tests__/reportBuilder/transform/parser/parser.test.ts index e8de2a0d0a..3e7f9dfacc 100644 --- a/packages/report-server/src/__tests__/reportBuilder/transform/parser/parser.test.ts +++ b/packages/report-server/src/__tests__/reportBuilder/transform/parser/parser.test.ts @@ -30,80 +30,93 @@ describe('parser', () => { ], { query: { animal: 'cat' } }, ); - expect(transform(TransformTable.fromRows(PARSABLE_ANALYTICS))).toEqual( - TransformTable.fromRows([ - { - variable: 4, - current: 4, - index: 1, - previous: undefined, - next: 2, - lastAll: 2, - sumAllPrevious: 4, - sumWhereMatchingOrgUnit: 11, - tableLength: 6, - requestParam: 'cat', - }, - { - variable: 2, - current: 2, - index: 2, - previous: 4, - next: 5, - lastAll: 2, - sumAllPrevious: 6, - sumWhereMatchingOrgUnit: 11, - tableLength: 6, - requestParam: 'cat', - }, - { - variable: 5, - current: 5, - index: 3, - previous: 2, - next: 7, - lastAll: 2, - sumAllPrevious: 11, - sumWhereMatchingOrgUnit: 11, - tableLength: 6, - requestParam: 'cat', - }, - { - variable: 7, - current: 7, - index: 4, - previous: 5, - next: 8, - lastAll: 2, - sumAllPrevious: 18, - sumWhereMatchingOrgUnit: 17, - tableLength: 6, - requestParam: 'cat', - }, - { - variable: 8, - current: 8, - index: 5, - previous: 7, - next: 2, - lastAll: 2, - sumAllPrevious: 26, - sumWhereMatchingOrgUnit: 17, - tableLength: 6, - requestParam: 'cat', - }, - { - variable: 2, - current: 2, - index: 6, - previous: 8, - lastAll: 2, - sumAllPrevious: 28, - sumWhereMatchingOrgUnit: 17, - tableLength: 6, - requestParam: 'cat', - }, - ]), + expect(transform(TransformTable.fromRows(PARSABLE_ANALYTICS))).toStrictEqual( + TransformTable.fromRows( + [ + { + variable: 4, + current: 4, + index: 1, + next: 2, + lastAll: 2, + sumAllPrevious: 4, + sumWhereMatchingOrgUnit: 11, + tableLength: 6, + requestParam: 'cat', + }, + { + variable: 2, + current: 2, + index: 2, + previous: 4, + next: 5, + lastAll: 2, + sumAllPrevious: 6, + sumWhereMatchingOrgUnit: 11, + tableLength: 6, + requestParam: 'cat', + }, + { + variable: 5, + current: 5, + index: 3, + previous: 2, + next: 7, + lastAll: 2, + sumAllPrevious: 11, + sumWhereMatchingOrgUnit: 11, + tableLength: 6, + requestParam: 'cat', + }, + { + variable: 7, + current: 7, + index: 4, + previous: 5, + next: 8, + lastAll: 2, + sumAllPrevious: 18, + sumWhereMatchingOrgUnit: 17, + tableLength: 6, + requestParam: 'cat', + }, + { + variable: 8, + current: 8, + index: 5, + previous: 7, + next: 2, + lastAll: 2, + sumAllPrevious: 26, + sumWhereMatchingOrgUnit: 17, + tableLength: 6, + requestParam: 'cat', + }, + { + variable: 2, + current: 2, + index: 6, + previous: 8, + lastAll: 2, + sumAllPrevious: 28, + sumWhereMatchingOrgUnit: 17, + tableLength: 6, + requestParam: 'cat', + }, + ], + [ + 'variable', + 'current', + 'index', + 'previous', + 'next', + 'lastAll', + 'sumAllPrevious', + 'sumWhereMatchingOrgUnit', + 'tableLength', + 'requestParam', + ], + ), ); }); @@ -120,13 +133,16 @@ describe('parser', () => { where: "=eq($organisationUnit, 'TO')", }, ]); - expect(transform(TransformTable.fromRows(PARSABLE_ANALYTICS))).toEqual( - TransformTable.fromRows([ - { period: undefined, organisationUnit: undefined, BCD1: 11 }, - { period: '20200101', organisationUnit: 'PG', BCD1: 7 }, - { period: '20200102', organisationUnit: 'PG', BCD1: 8 }, - { period: '20200103', organisationUnit: 'PG', BCD1: 2 }, - ]), + expect(transform(TransformTable.fromRows(PARSABLE_ANALYTICS))).toStrictEqual( + TransformTable.fromRows( + [ + { BCD1: 11 }, + { period: '20200101', organisationUnit: 'PG', BCD1: 7 }, + { period: '20200102', organisationUnit: 'PG', BCD1: 8 }, + { period: '20200103', organisationUnit: 'PG', BCD1: 2 }, + ], + ['period', 'organisationUnit', 'BCD1'], + ), ); }); @@ -138,7 +154,7 @@ describe('parser', () => { '=$BCD1 <= mean(where(f(@otherRow) = eq($organisationUnit, @otherRow.organisationUnit)).BCD1)', }, ]); - expect(transform(TransformTable.fromRows(PARSABLE_ANALYTICS))).toEqual( + expect(transform(TransformTable.fromRows(PARSABLE_ANALYTICS))).toStrictEqual( TransformTable.fromRows([ { period: '20200101', organisationUnit: 'TO', BCD1: 4 }, { period: '20200103', organisationUnit: 'TO', BCD1: 5 }, @@ -158,7 +174,7 @@ describe('parser', () => { exclude: ['organisationUnit', 'BCD1'], }, ]); - expect(transform(TransformTable.fromRows(PARSABLE_ANALYTICS))).toEqual( + expect(transform(TransformTable.fromRows(PARSABLE_ANALYTICS))).toStrictEqual( TransformTable.fromRows([ { period: '20200101', TO: 4 }, { period: '20200102', TO: 2 }, @@ -177,7 +193,7 @@ describe('parser', () => { by: '=$BCD1', }, ]); - expect(transform(TransformTable.fromRows(PARSABLE_ANALYTICS))).toEqual( + expect(transform(TransformTable.fromRows(PARSABLE_ANALYTICS))).toStrictEqual( TransformTable.fromRows([ { period: '20200102', organisationUnit: 'TO', BCD1: 2 }, { period: '20200103', organisationUnit: 'PG', BCD1: 2 }, diff --git a/packages/report-server/src/__tests__/reportBuilder/transform/sortRows.test.ts b/packages/report-server/src/__tests__/reportBuilder/transform/sortRows.test.ts index d40e5c8269..53e5b7893e 100644 --- a/packages/report-server/src/__tests__/reportBuilder/transform/sortRows.test.ts +++ b/packages/report-server/src/__tests__/reportBuilder/transform/sortRows.test.ts @@ -25,7 +25,7 @@ describe('sortRows', () => { by: 'period', }, ]); - expect(transform(TransformTable.fromRows(SORTABLE_ANALYTICS))).toEqual( + expect(transform(TransformTable.fromRows(SORTABLE_ANALYTICS))).toStrictEqual( TransformTable.fromRows([ { period: '20200101', organisationUnit: 'TO', BCD1: 4 }, { period: '20200101', organisationUnit: 'TO', BCD1: 11 }, @@ -51,7 +51,7 @@ describe('sortRows', () => { direction: 'desc', }, ]); - expect(transform(TransformTable.fromRows(SORTABLE_ANALYTICS))).toEqual( + expect(transform(TransformTable.fromRows(SORTABLE_ANALYTICS))).toStrictEqual( TransformTable.fromRows([ { period: '20200103', organisationUnit: 'TO', BCD1: 5 }, { period: '20200103', organisationUnit: 'TO', BCD1: 0 }, @@ -76,7 +76,7 @@ describe('sortRows', () => { by: ['period', 'organisationUnit'], }, ]); - expect(transform(TransformTable.fromRows(SORTABLE_ANALYTICS))).toEqual( + expect(transform(TransformTable.fromRows(SORTABLE_ANALYTICS))).toStrictEqual( TransformTable.fromRows([ { period: '20200101', organisationUnit: 'PG', BCD1: 7 }, { period: '20200101', organisationUnit: 'PG', BCD1: 13 }, @@ -102,7 +102,7 @@ describe('sortRows', () => { direction: ['asc', 'desc'], }, ]); - expect(transform(TransformTable.fromRows(SORTABLE_ANALYTICS))).toEqual( + expect(transform(TransformTable.fromRows(SORTABLE_ANALYTICS))).toStrictEqual( TransformTable.fromRows([ { period: '20200101', organisationUnit: 'PG', BCD1: 13 }, { period: '20200101', organisationUnit: 'TO', BCD1: 11 }, @@ -127,7 +127,7 @@ describe('sortRows', () => { by: '=$BCD1 * $BCD1', }, ]); - expect(transform(TransformTable.fromRows(SORTABLE_ANALYTICS))).toEqual( + expect(transform(TransformTable.fromRows(SORTABLE_ANALYTICS))).toStrictEqual( TransformTable.fromRows([ { period: '20200103', organisationUnit: 'TO', BCD1: 0 }, { period: '20200102', organisationUnit: 'TO', BCD1: 1 }, diff --git a/packages/report-server/src/__tests__/reportBuilder/transform/transform.test.ts b/packages/report-server/src/__tests__/reportBuilder/transform/transform.test.ts index 083be5569e..3f52c3fa09 100644 --- a/packages/report-server/src/__tests__/reportBuilder/transform/transform.test.ts +++ b/packages/report-server/src/__tests__/reportBuilder/transform/transform.test.ts @@ -42,7 +42,7 @@ describe('transform', () => { exclude: '*', }, ]); - expect(transform(TransformTable.fromRows(MULTIPLE_ANALYTICS))).toEqual( + expect(transform(TransformTable.fromRows(MULTIPLE_ANALYTICS))).toStrictEqual( TransformTable.fromRows([{ Total: 11 }]), ); }); @@ -74,7 +74,7 @@ describe('transform', () => { exclude: '*', }, ]); - expect(transform(TransformTable.fromRows(MULTIPLE_ANALYTICS))).toEqual( + expect(transform(TransformTable.fromRows(MULTIPLE_ANALYTICS))).toStrictEqual( TransformTable.fromRows([{ Total: 11 }]), ); }); diff --git a/packages/report-server/src/__tests__/reportBuilder/transform/updateColumns.test.ts b/packages/report-server/src/__tests__/reportBuilder/transform/updateColumns.test.ts index ba2ece8b33..39dbe6cf0e 100644 --- a/packages/report-server/src/__tests__/reportBuilder/transform/updateColumns.test.ts +++ b/packages/report-server/src/__tests__/reportBuilder/transform/updateColumns.test.ts @@ -13,7 +13,7 @@ describe('updateColumns', () => { transform: 'updateColumns', }, ]); - expect(transform(TransformTable.fromRows(SINGLE_ANALYTIC))).toEqual( + expect(transform(TransformTable.fromRows(SINGLE_ANALYTIC))).toStrictEqual( TransformTable.fromRows([{ ...SINGLE_ANALYTIC[0] }]), ); }); @@ -29,7 +29,7 @@ describe('updateColumns', () => { }, }, ]); - expect(transform(TransformTable.fromRows(SINGLE_ANALYTIC))).toEqual( + expect(transform(TransformTable.fromRows(SINGLE_ANALYTIC))).toStrictEqual( TransformTable.fromRows([{ ...SINGLE_ANALYTIC[0], number: 1, string: 'Hi', boolean: false }]), ); }); @@ -43,7 +43,7 @@ describe('updateColumns', () => { }, }, ]); - expect(transform(TransformTable.fromRows(SINGLE_ANALYTIC))).toEqual( + expect(transform(TransformTable.fromRows(SINGLE_ANALYTIC))).toStrictEqual( TransformTable.fromRows([{ ...SINGLE_ANALYTIC[0], dataElementValue: 4 }]), ); }); @@ -57,7 +57,7 @@ describe('updateColumns', () => { }, }, ]); - expect(transform(TransformTable.fromRows(SINGLE_ANALYTIC))).toEqual( + expect(transform(TransformTable.fromRows(SINGLE_ANALYTIC))).toStrictEqual( TransformTable.fromRows([{ ...SINGLE_ANALYTIC[0], BCD1: 4 }]), ); }); @@ -71,7 +71,7 @@ describe('updateColumns', () => { }, }, ]); - expect(transform(TransformTable.fromRows(SINGLE_ANALYTIC))).toEqual( + expect(transform(TransformTable.fromRows(SINGLE_ANALYTIC))).toStrictEqual( TransformTable.fromRows([{ ...SINGLE_ANALYTIC[0], period: '1st Jan 2020' }]), ); }); @@ -86,7 +86,7 @@ describe('updateColumns', () => { include: '*', }, ]); - expect(transform(TransformTable.fromRows(SINGLE_ANALYTIC))).toEqual( + expect(transform(TransformTable.fromRows(SINGLE_ANALYTIC))).toStrictEqual( TransformTable.fromRows([ { period: '1st Jan 2020', organisationUnit: 'TO', dataElement: 'BCD1', value: 4 }, ]), @@ -103,7 +103,7 @@ describe('updateColumns', () => { include: ['organisationUnit', 'value'], }, ]); - expect(transform(TransformTable.fromRows(SINGLE_ANALYTIC))).toEqual( + expect(transform(TransformTable.fromRows(SINGLE_ANALYTIC))).toStrictEqual( TransformTable.fromRows([{ organisationUnit: 'TO', value: 4, period: '1st Jan 2020' }]), ); }); @@ -118,7 +118,7 @@ describe('updateColumns', () => { exclude: '*', }, ]); - expect(transform(TransformTable.fromRows(SINGLE_ANALYTIC))).toEqual( + expect(transform(TransformTable.fromRows(SINGLE_ANALYTIC))).toStrictEqual( TransformTable.fromRows([{ period: '1st Jan 2020' }]), ); }); @@ -133,7 +133,7 @@ describe('updateColumns', () => { exclude: ['organisationUnit', 'value'], }, ]); - expect(transform(TransformTable.fromRows(SINGLE_ANALYTIC))).toEqual( + expect(transform(TransformTable.fromRows(SINGLE_ANALYTIC))).toStrictEqual( TransformTable.fromRows([{ period: '1st Jan 2020', dataElement: 'BCD1' }]), ); }); @@ -149,7 +149,7 @@ describe('updateColumns', () => { include: ['organisationUnit'], }, ]); - expect(transform(TransformTable.fromRows(MULTIPLE_ANALYTICS))).toEqual( + expect(transform(TransformTable.fromRows(MULTIPLE_ANALYTICS))).toStrictEqual( TransformTable.fromRows([ { organisationUnit: 'TO', period: '1st Jan 2020', BCD1: 4 }, { organisationUnit: 'TO', period: '2nd Jan 2020', BCD1: 2 }, @@ -169,7 +169,7 @@ describe('updateColumns', () => { include: ['period', 'organisationUnit'], }, ]); - expect(transform(TransformTable.fromRows(MERGEABLE_ANALYTICS))).toEqual( + expect(transform(TransformTable.fromRows(MERGEABLE_ANALYTICS))).toStrictEqual( TransformTable.fromRows([ { period: '20200101', organisationUnit: 'TO', newVal: 8 }, { period: '20200102', organisationUnit: 'TO', newVal: 4 }, diff --git a/packages/report-server/src/reportBuilder/transform/functions/mergeRows/mergeRows.ts b/packages/report-server/src/reportBuilder/transform/functions/mergeRows/mergeRows.ts index b7f7addb51..1cde67feda 100644 --- a/packages/report-server/src/reportBuilder/transform/functions/mergeRows/mergeRows.ts +++ b/packages/report-server/src/reportBuilder/transform/functions/mergeRows/mergeRows.ts @@ -107,7 +107,9 @@ const mergeGroups = (groups: Group[], params: MergeRowsParams) => { Object.entries(group).forEach(([columnName, groupValues]) => { const mergeStrategy = params.getMergeStrategy(columnName); const mergedValue = mergeStrategies[mergeStrategy](groupValues); - mergedRow[columnName] = mergedValue; + if (mergedValue !== undefined) { + mergedRow[columnName] = mergedValue; + } }); return mergedRow; }); diff --git a/packages/report-server/src/reportBuilder/transform/table/TransformTable.ts b/packages/report-server/src/reportBuilder/transform/table/TransformTable.ts index 6ce3a93d79..829ef15a52 100644 --- a/packages/report-server/src/reportBuilder/transform/table/TransformTable.ts +++ b/packages/report-server/src/reportBuilder/transform/table/TransformTable.ts @@ -147,7 +147,12 @@ export class TransformTable { } values.forEach((value, index) => { - this.rows[index][columnName] = value; + if (isExistingColumn) { + delete this.rows[index][columnName]; + } + if (value !== undefined) { + this.rows[index][columnName] = value; + } }); }