From 17772651dc32c3e25f974f7c48f3df142a814647 Mon Sep 17 00:00:00 2001 From: Nick Phura Date: Tue, 29 Oct 2024 17:44:22 -0700 Subject: [PATCH] Update tests to work in git actions --- .../capture/import-captures-strategy.test.ts | 6 +-- .../marking/import-markings-strategy.test.ts | 6 +-- .../import-measurements-strategy.test.ts | 42 +++++++-------- .../import-services/utils/datetime.test.ts | 52 +++++++++++++++++-- .../utils/xlsx-utils/worksheet-utils.test.ts | 6 +-- 5 files changed, 77 insertions(+), 35 deletions(-) diff --git a/api/src/services/import-services/capture/import-captures-strategy.test.ts b/api/src/services/import-services/capture/import-captures-strategy.test.ts index c5687cac27..ec5d8059f3 100644 --- a/api/src/services/import-services/capture/import-captures-strategy.test.ts +++ b/api/src/services/import-services/capture/import-captures-strategy.test.ts @@ -22,18 +22,18 @@ describe('import-captures-service', () => { I1: { t: 's', v: 'RELEASE_LONGITUDE' }, J1: { t: 's', v: 'RELEASE_COMMENT' }, K1: { t: 's', v: 'CAPTURE_COMMENT' }, - A2: { z: 'dd/mm/yyyy', t: 'd', v: new Date('2024-10-11T00:00:00'), w: '11/10/2024' }, + A2: { t: 's', v: '2024-10-11' }, B2: { t: 's', v: 'Carl' }, C2: { t: 's', v: '10:10:10' }, D2: { t: 'n', w: '90', v: 90 }, E2: { t: 'n', w: '100', v: 100 }, - F2: { t: 's', v: '2024-10-11' }, + F2: { t: 's', v: '2024-10-10' }, G2: { t: 's', v: '9:09' }, H2: { t: 'n', w: '90', v: 90 }, I2: { t: 'n', w: '90', v: 90 }, J2: { t: 's', v: 'release' }, K2: { t: 's', v: 'capture' }, - A3: { z: 'yyyy-mm-dd', t: 'd', v: new Date('2024-10-11T07:00:00.000Z'), w: '2024-10-11' }, + A3: { z: 'yyyy-mm-dd', t: 'd', v: new Date('2024-10-10T07:00:00.000Z'), w: '2024-10-10' }, B3: { t: 's', v: 'Carlita' }, D3: { t: 'n', w: '90', v: 90 }, E3: { t: 'n', w: '100', v: 100 }, diff --git a/api/src/services/import-services/marking/import-markings-strategy.test.ts b/api/src/services/import-services/marking/import-markings-strategy.test.ts index 4cfc6e192a..074cc472f2 100644 --- a/api/src/services/import-services/marking/import-markings-strategy.test.ts +++ b/api/src/services/import-services/marking/import-markings-strategy.test.ts @@ -24,7 +24,7 @@ describe('ImportMarkingsStrategy', () => { G1: { t: 's', v: 'PRIMARY_COLOUR' }, H1: { t: 's', v: 'SECONDARY_COLOUR' }, I1: { t: 's', v: 'DESCRIPTION' }, // testing alias works - A2: { z: 'm/d/yy', t: 'd', v: '2024-10-10T07:00:00.000Z', w: '10/10/24' }, + A2: { z: 'yyyy-mm-dd', t: 'd', v: new Date('2024-10-10T07:00:00.000Z'), w: '2024-10-10' }, B2: { t: 's', v: 'Carl' }, C2: { t: 's', v: '10:10:12' }, D2: { t: 's', v: 'Left ear' }, // testing case insensitivity @@ -100,8 +100,8 @@ describe('ImportMarkingsStrategy', () => { try { const data = await importCSV(new MediaFile('test', 'test', 'test' as unknown as Buffer), strategy); expect(data).to.deep.equal(2); - } catch (err: any) { - expect.fail(); + } catch (error: any) { + expect.fail(error); } }); }); diff --git a/api/src/services/import-services/measurement/import-measurements-strategy.test.ts b/api/src/services/import-services/measurement/import-measurements-strategy.test.ts index 9503e0569c..c60c76e989 100644 --- a/api/src/services/import-services/measurement/import-measurements-strategy.test.ts +++ b/api/src/services/import-services/measurement/import-measurements-strategy.test.ts @@ -26,12 +26,12 @@ describe('importMeasurementsStrategy', () => { E1: { t: 's', v: 'skull condition' }, F1: { t: 's', v: 'unknown' }, A2: { t: 's', v: 'carl' }, - B2: { z: 'm/d/yy', t: 'd', v: '2024-10-10T07:00:00.000Z', w: '10/10/24' }, + B2: { t: 's', v: '2024-10-10' }, C2: { t: 's', v: '10:10:12' }, D2: { t: 'n', w: '2', v: 2 }, E2: { t: 'n', w: '0', v: 'good' }, A3: { t: 's', v: 'carlita' }, - B3: { z: 'm/d/yy', t: 'd', v: '2024-10-10T07:00:00.000Z', w: '10/10/24' }, + B3: { z: 'yyyy-mm-dd', t: 'd', v: new Date('2024-10-10T07:00:00.000Z'), w: '2024-10-10' }, C3: { t: 's', v: '10:10:12' }, D3: { t: 'n', w: '2', v: 2 }, E3: { t: 'n', w: '0', v: 'good' }, @@ -54,7 +54,7 @@ describe('importMeasurementsStrategy', () => { critter_id: 'A', animal_id: 'carl', itis_tsn: 'tsn1', - captures: [{ capture_id: 'B', capture_date: '10/10/2024', capture_time: '10:10:12' }] + captures: [{ capture_id: 'B', capture_date: '2024-10-10', capture_time: '10:10:12' }] } as any ], [ @@ -63,7 +63,7 @@ describe('importMeasurementsStrategy', () => { critter_id: 'B', animal_id: 'carlita', itis_tsn: 'tsn2', - captures: [{ capture_id: 'B', capture_date: '10/10/2024', capture_time: '10:10:12' }] + captures: [{ capture_id: 'B', capture_date: '2024-10-10', capture_time: '10:10:12' }] } as any ] ]); @@ -143,8 +143,8 @@ describe('importMeasurementsStrategy', () => { } ] }); - } catch (e: any) { - expect.fail(); + } catch (error: any) { + expect.fail(error); } }); }); @@ -183,7 +183,7 @@ describe('importMeasurementsStrategy', () => { const conn = getMockDBConnection(); const strategy = new ImportMeasurementsStrategy(conn, 1); - const row = { ALIAS: 'alias', CAPTURE_DATE: '10/10/2024', CAPTURE_TIME: '10:10:10' }; + const row = { ALIAS: 'alias', CAPTURE_DATE: '2024-10-10', CAPTURE_TIME: '10:10:10' }; const critterAliasMap = new Map([ [ 'alias', @@ -191,7 +191,7 @@ describe('importMeasurementsStrategy', () => { critter_id: 'A', animal_id: 'alias', itis_tsn: 'tsn1', - captures: [{ capture_id: 'B', capture_date: '10/10/2024', capture_time: '10:10:10' }] + captures: [{ capture_id: 'B', capture_date: '2024-10-10', capture_time: '10:10:10' }] } as any ] ]); @@ -205,7 +205,7 @@ describe('importMeasurementsStrategy', () => { const conn = getMockDBConnection(); const strategy = new ImportMeasurementsStrategy(conn, 1); - const row = { ALIAS: 'alias', CAPTURE_DATE: '10/10/2024', CAPTURE_TIME: '10:10:10' }; + const row = { ALIAS: 'alias', CAPTURE_DATE: '2024-10-10', CAPTURE_TIME: '10:10:10' }; const critterAliasMap = new Map([ [ 'alias2', @@ -213,7 +213,7 @@ describe('importMeasurementsStrategy', () => { critter_id: 'A', animal_id: 'alias2', itis_tsn: 'tsn1', - captures: [{ capture_id: 'B', capture_date: '10/10/2024', capture_time: '10:10:10' }] + captures: [{ capture_id: 'B', capture_date: '2024-10-10', capture_time: '10:10:10' }] } as any ] ]); @@ -227,7 +227,7 @@ describe('importMeasurementsStrategy', () => { const conn = getMockDBConnection(); const strategy = new ImportMeasurementsStrategy(conn, 1); - const row = { ALIAS: 'alias', CAPTURE_DATE: '10/10/2024', CAPTURE_TIME: '10:10:10' }; + const row = { ALIAS: 'alias', CAPTURE_DATE: '2024-10-10', CAPTURE_TIME: '10:10:10' }; const critterAliasMap = new Map([ [ 'alias', @@ -235,7 +235,7 @@ describe('importMeasurementsStrategy', () => { critter_id: 'A', animal_id: 'alias', itis_tsn: 'tsn1', - captures: [{ capture_id: 'B', capture_date: '11/11/2024', capture_time: '10:10:10' }] + captures: [{ capture_id: 'B', capture_date: '2024-11-11', capture_time: '10:10:10' }] } as any ] ]); @@ -344,7 +344,7 @@ describe('importMeasurementsStrategy', () => { critter_id: 'A', animal_id: 'alias', itis_tsn: 'tsn1', - captures: [{ capture_id: 'B', capture_date: '10/10/2024', capture_time: '10:10:10' }] + captures: [{ capture_id: 'B', capture_date: '2024-10-10', capture_time: '10:10:10' }] } as any ] ]); @@ -372,7 +372,7 @@ describe('importMeasurementsStrategy', () => { ); validateQualitativeMeasurementCellStub.returns({ error: undefined, optionId: 'C' }); - const rows = [{ ALIAS: 'alias', CAPTURE_DATE: '10/10/2024', CAPTURE_TIME: '10:10:10', measurement: 'length' }]; + const rows = [{ ALIAS: 'alias', CAPTURE_DATE: '2024-10-10', CAPTURE_TIME: '10:10:10', measurement: 'length' }]; const result = await strategy.validateRows(rows, {}); @@ -408,7 +408,7 @@ describe('importMeasurementsStrategy', () => { ); validateQualitativeMeasurementCellStub.returns({ error: undefined, optionId: 'C' }); - const rows = [{ ALIAS: 'alias', CAPTURE_DATE: '10/10/2024', CAPTURE_TIME: '10:10:10', measurement: 'length' }]; + const rows = [{ ALIAS: 'alias', CAPTURE_DATE: '2024-10-10', CAPTURE_TIME: '10:10:10', measurement: 'length' }]; const result = await strategy.validateRows(rows, {}); @@ -444,7 +444,7 @@ describe('importMeasurementsStrategy', () => { ); validateQualitativeMeasurementCellStub.returns({ error: undefined, optionId: 'C' }); - const rows = [{ ALIAS: 'alias', CAPTURE_DATE: '10/10/2024', CAPTURE_TIME: '10:10:10', measurement: 'length' }]; + const rows = [{ ALIAS: 'alias', CAPTURE_DATE: '2024-10-10', CAPTURE_TIME: '10:10:10', measurement: 'length' }]; const result = await strategy.validateRows(rows, {}); @@ -480,7 +480,7 @@ describe('importMeasurementsStrategy', () => { ); validateQualitativeMeasurementCellStub.returns({ error: undefined, optionId: 'C' }); - const rows = [{ ALIAS: 'alias', CAPTURE_DATE: '10/10/2024', CAPTURE_TIME: '10:10:10', measurement: 'length' }]; + const rows = [{ ALIAS: 'alias', CAPTURE_DATE: '2024-10-10', CAPTURE_TIME: '10:10:10', measurement: 'length' }]; const result = await strategy.validateRows(rows, {}); @@ -514,7 +514,7 @@ describe('importMeasurementsStrategy', () => { ); validateQualitativeMeasurementCellStub.returns({ error: 'qualitative failed', optionId: undefined }); - const rows = [{ ALIAS: 'alias', CAPTURE_DATE: '10/10/2024', CAPTURE_TIME: '10:10:10', measurement: 'length' }]; + const rows = [{ ALIAS: 'alias', CAPTURE_DATE: '2024-10-10', CAPTURE_TIME: '10:10:10', measurement: 'length' }]; const result = await strategy.validateRows(rows, {}); @@ -548,7 +548,7 @@ describe('importMeasurementsStrategy', () => { ); validateQuantitativeMeasurementCellStub.returns({ error: 'quantitative failed', value: undefined }); - const rows = [{ ALIAS: 'alias', CAPTURE_DATE: '10/10/2024', CAPTURE_TIME: '10:10:10', measurement: 'length' }]; + const rows = [{ ALIAS: 'alias', CAPTURE_DATE: '2024-10-10', CAPTURE_TIME: '10:10:10', measurement: 'length' }]; const result = await strategy.validateRows(rows, {}); @@ -573,7 +573,7 @@ describe('importMeasurementsStrategy', () => { getRowMetaStub.returns({ critter_id: 'A', tsn: 'tsn1', capture_id: 'C' }); getTsnMeasurementMapStub.resolves(new Map([['tsn1', { quantitative: [], qualitative: [] } as any]])); - const rows = [{ ALIAS: 'alias', CAPTURE_DATE: '10/10/2024', CAPTURE_TIME: '10:10:10', measurement: 'length' }]; + const rows = [{ ALIAS: 'alias', CAPTURE_DATE: '2024-10-10', CAPTURE_TIME: '10:10:10', measurement: 'length' }]; const result = await strategy.validateRows(rows, {}); @@ -607,7 +607,7 @@ describe('importMeasurementsStrategy', () => { ]) ); - const rows = [{ ALIAS: 'alias', CAPTURE_DATE: '10/10/2024', CAPTURE_TIME: '10:10:10', measurement: 'length' }]; + const rows = [{ ALIAS: 'alias', CAPTURE_DATE: '2024-10-10', CAPTURE_TIME: '10:10:10', measurement: 'length' }]; const result = await strategy.validateRows(rows, {}); diff --git a/api/src/services/import-services/utils/datetime.test.ts b/api/src/services/import-services/utils/datetime.test.ts index 24e0452a13..71eb5ac1c6 100644 --- a/api/src/services/import-services/utils/datetime.test.ts +++ b/api/src/services/import-services/utils/datetime.test.ts @@ -25,14 +25,56 @@ describe('formatTimeString', () => { }); describe('areDatesEqual', () => { + const date1 = '2024-10-11'; + const date2 = '24-10-11'; + const date3 = '11-10-2024'; + const date4 = '11-10-24'; + + const date5 = '2024/10/11'; + const date6 = '11/10/2024'; + const date7 = '24/10/11'; + const date8 = '11/10/24'; + it('should be true when dates are equal in all formats', () => { - expect(areDatesEqual('10-10-2024', '10-10-2024')).to.be.true; - expect(areDatesEqual('10-10-2024', '10/10/2024')).to.be.true; - expect(areDatesEqual('10-10-2024', '10/10/24')).to.be.true; - expect(areDatesEqual('10-10-2024', '2024-10-10')).to.be.true; + expect(areDatesEqual(date1, date5)).to.be.true; + + expect(areDatesEqual(date3, date4)).to.be.true; + expect(areDatesEqual(date3, date6)).to.be.true; + expect(areDatesEqual(date3, date8)).to.be.true; + + expect(areDatesEqual(date4, date6)).to.be.true; + expect(areDatesEqual(date4, date8)).to.be.true; + + expect(areDatesEqual(date6, date8)).to.be.true; }); it('should fail if dates are incorrect format', () => { - expect(areDatesEqual('BAD DATE BAD', '10/10/2024')).to.be.false; + expect(areDatesEqual(date1, date2)).to.be.false; + expect(areDatesEqual(date1, date3)).to.be.false; + expect(areDatesEqual(date1, date4)).to.be.false; + expect(areDatesEqual(date1, date6)).to.be.false; + expect(areDatesEqual(date1, date7)).to.be.false; + expect(areDatesEqual(date1, date8)).to.be.false; + expect(areDatesEqual(date2, date3)).to.be.false; + + expect(areDatesEqual(date2, date4)).to.be.false; + expect(areDatesEqual(date2, date5)).to.be.false; + expect(areDatesEqual(date2, date6)).to.be.false; + expect(areDatesEqual(date2, date7)).to.be.false; + expect(areDatesEqual(date2, date8)).to.be.false; + + expect(areDatesEqual(date3, date5)).to.be.false; + expect(areDatesEqual(date3, date7)).to.be.false; + + expect(areDatesEqual(date4, date5)).to.be.false; + expect(areDatesEqual(date4, date7)).to.be.false; + + expect(areDatesEqual(date5, date6)).to.be.false; + expect(areDatesEqual(date5, date7)).to.be.false; + expect(areDatesEqual(date5, date8)).to.be.false; + + expect(areDatesEqual(date6, date7)).to.be.false; + + expect(areDatesEqual(date7, date8)).to.be.false; }); }); diff --git a/api/src/utils/xlsx-utils/worksheet-utils.test.ts b/api/src/utils/xlsx-utils/worksheet-utils.test.ts index 067e1c9063..45517f713e 100644 --- a/api/src/utils/xlsx-utils/worksheet-utils.test.ts +++ b/api/src/utils/xlsx-utils/worksheet-utils.test.ts @@ -16,7 +16,7 @@ const xlsxWorksheet: xlsx.WorkSheet = { H1: { t: 's', v: 'Wind Direction' }, A2: { t: 'n', w: '180703', v: 180703 }, B2: { t: 'n', w: '1', v: 1 }, - C2: { z: 'm/d/yy', t: 'd', v: '1970-01-01T08:00:00.000Z', w: '1/1/70' }, + C2: { t: 's', v: '1970-01-01T08:00:00.000Z' }, D2: { t: 's', v: '9:01' }, E2: { t: 'n', w: '-58', v: -58 }, F2: { t: 'n', w: '-123', v: -123 }, @@ -24,14 +24,14 @@ const xlsxWorksheet: xlsx.WorkSheet = { H2: { t: 's', v: 'North' }, A3: { t: 'n', w: '180596', v: 180596 }, B3: { t: 'n', w: '2', v: 2 }, - C3: { z: 'm/d/yy', t: 'd', v: '1970-01-01T08:00:00.000Z', w: '1/1/70' }, + C3: { t: 's', v: '1970-01-01T08:00:00.000Z' }, D3: { t: 's', v: '9:02' }, E3: { t: 'n', w: '-57', v: -57 }, F3: { t: 'n', w: '-122', v: -122 }, H3: { t: 's', v: 'North' }, A4: { t: 'n', w: '180713', v: 180713 }, B4: { t: 'n', w: '3', v: 3 }, - C4: { z: 'm/d/yy', t: 'd', v: '1970-01-01T08:00:00.000Z', w: '1/1/70' }, + C4: { t: 's', v: '1970-01-01T08:00:00.000Z' }, D4: { t: 's', v: '9:03' }, E4: { t: 'n', w: '-56', v: -56 }, F4: { t: 'n', w: '-121', v: -121 },