Skip to content

Commit

Permalink
Fix test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
waisingyiu committed Mar 28, 2024
1 parent 8b512b9 commit 58f6762
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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
Expand All @@ -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)

Expand Down Expand Up @@ -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())
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}

0 comments on commit 58f6762

Please sign in to comment.