Skip to content

Commit

Permalink
Update tests to work in git actions
Browse files Browse the repository at this point in the history
  • Loading branch information
NickPhura committed Oct 30, 2024
1 parent 882b8fb commit 1777265
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
Expand All @@ -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
],
[
Expand All @@ -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
]
]);
Expand Down Expand Up @@ -143,8 +143,8 @@ describe('importMeasurementsStrategy', () => {
}
]
});
} catch (e: any) {
expect.fail();
} catch (error: any) {
expect.fail(error);
}
});
});
Expand Down Expand Up @@ -183,15 +183,15 @@ 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',
{
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
]
]);
Expand All @@ -205,15 +205,15 @@ 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',
{
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
]
]);
Expand All @@ -227,15 +227,15 @@ 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',
{
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
]
]);
Expand Down Expand Up @@ -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
]
]);
Expand Down Expand Up @@ -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, {});

Expand Down Expand Up @@ -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, {});

Expand Down Expand Up @@ -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, {});

Expand Down Expand Up @@ -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, {});

Expand Down Expand Up @@ -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, {});

Expand Down Expand Up @@ -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, {});

Expand All @@ -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, {});

Expand Down Expand Up @@ -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, {});

Expand Down
52 changes: 47 additions & 5 deletions api/src/services/import-services/utils/datetime.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
});
6 changes: 3 additions & 3 deletions api/src/utils/xlsx-utils/worksheet-utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,22 @@ 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 },
G2: { t: 's', v: 'more than 3 points' },
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 },
Expand Down

0 comments on commit 1777265

Please sign in to comment.