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