Created
October 11, 2019 08:22
-
-
Save mathieu-morchipont/f3b4ff9acbd0f7e216fc73ae216b7d2e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { GCS_BUCKET_NAME_MEDIA } from '../config/storage'; | |
import { MediaGenerateThumbsOnWrite } from './media-thumbs.function'; | |
import { ObjectMetadata } from 'firebase-functions/lib/providers/storage'; | |
import { ObjectWritableMock } from 'stream-mock'; | |
import { DownloadResponse } from '@google-cloud/storage'; | |
// tslint:disable-next-line | |
const { Storage } = require('@google-cloud/storage'); | |
jest.mock('@google-cloud/storage'); | |
const createWriteStream = jest.fn(() => new ObjectWritableMock()); | |
const makePublic = jest.fn(); | |
const file = jest.fn(() => ({ download })); | |
const upload = jest.fn(name => Promise.resolve()); | |
const bucket = jest.fn(() => ({ file, upload })); | |
const download = jest.fn(() => Promise.resolve<DownloadResponse>([new Buffer('\u00bd + \u00bc = \u00be')])); | |
const resize = jest.fn(); | |
const toFile = jest.fn(); | |
const sharp = jest.fn(() => ({ resize, toFile })); | |
Storage.mockImplementation(() => ({ bucket })); | |
it('MediaGenerateThumbsOnWrite: should create thumbs for new media in the GCS bucket', async () => { | |
const data = { | |
bucket: GCS_BUCKET_NAME_MEDIA, | |
name: '/path/of/the/media.png' | |
}; | |
await MediaGenerateThumbsOnWrite(data as ObjectMetadata); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment