firebase / firebase-functions-test

MIT License
232 stars 48 forks source link

Allow passing context.app to wrapped callable functions. #123

Closed taeold closed 2 years ago

taeold commented 2 years ago

Change allows users to pass app property in the mocked callable context, e.g.

export myFunc = functions.https.onCall((data, context) => {
  if (context.app == undefined) {
    throw new functions.https.HttpsError(
        'failed-precondition',
        'The function must be called from an App Check verified app.')
  }
});

Before

wrap(myFunc)('data', { app: { appId: 'my-app-123' }});
// => Options object {"auth":{"uid":""},"app":{}} has invalid key "app"

After

wrap(myFunc)('data', { app: { appId: 'my-app-123' }});
// no error

The diff on main.spec.ts looks terrible - I'm just adding a few test cases for callable functions, and indenting the ones that existed before.

Fixes https://github.com/firebase/firebase-functions-test/issues/122