Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mathieu-morchipont/f3b4ff9acbd0f7e216fc73ae216b7d2e to your computer and use it in GitHub Desktop.
Save mathieu-morchipont/f3b4ff9acbd0f7e216fc73ae216b7d2e to your computer and use it in GitHub Desktop.
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