Skip to content

Commit

Permalink
fix: sex now optional
Browse files Browse the repository at this point in the history
  • Loading branch information
MacQSL committed Dec 6, 2024
1 parent 99996e0 commit 6b52461
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ describe('critter-header-configs', () => {
new CSVConfigUtils(xlsx.utils.json_to_sheet([]), mockConfig)
);

const cellValues = ['male', 'MALE'];
const cellValues = ['male', 'MALE', undefined];

for (const cell of cellValues) {
const result = cellValidator({ cell: cell, row: { ITIS_TSN: 1 }, header: 'HEADER', rowIndex: 0 });
Expand All @@ -216,7 +216,7 @@ describe('critter-header-configs', () => {
new CSVConfigUtils(xlsx.utils.json_to_sheet([]), mockConfig)
);

const cellValues = [undefined, '', 0];
const cellValues = ['', 0];

for (const cell of cellValues) {
const result = cellValidator({ cell: cell, row: { ITIS_TSN: 1 }, header: 'HEADER', rowIndex: 0 });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export class ImportCrittersService extends DBService {
staticHeadersConfig: {
ITIS_TSN: { aliases: ['TAXON', 'SPECIES', 'TSN'] },
ALIAS: { aliases: ['NICKNAME', 'NAME', 'ANIMAL_ID'] },
SEX: { aliases: [] },
SEX: { aliases: [], optional: true },
WLH_ID: { aliases: ['WILDLIFE_HEALTH_ID', 'WILD LIFE HEALTH ID', 'WLHID'], optional: true },
DESCRIPTION: { aliases: ['COMMENTS', 'COMMENT', 'NOTES'], optional: true }
},
Expand Down
12 changes: 12 additions & 0 deletions api/src/utils/csv-utils/csv-config-validation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,18 @@ describe('csv-config-validation', () => {
]);
});

it('should NOT return an error if the worksheet is missing a optional header', () => {
const mockConfig: CSVConfig = {
staticHeadersConfig: { ALIAS: { aliases: [], optional: true } },
ignoreDynamicHeaders: true
};
const worksheet: WorkSheet = xlsx.utils.json_to_sheet([{ NOT_ALIAS: 'value' }]);

const result = validateCSVHeaders(worksheet, mockConfig);

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

it('should return an error if the worksheet has an unknown header and dynamic headers are not ignored', () => {
const mockConfig: CSVConfig = { staticHeadersConfig: { ALIAS: { aliases: [] } }, ignoreDynamicHeaders: false };
const worksheet: WorkSheet = xlsx.utils.json_to_sheet([{ ALIAS: 'alias', UNKNOWN_HEADER: 'value' }]);
Expand Down

0 comments on commit 6b52461

Please sign in to comment.