New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit testing HTTP Callable functions #9

Open
ahaverty opened this Issue Apr 8, 2018 · 10 comments

Comments

Projects
None yet
7 participants
@ahaverty

ahaverty commented Apr 8, 2018

I'm currently moving a lot of our functions to the new HTTP callable functions, and noticed that the docs note:

Note: Testing of HTTP Callable Functions is not yet supported.

Is this something that might be added to the library soon or is there some long-term limitation?

@laurenzlong

This comment has been minimized.

Member

laurenzlong commented Apr 21, 2018

We're working on it!

@ahaverty

This comment has been minimized.

ahaverty commented May 17, 2018

@laurenzlong Sorry for github issue spam, but adding unit testing of https.onCall is now at the top of our companies firebase wish-list 🙏 We'd appreciate hearing about any updates 😄

@thorlukasz

This comment has been minimized.

thorlukasz commented Jun 27, 2018

Any updates? :)

laurenzlong added a commit that referenced this issue Jul 17, 2018

@laurenzlong

This comment has been minimized.

Member

laurenzlong commented Aug 7, 2018

Sorry for the delay, and thanks for the patience everyone! We've been busy working on launching regional support, Node 8 support, and configuration of timeouts and memory allocation, now that those are out the door, this is next up on our roadmap.

@jeanregisser

This comment has been minimized.

jeanregisser commented Sep 3, 2018

Is there any workaround before official support for this gets released?

@joelgetaction

This comment has been minimized.

joelgetaction commented Sep 8, 2018

I really need this since most of my functions are http callable. In fact I'd be happy to help with this if you can assign me some tasks or hints ... :-)

Any updates?

@laurenzlong

This comment has been minimized.

Member

laurenzlong commented Sep 12, 2018

Thanks for the patience everyone! Our team is stretched thin right now so we haven't had a chance to implement this yet. However, you can make use of the run method offered by the firebase-functions SDK, which exists on all cloud functions except HTTPS onRequest functions (see code for callable functions). This is in fact how firebase-functions-test works, it calls the run method.

For example, let's say you have a callable function called myCallableFunction

const myFunctions = require('../index');
const expect = require('chai').expect;

const data = {foo: 'bar'};
const callableContext = {auth: {uid: 'abc'}}; // you can also add "rawRequest" or "instanceIdToken" fields

expect(myFunctions.myCallableFunction.run(data, callableContext))
  .to.eventually.deep.equal({expected: "result"});

@sipersso

This comment has been minimized.

sipersso commented Oct 19, 2018

@laurenzlong Do I understand it correctly that there is no way to test HTTPS callable?

@gustavopch

This comment has been minimized.

gustavopch commented Oct 19, 2018

@sipersso The firebase-functions-test package doesn't currently provide tools for testing Callable Functions, but you can test them anyways as @laurenzlong shows in the snippet right before your comment.

@sipersso

This comment has been minimized.

sipersso commented Oct 19, 2018

@gustavopch yes, I tried it and myFunctions.myCallableFunction.run is not "not a function", hence my question.

Since @laurenzlong wrote that "which exists on all cloud functions except HTTPS onRequest functions", I figured that HTTPS was the key here and not onRequest, but it should work for HTTPS callables?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment