-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Adds support for HTTPS onCall functions and improves HTTPS onRequest rejection #9 * Adds test for https auth params * Begin adding CallableContext * Adds ability to pass CallableContextOptions with runtime field checking * Resolve onCall nits
- Loading branch information
Showing
4 changed files
with
127 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { expect } from 'chai'; | ||
import * as functions from 'firebase-functions'; | ||
import fft = require('../../src/index'); | ||
|
||
const cfToUpperCaseOnRequest = functions.https.onRequest((req, res) => { | ||
res.json({msg: req.params.message.toUpperCase()}); | ||
}); | ||
|
||
const cfToUpperCaseOnCall = functions.https.onCall((data, context) => { | ||
const result = { | ||
msg: data.message.toUpperCase(), | ||
from: 'anonymous', | ||
}; | ||
|
||
if (context.auth && context.auth.uid) { | ||
result.from = context.auth.uid; | ||
} | ||
|
||
return result; | ||
}); | ||
|
||
describe('providers/https', () => { | ||
it('should not throw when passed onRequest function', async () => { | ||
const test = fft(); | ||
/* | ||
Note that we must cast the function to any here because onRequst functions | ||
do not fulfill Runnable<>, so these checks are solely for usage of this lib | ||
in JavaScript test suites. | ||
*/ | ||
expect(() => test.wrap(cfToUpperCaseOnRequest as any)).to.throw(); | ||
}); | ||
|
||
it('should run the wrapped onCall function and return result', async () => { | ||
const test = fft(); | ||
const result = await test.wrap(cfToUpperCaseOnCall)({message: 'lowercase'}); | ||
expect(result).to.deep.equal({msg: 'LOWERCASE', from: 'anonymous'}); | ||
}); | ||
|
||
it('should accept auth params', async () => { | ||
const test = fft(); | ||
const options = {auth: {uid: 'abc'}}; | ||
const result = await test.wrap(cfToUpperCaseOnCall)({message: 'lowercase'}, options); | ||
expect(result).to.deep.equal({msg: 'LOWERCASE', from: 'abc'}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters