@@ -65,12 +65,27 @@ class FirebaseFunctionsTest : public FirebaseTest {
65
65
// Sign in an anonymous user.
66
66
void SignIn ();
67
67
68
+ firebase::Future<firebase::functions::HttpsCallableResult> TestFunctionHelper (
69
+ const char * function_name,
70
+ firebase::functions::HttpsCallableReference& ref,
71
+ const firebase::Variant* const function_data,
72
+ const firebase::Variant& expected_result,
73
+ firebase::functions::Error expected_error =
74
+ firebase::functions::kErrorNone );
75
+
68
76
firebase::Future<firebase::functions::HttpsCallableResult> TestFunction (
69
77
const char * function_name, const firebase::Variant* const function_data,
70
78
const firebase::Variant& expected_result,
71
79
firebase::functions::Error expected_error =
72
80
firebase::functions::kErrorNone );
73
81
82
+ firebase::Future<firebase::functions::HttpsCallableResult>
83
+ TestFunctionFromURL (const char * function_url,
84
+ const firebase::Variant* const function_data,
85
+ const firebase::Variant& expected_result,
86
+ firebase::functions::Error expected_error =
87
+ firebase::functions::kErrorNone );
88
+
74
89
bool initialized_;
75
90
firebase::auth::Auth* auth_;
76
91
firebase::functions::Functions* functions_;
@@ -181,15 +196,11 @@ void FirebaseFunctionsTest::SignIn() {
181
196
182
197
// A helper function for calling a Firebase Function and waiting on the result.
183
198
firebase::Future<firebase::functions::HttpsCallableResult>
184
- FirebaseFunctionsTest::TestFunction (
185
- const char * function_name, const firebase::Variant* const function_data,
199
+ FirebaseFunctionsTest::TestFunctionHelper (
200
+ const char * function_name, firebase::functions::HttpsCallableReference& ref,
201
+ const firebase::Variant* const function_data,
186
202
const firebase::Variant& expected_result,
187
203
firebase::functions::Error expected_error) {
188
- // Create a callable that we can run our test with.
189
- LogDebug (" Calling %s" , function_name);
190
- firebase::functions::HttpsCallableReference ref;
191
- ref = functions_->GetHttpsCallable (function_name);
192
-
193
204
firebase::Future<firebase::functions::HttpsCallableResult> future;
194
205
if (function_data == nullptr ) {
195
206
future = ref.Call ();
@@ -207,6 +218,34 @@ FirebaseFunctionsTest::TestFunction(
207
218
return future;
208
219
}
209
220
221
+ firebase::Future<firebase::functions::HttpsCallableResult>
222
+ FirebaseFunctionsTest::TestFunction (
223
+ const char * function_name, const firebase::Variant* const function_data,
224
+ const firebase::Variant& expected_result,
225
+ firebase::functions::Error expected_error) {
226
+ // Create a callable that we can run our test with.
227
+ LogDebug (" Calling %s" , function_name);
228
+ firebase::functions::HttpsCallableReference ref;
229
+ ref = functions_->GetHttpsCallable (function_name);
230
+
231
+ return TestFunctionHelper (function_name, ref, function_data, expected_result,
232
+ expected_error);
233
+ }
234
+
235
+ firebase::Future<firebase::functions::HttpsCallableResult>
236
+ FirebaseFunctionsTest::TestFunctionFromURL (
237
+ const char * function_url, const firebase::Variant* const function_data,
238
+ const firebase::Variant& expected_result,
239
+ firebase::functions::Error expected_error) {
240
+ // Create a callable that we can run our test with.
241
+ LogDebug (" Calling by URL %s" , function_url);
242
+ firebase::functions::HttpsCallableReference ref;
243
+ ref = functions_->GetHttpsCallableFromURL (function_url);
244
+
245
+ return TestFunctionHelper (function_url, ref, function_data, expected_result,
246
+ expected_error);
247
+ }
248
+
210
249
TEST_F (FirebaseFunctionsTest, TestInitializeAndTerminate) {
211
250
// Already tested via SetUp() and TearDown().
212
251
}
@@ -323,4 +362,22 @@ TEST_F(FirebaseFunctionsTest, TestErrorHandling) {
323
362
firebase::functions::kErrorOutOfRange );
324
363
}
325
364
365
+ TEST_F (FirebaseFunctionsTest, TestFunctionFromURL) {
366
+ SignIn ();
367
+
368
+ // addNumbers(4, 2) = 6
369
+ firebase::Variant data (firebase::Variant::EmptyMap ());
370
+ data.map ()[" firstNumber" ] = 4 ;
371
+ data.map ()[" secondNumber" ] = 2 ;
372
+ std::string proj = app_->options ().project_id ();
373
+ std::string url =
374
+ " https://us-central1-" + proj + " .cloudfunctions.net/addNumbers" ;
375
+ firebase::Variant result =
376
+ TestFunctionFromURL (url.c_str (), &data, firebase::Variant::Null ())
377
+ .result ()
378
+ ->data ();
379
+ EXPECT_TRUE (result.is_map ());
380
+ EXPECT_EQ (result.map ()[" operationResult" ], 6 );
381
+ }
382
+
326
383
} // namespace firebase_testapp_automated
0 commit comments