From 58f676209dfc6c058099143fde8b5f541adc4917 Mon Sep 17 00:00:00 2001 From: Wai Sing Yiu Date: Thu, 28 Mar 2024 12:01:04 +0000 Subject: [PATCH] Fix test cases --- .../gu/notifications/worker/delivery/fcm/FcmClient.scala | 7 ++++--- .../notifications/worker/delivery/fcm/FcmClientTest.scala | 6 +++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/notificationworkerlambda/src/main/scala/com/gu/notifications/worker/delivery/fcm/FcmClient.scala b/notificationworkerlambda/src/main/scala/com/gu/notifications/worker/delivery/fcm/FcmClient.scala index 61fcb8152..775fb8a96 100644 --- a/notificationworkerlambda/src/main/scala/com/gu/notifications/worker/delivery/fcm/FcmClient.scala +++ b/notificationworkerlambda/src/main/scala/com/gu/notifications/worker/delivery/fcm/FcmClient.scala @@ -2,6 +2,7 @@ package com.gu.notifications.worker.delivery.fcm import _root_.models.Notification import com.google.api.core.{ApiFuture, ApiFutureCallback, ApiFutures} +import com.google.api.client.json.JsonFactory import com.google.auth.oauth2.GoogleCredentials import com.google.firebase.messaging._ import com.google.firebase.{ErrorCode, FirebaseApp, FirebaseOptions} @@ -24,7 +25,7 @@ import scala.util.{Failure, Success, Try} import okhttp3.{Headers, MediaType, OkHttpClient, Request, RequestBody, Response, ResponseBody} -class FcmClient (firebaseMessaging: FirebaseMessaging, firebaseApp: FirebaseApp, config: FcmConfig, projectId: String, credential: GoogleCredentials) +class FcmClient (firebaseMessaging: FirebaseMessaging, firebaseApp: FirebaseApp, config: FcmConfig, projectId: String, credential: GoogleCredentials, jsonFactory: JsonFactory) extends DeliveryClient with Logging { type Success = FcmDeliverySuccess @@ -49,7 +50,7 @@ class FcmClient (firebaseMessaging: FirebaseMessaging, firebaseApp: FirebaseApp, private final val FCM_URL: String = s"https://fcm.googleapis.com/v1/projects/${projectId}/messages:send"; - private val fcmClient: FcmTransportMultiplexedHttp2Impl = new FcmTransportMultiplexedHttp2Impl(credential, FCM_URL, firebaseApp.getOptions().getJsonFactory()) + private val fcmClient: FcmTransportMultiplexedHttp2Impl = new FcmTransportMultiplexedHttp2Impl(credential, FCM_URL, jsonFactory) def payloadBuilder: Notification => Option[FcmPayload] = n => FcmPayloadBuilder(n, config.debug) @@ -174,7 +175,7 @@ object FcmClient { case None => FirebaseApp.initializeApp(firebaseOptions) case Some(name) => FirebaseApp.initializeApp(firebaseOptions, name) } - new FcmClient(FirebaseMessaging.getInstance(firebaseApp), firebaseApp, config, firebaseOptions.getProjectId(), credential) + new FcmClient(FirebaseMessaging.getInstance(firebaseApp), firebaseApp, config, firebaseOptions.getProjectId(), credential, firebaseOptions.getJsonFactory()) } } diff --git a/notificationworkerlambda/src/test/scala/com/gu/notifications/worker/delivery/fcm/FcmClientTest.scala b/notificationworkerlambda/src/test/scala/com/gu/notifications/worker/delivery/fcm/FcmClientTest.scala index b752f29aa..a41bcd90e 100644 --- a/notificationworkerlambda/src/test/scala/com/gu/notifications/worker/delivery/fcm/FcmClientTest.scala +++ b/notificationworkerlambda/src/test/scala/com/gu/notifications/worker/delivery/fcm/FcmClientTest.scala @@ -22,6 +22,8 @@ import java.util.UUID import scala.collection.mutable.ListBuffer import scala.jdk.CollectionConverters._ import scala.util.{Failure, Success} +import com.google.auth.oauth2.GoogleCredentials +import com.google.api.client.json.JsonFactory class FcmClientTest extends Specification with Mockito { "the FcmClient" should { @@ -171,5 +173,7 @@ trait FcmScope extends Scope { val mockApiFuture = Mockito.mock[ApiFuture[String]] val config: FcmConfig = FcmConfig("serviceAccountKey") - val fcmClient = new FcmClient(mockFirebaseMessaging, app, config) + val mockCredential = Mockito.mock[GoogleCredentials] + val mockJsonFactory = Mockito.mock[JsonFactory] + val fcmClient = new FcmClient(mockFirebaseMessaging, app, config, "TEST-PROJECT-ID", mockCredential, mockJsonFactory) }