Fix tests

This commit is contained in:
Hongbo Wu 2023-03-02 11:02:53 +08:00
parent 10c01c12f2
commit 76b63efdc1
3 changed files with 7 additions and 6 deletions

View file

@ -9,7 +9,7 @@ import { env } from '../env'
* 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

View file

@ -1,6 +1,6 @@
import { Writable } from 'stream'
class MockStorage {
export class MockStorage {
buckets: { [name: string]: MockBucket }
constructor() {
@ -12,7 +12,7 @@ class MockStorage {
}
}
export class MockBucket {
class MockBucket {
name: string
files: { [path: string]: MockFile }

View file

@ -22,8 +22,8 @@ import { getHighlightUrl } from '../../src/services/highlights'
import { deletePage } from '../../src/elastic/pages'
import { READWISE_API_URL } from '../../src/services/integrations/readwise'
import sinon from 'sinon'
import { Storage } from '@google-cloud/storage'
import { MockBucket } from '../mock_storage'
import { MockStorage } from '../mock_storage'
import * as uploads from '../../src/utils/uploads'
describe('Integrations routers', () => {
const baseUrl = '/svc/pubsub/integrations'
@ -347,7 +347,8 @@ describe('Integrations routers', () => {
type: IntegrationType.Import,
})
// mock cloud storage bucket
sinon.stub(Storage, 'Bucket').returns(MockBucket)
// @ts-ignore
sinon.replace(uploads, 'storage', new MockStorage('test-bucket'))
// mock Pocket API
nock('https://getpocket.com', {
reqheaders: {