tests(functions): functions jest tests (#3565)

[skip-ci]
This commit is contained in:
Darren Ackers
2020-04-28 13:36:56 +01:00
committed by GitHub
parent 4cc5f4a86b
commit e10482b217
2 changed files with 22 additions and 17 deletions

View File

@@ -1,6 +1,14 @@
import functions from '../lib';
import functions, { firebase } from '../lib';
describe('Cloud Functions', () => {
describe('namespace', () => {
it('accessible from firebase.app()', () => {
const app = firebase.app();
expect(app.functions).toBeDefined();
expect(app.functions().httpsCallable).toBeDefined();
});
});
describe('useFunctionsEmulator()', () => {
it('useFunctionsEmulator -> uses 10.0.2.2', () => {
functions().useFunctionsEmulator('http://localhost');
@@ -9,4 +17,17 @@ describe('Cloud Functions', () => {
expect(functions()._useFunctionsEmulatorOrigin).toBe('http://10.0.2.2');
});
});
describe('httpcallable()', () => {
it('throws an error with an incorrect timeout', () => {
try {
const app = firebase.app();
app.functions().httpsCallable('example', { timeout: 'test' });
return Promise.reject(new Error('Did not throw'));
} catch (e) {
expect(e.message).toEqual('HttpsCallableOptions.timeout expected a Number in milliseconds');
return Promise.resolve();
}
});
});
});

View File

@@ -19,12 +19,6 @@ const { SAMPLE_DATA } = require('@react-native-firebase/private-tests-firebase-f
describe('functions()', () => {
describe('namespace', () => {
it('accessible from firebase.app()', () => {
const app = firebase.app();
should.exist(app.functions);
app.functions().httpsCallable.should.be.a.Function();
});
it('accepts passing in an FirebaseApp instance as first arg', async () => {
const appName = `functionsApp${FirebaseHelpers.id}1`;
const platformAppConfig = FirebaseHelpers.app.config();
@@ -65,16 +59,6 @@ describe('functions()', () => {
});
});
android.it('useFunctionsEmulator -> uses 10.0.2.2', async () => {
const region = 'europe-west2';
const functions = firebase.app().functions(region);
functions.useFunctionsEmulator('http://localhost');
functions._useFunctionsEmulatorOrigin.should.equal('http://10.0.2.2');
functions.useFunctionsEmulator('http://127.0.0.1');
functions._useFunctionsEmulatorOrigin.should.equal('http://10.0.2.2');
});
it('useFunctionsEmulator', async () => {
const region = 'europe-west2';
const fnName = 'invertaseReactNativeFirebaseFunctionsEmulator';