diff --git a/packages/import-handler/src/csv.ts b/packages/import-handler/src/csv.ts index c73c0dd59..140cf00f0 100644 --- a/packages/import-handler/src/csv.ts +++ b/packages/import-handler/src/csv.ts @@ -13,7 +13,7 @@ export const importCsv = async (ctx: ImportContext, stream: Stream) => { for await (const row of parser) { try { const url = new URL(row[0]) - const state = row.length > 1 ? row[1] : undefined + const state = row.length > 1 && row[1] ? row[1] : undefined // labels follows format: "[label1,label2]" const labels = row.length > 2 diff --git a/packages/import-handler/test/csv/csv.test.ts b/packages/import-handler/test/csv/csv.test.ts index 0a8ea2e25..4d8e454c1 100644 --- a/packages/import-handler/test/csv/csv.test.ts +++ b/packages/import-handler/test/csv/csv.test.ts @@ -88,3 +88,24 @@ describe('Load a complex CSV file', () => { ]) }) }) + +describe('A file with no status set', () => { + it('should not try to set status', async () => { + const states: (ArticleSavingRequestStatus | undefined)[] = [] + const stream = fs.createReadStream('./test/csv/data/unset-status.csv') + const stub = stubImportCtx() + stub.urlHandler = ( + ctx: ImportContext, + url, + state?: ArticleSavingRequestStatus + ): Promise => { + states.push(state) + return Promise.resolve() + } + + await importCsv(stub, stream) + expect(stub.countFailed).to.equal(0) + expect(stub.countImported).to.equal(2) + expect(states).to.eql([undefined, ArticleSavingRequestStatus.Archived]) + }) +})