fix: testcases
This commit is contained in:
@ -13,7 +13,7 @@ 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()
|
||||
const stub = await stubImportCtx()
|
||||
stub.urlHandler = (ctx: ImportContext, url): Promise<void> => {
|
||||
urls.push(url)
|
||||
return Promise.resolve()
|
||||
@ -26,12 +26,14 @@ describe('Load a simple CSV file', () => {
|
||||
new URL('https://omnivore.app'),
|
||||
new URL('https://google.com'),
|
||||
])
|
||||
|
||||
await stub.redisClient.quit()
|
||||
})
|
||||
|
||||
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()
|
||||
const stub = await stubImportCtx()
|
||||
stub.urlHandler = (ctx: ImportContext, url): Promise<void> => {
|
||||
urls.push(url)
|
||||
return Promise.reject('Failed to import url')
|
||||
@ -40,6 +42,8 @@ describe('Load a simple CSV file', () => {
|
||||
await importCsv(stub, stream)
|
||||
expect(stub.countFailed).to.equal(2)
|
||||
expect(stub.countImported).to.equal(0)
|
||||
|
||||
await stub.redisClient.quit()
|
||||
})
|
||||
})
|
||||
|
||||
@ -51,7 +55,7 @@ describe('Load a complex CSV file', () => {
|
||||
labels?: string[]
|
||||
}[] = []
|
||||
const stream = fs.createReadStream('./test/csv/data/complex.csv')
|
||||
const stub = stubImportCtx()
|
||||
const stub = await stubImportCtx()
|
||||
stub.urlHandler = (
|
||||
ctx: ImportContext,
|
||||
url,
|
||||
@ -86,6 +90,8 @@ describe('Load a complex CSV file', () => {
|
||||
labels: ['test', 'development'],
|
||||
},
|
||||
])
|
||||
|
||||
await stub.redisClient.quit()
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@ -1,15 +1,15 @@
|
||||
import 'mocha'
|
||||
import { Readability } from '@omnivore/readability'
|
||||
import * as chai from 'chai'
|
||||
import { expect } from 'chai'
|
||||
import chaiString from 'chai-string'
|
||||
import * as fs from 'fs'
|
||||
import 'mocha'
|
||||
import { ImportContext } from '../../src'
|
||||
import {
|
||||
importMatterArchive,
|
||||
importMatterHistoryCsv,
|
||||
} from '../../src/matterHistory'
|
||||
import { stubImportCtx } from '../util'
|
||||
import { ImportContext } from '../../src'
|
||||
import { Readability } from '@omnivore/readability'
|
||||
|
||||
chai.use(chaiString)
|
||||
|
||||
@ -17,7 +17,7 @@ describe('Load a simple _matter_history file', () => {
|
||||
it('should find the URL of each row', async () => {
|
||||
const urls: URL[] = []
|
||||
const stream = fs.createReadStream('./test/matter/data/_matter_history.csv')
|
||||
const stub = stubImportCtx()
|
||||
const stub = await stubImportCtx()
|
||||
stub.urlHandler = (ctx: ImportContext, url): Promise<void> => {
|
||||
urls.push(url)
|
||||
return Promise.resolve()
|
||||
@ -29,6 +29,8 @@ describe('Load a simple _matter_history file', () => {
|
||||
expect(urls).to.eql([
|
||||
new URL('https://www.bloomberg.com/features/2022-the-crypto-story/'),
|
||||
])
|
||||
|
||||
await stub.redisClient.quit()
|
||||
})
|
||||
})
|
||||
|
||||
@ -36,7 +38,7 @@ describe('Load archive file', () => {
|
||||
it('should find the URL of each row', async () => {
|
||||
const urls: URL[] = []
|
||||
const stream = fs.createReadStream('./test/matter/data/Archive.zip')
|
||||
const stub = stubImportCtx()
|
||||
const stub = await stubImportCtx()
|
||||
stub.contentHandler = (
|
||||
ctx: ImportContext,
|
||||
url: URL,
|
||||
@ -54,5 +56,7 @@ describe('Load archive file', () => {
|
||||
expect(urls).to.eql([
|
||||
new URL('https://www.bloomberg.com/features/2022-the-crypto-story/'),
|
||||
])
|
||||
|
||||
await stub.redisClient.quit()
|
||||
})
|
||||
})
|
||||
|
||||
@ -1,7 +1,9 @@
|
||||
import { Readability } from '@omnivore/readability'
|
||||
import { ArticleSavingRequestStatus, ImportContext } from '../src'
|
||||
import { createRedisClient } from '../src/redis'
|
||||
|
||||
export const stubImportCtx = () => {
|
||||
export const stubImportCtx = async () => {
|
||||
const redisClient = await createRedisClient()
|
||||
return {
|
||||
userId: '',
|
||||
countImported: 0,
|
||||
@ -23,5 +25,7 @@ export const stubImportCtx = () => {
|
||||
): Promise<void> => {
|
||||
return Promise.resolve()
|
||||
},
|
||||
redisClient,
|
||||
taskId: '',
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user