mirror of
https://github.com/zhigang1992/react-native-firebase.git
synced 2026-01-12 17:42:24 +08:00
[tests][functions] create testing cloud function project
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -96,3 +96,4 @@ tests/ios/Fabric.framework/Fabric
|
||||
bridge/android/app/.classpath
|
||||
bridge/android/app/.project
|
||||
**/.vscode
|
||||
bridge/functions/firebase-debug.log
|
||||
|
||||
5
bridge/.firebaserc
Normal file
5
bridge/.firebaserc
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"projects": {
|
||||
"default": "rnfirebase-b9ad4"
|
||||
}
|
||||
}
|
||||
1
bridge/firebase.json
Normal file
1
bridge/firebase.json
Normal file
@@ -0,0 +1 @@
|
||||
{}
|
||||
40
bridge/functions/index.js
Normal file
40
bridge/functions/index.js
Normal file
@@ -0,0 +1,40 @@
|
||||
const functions = require('firebase-functions');
|
||||
|
||||
const TEST_DATA = require('./test-data');
|
||||
|
||||
exports.runTest = functions.https.onCall(data => {
|
||||
const { type, asError, inputData } = data;
|
||||
if (!Object.hasOwnProperty.call(TEST_DATA, type)) {
|
||||
throw new functions.https.HttpsError(
|
||||
'invalid-argument',
|
||||
'Invalid test requested.'
|
||||
);
|
||||
}
|
||||
|
||||
const outputData = TEST_DATA[type];
|
||||
if (typeof outputData !== typeof inputData) {
|
||||
throw new functions.https.HttpsError(
|
||||
'invalid-argument',
|
||||
'Input and Output types did not match.'
|
||||
);
|
||||
}
|
||||
|
||||
// cheap deep equality check
|
||||
if (JSON.stringify(outputData) !== JSON.stringify(inputData)) {
|
||||
throw new functions.https.HttpsError(
|
||||
'invalid-argument',
|
||||
'Input and Output failed deep equality check.'
|
||||
);
|
||||
}
|
||||
|
||||
// all good
|
||||
if (asError) {
|
||||
throw new functions.https.HttpsError(
|
||||
'cancelled',
|
||||
'Response data was request as part of a Error payload, so here we are!',
|
||||
outputData
|
||||
);
|
||||
}
|
||||
|
||||
return outputData;
|
||||
});
|
||||
3866
bridge/functions/package-lock.json
generated
Normal file
3866
bridge/functions/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
16
bridge/functions/package.json
Normal file
16
bridge/functions/package.json
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"name": "functions",
|
||||
"description": "Cloud Functions for Firebase",
|
||||
"scripts": {
|
||||
"serve": "firebase serve --only functions",
|
||||
"shell": "firebase functions:shell",
|
||||
"start": "npm run shell",
|
||||
"deploy": "firebase deploy --only functions",
|
||||
"logs": "firebase functions:log"
|
||||
},
|
||||
"dependencies": {
|
||||
"firebase-admin": "~5.12.0",
|
||||
"firebase-functions": "^1.0.1"
|
||||
},
|
||||
"private": true
|
||||
}
|
||||
41
bridge/functions/test-data.js
Normal file
41
bridge/functions/test-data.js
Normal file
@@ -0,0 +1,41 @@
|
||||
module.exports = {
|
||||
number: 1234,
|
||||
string: 'acde',
|
||||
boolean: true,
|
||||
null: null,
|
||||
simpleObject: {
|
||||
number: 1234,
|
||||
string: 'acde',
|
||||
boolean: true,
|
||||
null: null,
|
||||
},
|
||||
simpleArray: [1234, 'acde', true, null],
|
||||
advancedObject: {
|
||||
array: [1234, 'acde', false, null],
|
||||
object: {
|
||||
number: 1234,
|
||||
string: 'acde',
|
||||
boolean: true,
|
||||
null: null,
|
||||
array: [1234, 'acde', true, null],
|
||||
},
|
||||
number: 1234,
|
||||
string: 'acde',
|
||||
boolean: true,
|
||||
null: null,
|
||||
},
|
||||
advancedArray: [
|
||||
1234,
|
||||
'acde',
|
||||
true,
|
||||
null,
|
||||
[1234, 'acde', true, null],
|
||||
{
|
||||
number: 1234,
|
||||
string: 'acde',
|
||||
boolean: true,
|
||||
null: null,
|
||||
array: [1234, 'acde', true, null],
|
||||
},
|
||||
],
|
||||
};
|
||||
Reference in New Issue
Block a user