omnivore/packages/import-handler/test/csv/csv.test.ts

31 lines
876 B
TypeScript
Raw Normal View History

2022-02-11 17:24:33 +00:00
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 { ImportContext } from '../../src'
import { stubImportCtx } from '../util'
2022-02-11 17:24:33 +00:00
chai.use(chaiString)
describe('Load a simple CSV file', () => {
it('should call the handler for each URL', async () => {
const urls: URL[] = []
const stream = fs.createReadStream('./test/csv/data/simple.csv')
const stub = stubImportCtx()
stub.urlHandler = (ctx: ImportContext, url): Promise<void> => {
2022-02-11 17:24:33 +00:00
urls.push(url)
return Promise.resolve()
}
2023-01-11 14:55:04 +00:00
await importCsv(stub, stream)
expect(stub.countFailed).to.equal(0)
expect(stub.countImported).to.equal(2)
2022-02-11 17:24:33 +00:00
expect(urls).to.eql([
new URL('https://omnivore.app'),
new URL('https://google.com'),
])
})
})