diff --git a/api/src/services/import-services/critter/critter-header-configs.test.ts b/api/src/services/import-services/critter/critter-header-configs.test.ts index c58549befe..d965a70a2f 100644 --- a/api/src/services/import-services/critter/critter-header-configs.test.ts +++ b/api/src/services/import-services/critter/critter-header-configs.test.ts @@ -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 }); @@ -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 }); diff --git a/api/src/services/import-services/critter/import-critters-services.test.ts b/api/src/services/import-services/critter/import-critters-service.test.ts similarity index 100% rename from api/src/services/import-services/critter/import-critters-services.test.ts rename to api/src/services/import-services/critter/import-critters-service.test.ts diff --git a/api/src/services/import-services/critter/import-critters-service.ts b/api/src/services/import-services/critter/import-critters-service.ts index 8a054d0b87..c714f56530 100644 --- a/api/src/services/import-services/critter/import-critters-service.ts +++ b/api/src/services/import-services/critter/import-critters-service.ts @@ -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 } }, diff --git a/api/src/utils/csv-utils/csv-config-validation.test.ts b/api/src/utils/csv-utils/csv-config-validation.test.ts index 3e77d7c112..71b63aae1e 100644 --- a/api/src/utils/csv-utils/csv-config-validation.test.ts +++ b/api/src/utils/csv-utils/csv-config-validation.test.ts @@ -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' }]);