Add test case for failures
This commit is contained in:
@ -17,7 +17,7 @@ export const importCsv = async (ctx: ImportContext, stream: Stream) => {
|
||||
// labels follows format: "[label1, label2]"
|
||||
const labels = row.length > 2 ? row[2].slice(1, -1).split(',') : undefined
|
||||
await ctx.urlHandler(ctx, url, state, labels)
|
||||
ctx.countImported++
|
||||
ctx.countImported += 1
|
||||
} catch (error) {
|
||||
console.log('invalid url', row, error)
|
||||
ctx.countFailed += 1
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
import 'mocha'
|
||||
import * as chai from 'chai'
|
||||
import { expect } from 'chai'
|
||||
import chaiString from 'chai-string'
|
||||
import * as fs from 'fs'
|
||||
import { importCsv } from '../../src/csv'
|
||||
import 'mocha'
|
||||
import { ArticleSavingRequestStatus, ImportContext } from '../../src'
|
||||
import { importCsv } from '../../src/csv'
|
||||
import { stubImportCtx } from '../util'
|
||||
|
||||
chai.use(chaiString)
|
||||
@ -27,6 +27,20 @@ describe('Load a simple CSV file', () => {
|
||||
new URL('https://google.com'),
|
||||
])
|
||||
})
|
||||
|
||||
it('increments the failed count when the URL is invalid', async () => {
|
||||
const urls: URL[] = []
|
||||
const stream = fs.createReadStream('./test/csv/data/simple.csv')
|
||||
const stub = stubImportCtx()
|
||||
stub.urlHandler = (ctx: ImportContext, url): Promise<void> => {
|
||||
urls.push(url)
|
||||
return Promise.reject('Failed to import url')
|
||||
}
|
||||
|
||||
await importCsv(stub, stream)
|
||||
expect(stub.countFailed).to.equal(2)
|
||||
expect(stub.countImported).to.equal(0)
|
||||
})
|
||||
})
|
||||
|
||||
describe('Load a complex CSV file', () => {
|
||||
|
||||
Reference in New Issue
Block a user