fix mock cloud storage
This commit is contained in:
1
.github/workflows/run-tests.yaml
vendored
1
.github/workflows/run-tests.yaml
vendored
@ -96,7 +96,6 @@ jobs:
|
||||
PG_LOGGER: debug
|
||||
REDIS_URL: redis://localhost:${{ job.services.redis.ports[6379] }}
|
||||
MQ_REDIS_URL: redis://localhost:${{ job.services.redis.ports[6379] }}
|
||||
GCS_UPLOAD_BUCKET: omnivore-demo-files
|
||||
build-docker-images:
|
||||
name: Build docker images
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
@ -8,7 +8,7 @@
|
||||
],
|
||||
"license": "AGPL-3.0-only",
|
||||
"scripts": {
|
||||
"test": "lerna run test",
|
||||
"test": "lerna run --stream test",
|
||||
"lint": "lerna run lint",
|
||||
"build": "lerna run build",
|
||||
"test:scoped:example": "lerna run test --scope={@omnivore/pdf-handler,@omnivore/web}",
|
||||
|
||||
@ -1,15 +1,10 @@
|
||||
{
|
||||
"extends": "@istanbuljs/nyc-config-typescript",
|
||||
"check-coverage": true,
|
||||
"all": true,
|
||||
"include": [
|
||||
"src/**/*.ts"
|
||||
],
|
||||
"reporter": [
|
||||
"text-summary"
|
||||
],
|
||||
"branches": 0,
|
||||
"lines": 0,
|
||||
"functions": 0,
|
||||
"statements": 60
|
||||
]
|
||||
}
|
||||
|
||||
@ -31,7 +31,7 @@ export const contentReaderForLibraryItem = (
|
||||
* the default app engine service account on the IAM page. We also need to
|
||||
* enable IAM related APIs on the project.
|
||||
*/
|
||||
const storage = env.fileUpload?.gcsUploadSAKeyFilePath
|
||||
export const storage = env.fileUpload?.gcsUploadSAKeyFilePath
|
||||
? new Storage({ keyFilename: env.fileUpload.gcsUploadSAKeyFilePath })
|
||||
: new Storage()
|
||||
const bucketName = env.fileUpload.gcsUploadBucket
|
||||
|
||||
@ -120,7 +120,13 @@ export const createTestLibraryItem = async (
|
||||
slug: 'test-with-omnivore',
|
||||
}
|
||||
|
||||
const createdItem = await createOrUpdateLibraryItem(item, userId)
|
||||
const createdItem = await createOrUpdateLibraryItem(
|
||||
item,
|
||||
userId,
|
||||
undefined,
|
||||
true,
|
||||
true
|
||||
)
|
||||
if (labels) {
|
||||
await saveLabelsInLibraryItem(labels, createdItem.id, userId)
|
||||
}
|
||||
|
||||
@ -1,9 +1,6 @@
|
||||
import { Storage } from '@google-cloud/storage'
|
||||
import sinon from 'sinon'
|
||||
import { env } from '../src/env'
|
||||
import { redisDataSource } from '../src/redis_data_source'
|
||||
import { createTestConnection } from './db'
|
||||
import { MockBucket } from './mock_storage'
|
||||
import { startApolloServer, startWorker } from './util'
|
||||
|
||||
export const mochaGlobalSetup = async () => {
|
||||
@ -22,12 +19,4 @@ export const mochaGlobalSetup = async () => {
|
||||
|
||||
await startApolloServer()
|
||||
console.log('apollo server started')
|
||||
|
||||
const mockBucket = new MockBucket('test')
|
||||
sinon.replace(
|
||||
Storage.prototype,
|
||||
'bucket',
|
||||
sinon.fake.returns(mockBucket as never)
|
||||
)
|
||||
console.log('mock cloud storage created')
|
||||
}
|
||||
|
||||
@ -1,12 +1,9 @@
|
||||
import sinon from 'sinon'
|
||||
import { appDataSource } from '../src/data_source'
|
||||
import { env } from '../src/env'
|
||||
import { redisDataSource } from '../src/redis_data_source'
|
||||
import { stopApolloServer, stopWorker } from './util'
|
||||
|
||||
export const mochaGlobalTeardown = async () => {
|
||||
sinon.restore()
|
||||
|
||||
await stopApolloServer()
|
||||
console.log('apollo server stopped')
|
||||
|
||||
|
||||
@ -1,10 +1,11 @@
|
||||
import { Writable } from 'stream'
|
||||
|
||||
class MockStorage {
|
||||
export class MockStorage {
|
||||
buckets: { [name: string]: MockBucket }
|
||||
|
||||
constructor() {
|
||||
this.buckets = {}
|
||||
console.log('MockStorage initialized')
|
||||
}
|
||||
|
||||
bucket(name: string) {
|
||||
@ -12,13 +13,14 @@ class MockStorage {
|
||||
}
|
||||
}
|
||||
|
||||
export class MockBucket {
|
||||
class MockBucket {
|
||||
name: string
|
||||
files: { [path: string]: MockFile }
|
||||
|
||||
constructor(name: string) {
|
||||
this.name = name
|
||||
this.files = {}
|
||||
console.log('MockBucket initialized')
|
||||
}
|
||||
|
||||
file(path: string) {
|
||||
@ -33,6 +35,7 @@ class MockFile {
|
||||
constructor(path: string) {
|
||||
this.path = path
|
||||
this.contents = Buffer.alloc(0)
|
||||
console.log('MockFile initialized')
|
||||
}
|
||||
|
||||
createWriteStream() {
|
||||
|
||||
@ -435,7 +435,13 @@ describe('Article API', () => {
|
||||
originalUrl: 'https://blog.omnivore.app/test-with-omnivore',
|
||||
directionality: DirectionalityType.RTL,
|
||||
}
|
||||
const item = await createOrUpdateLibraryItem(itemToCreate, user.id)
|
||||
const item = await createOrUpdateLibraryItem(
|
||||
itemToCreate,
|
||||
user.id,
|
||||
undefined,
|
||||
true,
|
||||
true
|
||||
)
|
||||
itemId = item.id
|
||||
|
||||
// save highlights
|
||||
@ -528,11 +534,11 @@ describe('Article API', () => {
|
||||
})
|
||||
|
||||
describe('SavePage', () => {
|
||||
let title = 'Example Title'
|
||||
const title = 'Example Title'
|
||||
let url = 'https://blog.omnivore.app'
|
||||
let originalContent =
|
||||
const originalContent =
|
||||
'<html dir="rtl"><body><div>Example Content</div></body></html>'
|
||||
let source = 'puppeteer-parse'
|
||||
const source = 'puppeteer-parse'
|
||||
|
||||
context('when we save a new item', () => {
|
||||
after(async () => {
|
||||
@ -668,7 +674,7 @@ describe('Article API', () => {
|
||||
|
||||
describe('SaveUrl', () => {
|
||||
let query = ''
|
||||
let url = 'https://blog.omnivore.app/new-url-1'
|
||||
const url = 'https://blog.omnivore.app/new-url-1'
|
||||
|
||||
before(() => {
|
||||
sinon.replace(createTask, 'enqueueParseRequest', sinon.fake.resolves(''))
|
||||
@ -727,8 +733,8 @@ describe('Article API', () => {
|
||||
describe('saveArticleReadingProgressResolver', () => {
|
||||
let query = ''
|
||||
let itemId = ''
|
||||
let progress = 0.5
|
||||
let topPercent: number | null = null
|
||||
const progress = 0.5
|
||||
const topPercent: number | null = null
|
||||
|
||||
before(async () => {
|
||||
itemId = (await createTestLibraryItem(user.id)).id
|
||||
@ -1976,7 +1982,7 @@ describe('Article API', () => {
|
||||
const items: LibraryItem[] = []
|
||||
|
||||
let query = ''
|
||||
let keyword = 'typeahead'
|
||||
const keyword = 'typeahead'
|
||||
|
||||
before(async () => {
|
||||
// Create some test items
|
||||
@ -2049,8 +2055,8 @@ describe('Article API', () => {
|
||||
}
|
||||
`
|
||||
let since: string
|
||||
let items: LibraryItem[] = []
|
||||
let deletedItems: LibraryItem[] = []
|
||||
const items: LibraryItem[] = []
|
||||
const deletedItems: LibraryItem[] = []
|
||||
|
||||
before(async () => {
|
||||
// Create some test items
|
||||
@ -2263,7 +2269,7 @@ describe('Article API', () => {
|
||||
)
|
||||
|
||||
context('when action is Delete and query contains item id', () => {
|
||||
let items: LibraryItem[] = []
|
||||
const items: LibraryItem[] = []
|
||||
|
||||
before(async () => {
|
||||
// Create some test items
|
||||
@ -2367,7 +2373,7 @@ describe('Article API', () => {
|
||||
}
|
||||
}`
|
||||
|
||||
let items: LibraryItem[] = []
|
||||
const items: LibraryItem[] = []
|
||||
|
||||
before(async () => {
|
||||
// Create some test items
|
||||
|
||||
Reference in New Issue
Block a user