mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
Handle empty state columns in the import CSV files
This commit is contained in:
parent
bf8b0c0034
commit
f1f83a6891
2 changed files with 22 additions and 1 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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<void> => {
|
||||
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])
|
||||
})
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in a new issue