[tests][functions] create testing cloud function project

This commit is contained in:
Salakar 2018-05-05 18:22:08 +01:00
parent a07e859ff6
commit 300c31fffe
7 changed files with 3970 additions and 0 deletions

1
.gitignore vendored
View File

@ -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
View File

@ -0,0 +1,5 @@
{
"projects": {
"default": "rnfirebase-b9ad4"
}
}

1
bridge/firebase.json Normal file
View File

@ -0,0 +1 @@
{}

40
bridge/functions/index.js Normal file
View 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

File diff suppressed because it is too large Load Diff

View 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
}

View 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],
},
],
};