Skip to content

Commit cb61522

Browse files
authored
Added smoke tests for Functions. (#474)
This commit adds two simple smoke tests for Functions.
1 parent ac88a6d commit cb61522

File tree

3 files changed

+63
-1
lines changed

3 files changed

+63
-1
lines changed

smoke-tests/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ android {
6565
"src/combined/java",
6666
"src/database/java",
6767
"src/firestore/java",
68+
"src/functions/java",
6869
"src/storage/java",
6970
]
7071
}
@@ -97,6 +98,7 @@ dependencies {
9798
combinedImplementation "com.google.firebase:firebase-auth"
9899
combinedImplementation "com.google.firebase:firebase-database"
99100
combinedImplementation "com.google.firebase:firebase-firestore"
101+
combinedImplementation "com.google.firebase:firebase-functions"
100102
combinedImplementation "com.google.firebase:firebase-storage"
101103

102104
// Database

smoke-tests/src/combined/java/com/google/firebase/testing/combined/AllTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import com.google.firebase.testing.database.DatabaseTest;
1818
import com.google.firebase.testing.firestore.FirestoreTest;
19+
import com.google.firebase.testing.functions.FunctionsTest;
1920
import com.google.firebase.testing.storage.StorageTest;
2021
import org.junit.runner.RunWith;
2122
import org.junit.runners.Suite;
@@ -24,5 +25,5 @@
2425
* A test suite combining the individual product flavors.
2526
*/
2627
@RunWith(Suite.class)
27-
@Suite.SuiteClasses({DatabaseTest.class, FirestoreTest.class, StorageTest.class})
28+
@Suite.SuiteClasses({DatabaseTest.class, FirestoreTest.class, FunctionsTest.class, StorageTest.class})
2829
public final class AllTests {}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// Copyright 2018 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package com.google.firebase.testing.functions;
16+
17+
import static com.google.common.truth.Truth.assertThat;
18+
19+
import android.app.Activity;
20+
import androidx.test.rule.ActivityTestRule;
21+
import androidx.test.runner.AndroidJUnit4;
22+
import com.google.android.gms.tasks.Task;
23+
import com.google.firebase.functions.FirebaseFunctions;
24+
import com.google.firebase.functions.FirebaseFunctionsException;
25+
import com.google.firebase.functions.HttpsCallableResult;
26+
import com.google.firebase.testing.common.Tasks2;
27+
import java.util.HashMap;
28+
import org.junit.Rule;
29+
import org.junit.Test;
30+
import org.junit.runner.RunWith;
31+
32+
/** Functions smoke tests. */
33+
@RunWith(AndroidJUnit4.class)
34+
public final class FunctionsTest {
35+
36+
@Rule public final ActivityTestRule<Activity> activity = new ActivityTestRule<>(Activity.class);
37+
38+
@Test
39+
public void callFakeFunctionShouldFail() throws Exception {
40+
FirebaseFunctions functions = FirebaseFunctions.getInstance();
41+
Task<HttpsCallableResult> task = functions.getHttpsCallable("clearlyFake31").call();
42+
Tasks2.waitForFailure(task);
43+
}
44+
45+
@Test
46+
@SuppressWarnings("unchecked")
47+
public void callAddNumbersShouldReturnResult() throws Exception {
48+
FirebaseFunctions functions = FirebaseFunctions.getInstance();
49+
HashMap<String, Object> data = new HashMap<>();
50+
data.put("firstNumber", 13);
51+
data.put("secondNumber", 17);
52+
53+
Task<HttpsCallableResult> task = functions.getHttpsCallable("addNumbers").call(data);
54+
HttpsCallableResult result = Tasks2.waitForSuccess(task);
55+
HashMap<String, Object> map = (HashMap<String, Object>) result.getData();
56+
57+
assertThat(map.get("operationResult")).isEqualTo(30);
58+
}
59+
}

0 commit comments

Comments
 (0)