diff --git a/smoke-tests/build.gradle b/smoke-tests/build.gradle index 44eea77f58f..087c2b0d055 100644 --- a/smoke-tests/build.gradle +++ b/smoke-tests/build.gradle @@ -65,6 +65,7 @@ android { "src/combined/java", "src/database/java", "src/firestore/java", + "src/functions/java", "src/storage/java", ] } @@ -97,6 +98,7 @@ dependencies { combinedImplementation "com.google.firebase:firebase-auth" combinedImplementation "com.google.firebase:firebase-database" combinedImplementation "com.google.firebase:firebase-firestore" + combinedImplementation "com.google.firebase:firebase-functions" combinedImplementation "com.google.firebase:firebase-storage" // Database diff --git a/smoke-tests/src/combined/java/com/google/firebase/testing/combined/AllTests.java b/smoke-tests/src/combined/java/com/google/firebase/testing/combined/AllTests.java index e4a4291a552..99ced1081ff 100644 --- a/smoke-tests/src/combined/java/com/google/firebase/testing/combined/AllTests.java +++ b/smoke-tests/src/combined/java/com/google/firebase/testing/combined/AllTests.java @@ -16,6 +16,7 @@ import com.google.firebase.testing.database.DatabaseTest; import com.google.firebase.testing.firestore.FirestoreTest; +import com.google.firebase.testing.functions.FunctionsTest; import com.google.firebase.testing.storage.StorageTest; import org.junit.runner.RunWith; import org.junit.runners.Suite; @@ -24,5 +25,5 @@ * A test suite combining the individual product flavors. */ @RunWith(Suite.class) -@Suite.SuiteClasses({DatabaseTest.class, FirestoreTest.class, StorageTest.class}) +@Suite.SuiteClasses({DatabaseTest.class, FirestoreTest.class, FunctionsTest.class, StorageTest.class}) public final class AllTests {} diff --git a/smoke-tests/src/functions/java/com/google/firebase/testing/functions/FunctionsTest.java b/smoke-tests/src/functions/java/com/google/firebase/testing/functions/FunctionsTest.java new file mode 100644 index 00000000000..13feff7af38 --- /dev/null +++ b/smoke-tests/src/functions/java/com/google/firebase/testing/functions/FunctionsTest.java @@ -0,0 +1,59 @@ +// Copyright 2018 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package com.google.firebase.testing.functions; + +import static com.google.common.truth.Truth.assertThat; + +import android.app.Activity; +import androidx.test.rule.ActivityTestRule; +import androidx.test.runner.AndroidJUnit4; +import com.google.android.gms.tasks.Task; +import com.google.firebase.functions.FirebaseFunctions; +import com.google.firebase.functions.FirebaseFunctionsException; +import com.google.firebase.functions.HttpsCallableResult; +import com.google.firebase.testing.common.Tasks2; +import java.util.HashMap; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; + +/** Functions smoke tests. */ +@RunWith(AndroidJUnit4.class) +public final class FunctionsTest { + + @Rule public final ActivityTestRule activity = new ActivityTestRule<>(Activity.class); + + @Test + public void callFakeFunctionShouldFail() throws Exception { + FirebaseFunctions functions = FirebaseFunctions.getInstance(); + Task task = functions.getHttpsCallable("clearlyFake31").call(); + Tasks2.waitForFailure(task); + } + + @Test + @SuppressWarnings("unchecked") + public void callAddNumbersShouldReturnResult() throws Exception { + FirebaseFunctions functions = FirebaseFunctions.getInstance(); + HashMap data = new HashMap<>(); + data.put("firstNumber", 13); + data.put("secondNumber", 17); + + Task task = functions.getHttpsCallable("addNumbers").call(data); + HttpsCallableResult result = Tasks2.waitForSuccess(task); + HashMap map = (HashMap) result.getData(); + + assertThat(map.get("operationResult")).isEqualTo(30); + } +}