mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
fix: testcases
This commit is contained in:
parent
345c56c57a
commit
8a89a47c16
6 changed files with 39 additions and 14 deletions
9
.github/workflows/run-tests.yaml
vendored
9
.github/workflows/run-tests.yaml
vendored
|
|
@ -42,6 +42,15 @@ jobs:
|
|||
--health-retries 10
|
||||
ports:
|
||||
- 9200
|
||||
redis:
|
||||
image: redis
|
||||
options: >-
|
||||
--health-cmd "redis-cli ping"
|
||||
--health-interval 10s
|
||||
--health-timeout 5s
|
||||
--health-retries 10
|
||||
ports:
|
||||
- 6379
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
|
|
|
|||
|
|
@ -40,7 +40,6 @@ const CONTENT_TYPES = ['text/csv', 'application/zip']
|
|||
export type UrlHandler = (
|
||||
ctx: ImportContext,
|
||||
url: URL,
|
||||
taskId: string,
|
||||
state?: ArticleSavingRequestStatus,
|
||||
labels?: string[]
|
||||
) => Promise<void>
|
||||
|
|
@ -175,7 +174,6 @@ const handlerForFile = (name: string): importHandlerFunc | undefined => {
|
|||
const urlHandler = async (
|
||||
ctx: ImportContext,
|
||||
url: URL,
|
||||
taskId: string,
|
||||
state?: ArticleSavingRequestStatus,
|
||||
labels?: string[]
|
||||
): Promise<void> => {
|
||||
|
|
@ -185,7 +183,7 @@ const urlHandler = async (
|
|||
ctx.userId,
|
||||
url,
|
||||
'csv-importer',
|
||||
taskId,
|
||||
ctx.taskId,
|
||||
state,
|
||||
labels && labels.length > 0 ? labels : undefined
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,9 +1,13 @@
|
|||
import fs from 'fs'
|
||||
import { readFileSync } from 'fs'
|
||||
import path from 'path'
|
||||
import { createClient } from 'redis'
|
||||
|
||||
// load lua script
|
||||
export const lua = {
|
||||
script: fs.readFileSync('./luaScripts/updateMetrics.lua', 'utf8'),
|
||||
script: readFileSync(
|
||||
path.resolve(__dirname, 'luaScripts/updateMetrics.lua'),
|
||||
'utf8'
|
||||
),
|
||||
sha: '',
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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: '',
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue