Skip to content

Commit 1f04643

Browse files
committed
Add .run method to HTTPS callable functions (#206)
1 parent 6d156d1 commit 1f04643

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

spec/providers/https.spec.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,22 @@ describe('callable.FunctionBuilder', () => {
519519
expect(fn.__trigger.availableMemoryMb).to.deep.equal(256);
520520
expect(fn.__trigger.timeout).to.deep.equal('90s');
521521
});
522+
523+
it('has a .run method', () => {
524+
const cf = https.onCall((data, context) => {
525+
return { data, context };
526+
});
527+
528+
const data = 'data';
529+
const context = {
530+
instanceIdToken: 'token',
531+
auth: {
532+
uid: 'abc',
533+
token: 'token',
534+
},
535+
};
536+
expect(cf.run(data, context)).to.deep.equal({ data, context });
537+
});
522538
});
523539
});
524540

src/cloud-functions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ export interface TriggerAnnotated {
180180

181181
/** A Runnable has a `run` method which directly invokes the user-defined function - useful for unit testing. */
182182
export interface Runnable<T> {
183-
run: (data: T, context: EventContext) => PromiseLike<any> | any;
183+
run: (data: T, context: any) => PromiseLike<any> | any;
184184
}
185185

186186
/**

src/providers/https.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import * as firebase from 'firebase-admin';
2525
import * as _ from 'lodash';
2626
import * as cors from 'cors';
2727
import { apps } from '../apps';
28-
import { HttpsFunction, optsToTrigger } from '../cloud-functions';
28+
import { HttpsFunction, optsToTrigger, Runnable } from '../cloud-functions';
2929
import { DeploymentOptions } from '../function-builder';
3030

3131
/**
@@ -415,7 +415,7 @@ const corsHandler = cors({ origin: true, methods: 'POST' });
415415
export function _onCallWithOpts(
416416
handler: (data: any, context: CallableContext) => any | Promise<any>,
417417
opts: DeploymentOptions
418-
): HttpsFunction {
418+
): HttpsFunction & Runnable<any> {
419419
const func = async (req: express.Request, res: express.Response) => {
420420
try {
421421
if (!isValidRequest(req)) {
@@ -486,5 +486,7 @@ export function _onCallWithOpts(
486486
labels: { 'deployment-callable': 'true' },
487487
});
488488

489+
corsFunc.run = handler;
490+
489491
return corsFunc;
490492
}

0 commit comments

Comments
 (0)