[tests][functions] create testing cloud function project
This commit is contained in:
parent
a07e859ff6
commit
300c31fffe
|
@ -96,3 +96,4 @@ tests/ios/Fabric.framework/Fabric
|
|||
bridge/android/app/.classpath
|
||||
bridge/android/app/.project
|
||||
**/.vscode
|
||||
bridge/functions/firebase-debug.log
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"projects": {
|
||||
"default": "rnfirebase-b9ad4"
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
{}
|
|
@ -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;
|
||||
});
|
File diff suppressed because it is too large
Load Diff
|
@ -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
|
||||
}
|
|
@ -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],
|
||||
},
|
||||
],
|
||||
};
|
Loading…
Reference in New Issue