Skip to content

Commit

Permalink
chore: updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MacQSL committed Dec 19, 2024
1 parent 06c1aab commit eb00d42
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ import { ApiGeneralError } from '../../../errors/api-error';
import { HTTP422CSVValidationError } from '../../../errors/http-error';
import { CSVConfigUtils } from '../../../utils/csv-utils/csv-config-utils';
import { validateCSVWorksheet } from '../../../utils/csv-utils/csv-config-validation';
import { CSVConfig, CSVHeaderConfig, CSVRowValidated } from '../../../utils/csv-utils/csv-config-validation.interface';
import {
CSVConfig,
CSVHeaderConfig,
CSVRowValidated,
CSV_ERROR_MESSAGE
} from '../../../utils/csv-utils/csv-config-validation.interface';
import { getDescriptionCellValidator, getTsnCellValidator } from '../../../utils/csv-utils/csv-header-configs';
import { getLogger } from '../../../utils/logger';
import { NestedRecord } from '../../../utils/nested-record';
Expand Down Expand Up @@ -94,7 +99,7 @@ export class ImportCrittersService extends DBService {
const { errors, rows } = validateCSVWorksheet(this.worksheet, config);

if (errors.length) {
throw new HTTP422CSVValidationError('Failed to validate Critter CSV', errors);
throw new HTTP422CSVValidationError(CSV_ERROR_MESSAGE, errors);

Check warning on line 102 in api/src/services/import-services/critter/import-critters-service.ts

View check run for this annotation

Codecov / codecov/patch

api/src/services/import-services/critter/import-critters-service.ts#L102

Added line #L102 was not covered by tests
}

const payloads = this._getImportPayloads(rows);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ describe('marking-header-configs', () => {
expect(result).to.deep.equal([]);
});

it('should allow undefined', () => {
const surveyAliasMap: any = new Map<string, string>([['alias', { captures: [{ capture_id: 'uuid' }] } as any]]);

const result = getMarkingAliasCellValidator(surveyAliasMap)({ cell: undefined } as CSVParams);

expect(result).to.deep.equal([]);
});

it('should update the mutateCell value to the critter_id', () => {
const surveyAliasMap = new Map([['alias', { critter_id: 'critter', captures: [{ capture_id: 'uuid' }] } as any]]);

Expand Down Expand Up @@ -88,6 +96,14 @@ describe('marking-header-configs', () => {
expect(result).to.deep.equal([]);
});

it('should allow undefined', () => {
const markingTypes = new Set<string>(['type']);

const result = getMarkingTypeCellValidator(markingTypes)({ cell: undefined } as CSVParams);

expect(result).to.deep.equal([]);
});

it('should return a single error if the value is not in the markingTypes set', () => {
const markingTypes = new Set<string>(['type']);

Expand Down Expand Up @@ -120,6 +136,14 @@ describe('marking-header-configs', () => {
expect(result).to.deep.equal([]);
});

it('should return no errors for undefined', () => {
const cellValidator = getMarkingBodyLocationCellValidator(new NestedRecord(), {} as any);

const result = cellValidator({ cell: undefined } as CSVParams);

expect(result).to.deep.equal([]);
});

it('should return a single error when alias has no body locations', () => {
const dictionary = new NestedRecord({ alias: { location: 'uuid' } });
const mockConfig: CSVConfig<'ALIAS'> = {
Expand Down Expand Up @@ -171,6 +195,14 @@ describe('marking-header-configs', () => {
expect(result).to.deep.equal([]);
});

it('should return no errors for undefined', () => {
const colours = new Set<string>(['colour']);

const result = getMarkingColourCellValidator(colours)({ cell: undefined } as CSVParams);

expect(result).to.deep.equal([]);
});

it('should return a single error if the value is not in the colours set', () => {
const colours = new Set<string>(['colour']);

Expand Down

0 comments on commit eb00d42

Please sign in to comment.