How to stub auth0 using sinon in Firebase Functions

I’m trying to make offline testing work for my app, but I’m having trouble stubbing auth0

You can see above that in my function I call

auth0.getProfile(conv.user.access.token)

I’m simply trying to stub that to return a canned response, but I can’t figure out how to stub the object auth0 from within my test script.

Closing this as @dwmaillist commented in his SO thread what he did to correct, which I am copying in here:

I discovered that rather than initialize the Auth0 AuthenticationClient, I could first require the UsersManager, where the getProfile (which wraps getInfo) is defined.

var UsersManager = require('auth0/src/auth/UsersManager');

In my before() method, I can then create a stub for getInfo, like this

sinon.stub(UsersManager.prototype, 'getInfo').callsFake( function fakeGetProfile() {
  return Promise.resolve({"email": "some.user@company.com"});
});

All the calls to auth0.getProfile then return a Promise that resolves to the document shown in my stub fake function.

This topic was automatically closed after 25 hours. New replies are no longer allowed.