Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions spec/v2.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,25 @@ import {
import { defineString } from 'firebase-functions/params';
import { makeDataSnapshot } from '../src/providers/database';
import { makeDocumentSnapshot } from '../src/providers/firestore';
import { makeChange } from '../src/v1';
import { inspect } from 'util';

describe('v2', () => {
describe('#wrapV2', () => {
const handler = (cloudEvent) => ({ cloudEvent });

function assertWrappedV2FunctionTypes() {
const cloudFn = firestore.onDocumentWritten('foo/bar/baz', handler);
const cloudFnWrap = wrapV2(cloudFn);
const before = makeDocumentSnapshot({ snapshot: 'before' }, 'foo/bar/baz');
const after = makeDocumentSnapshot({ snapshot: 'after' }, 'foo/bar/baz');
const change = makeChange(before, after);

cloudFnWrap({ data: change });
// @ts-expect-error V2 wrappers accept CloudEvent partials, not raw event data.
cloudFnWrap(change);
}
Comment thread
CorieW marked this conversation as resolved.
Outdated

describe('alerts', () => {
describe('alerts.onAlertPublished()', () => {
it('should update CloudEvent appropriately', () => {
Expand Down
8 changes: 7 additions & 1 deletion src/v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,17 @@ import { generateCombinedCloudEvent } from './cloudevent/generate';
import { DeepPartial } from './cloudevent/types';
import * as express from 'express';

type WrappedV2CloudEventPartial<T extends CloudEvent<unknown>> = DeepPartial<
Omit<T, 'data'>
> & {
data?: T['data'] | object;
};

/** A function that can be called with test data and optional override values for {@link CloudEvent}
* It will subsequently invoke the cloud function it wraps with the provided {@link CloudEvent}
*/
export type WrappedV2Function<T extends CloudEvent<unknown>> = (
cloudEventPartial?: DeepPartial<T | object>
cloudEventPartial?: WrappedV2CloudEventPartial<T>
) => any | Promise<any>;

export type WrappedV2CallableFunction<T> = (
Expand Down
Loading