Skip to content

Commit

Permalink
feat(multi-id): move CoreCompletionHandlerRefreshTokenProxy to emarsy…
Browse files Browse the repository at this point in the history
…s module

SUITEDEV-35599

Co-authored-by: davidSchuppa <[email protected]>
  • Loading branch information
matusekma and davidSchuppa committed Apr 22, 2024
1 parent ff7a60e commit 4421d55
Show file tree
Hide file tree
Showing 12 changed files with 19 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ import com.emarsys.mobileengage.push.NotificationInformationListenerProvider
import com.emarsys.mobileengage.push.PushInternal
import com.emarsys.mobileengage.push.PushTokenProvider
import com.emarsys.mobileengage.push.SilentNotificationInformationListenerProvider
import com.emarsys.mobileengage.request.CoreCompletionHandlerRefreshTokenProxyProvider
import com.emarsys.mobileengage.request.MobileEngageRequestModelFactory
import com.emarsys.mobileengage.responsehandler.MobileEngageTokenResponseHandler
import com.emarsys.mobileengage.service.mapper.RemoteMessageMapperFactory
Expand Down Expand Up @@ -121,7 +120,6 @@ class FakeFirebaseDependencyContainer(
override val appLifecycleObserver: AppLifecycleObserver = mock(),
override val requestModelHelper: RequestModelHelper = mock(),
override val sessionIdHolder: SessionIdHolder = mock(),
override val coreCompletionHandlerRefreshTokenProxyProvider: CoreCompletionHandlerRefreshTokenProxyProvider = mock(),
override val mobileEngageRequestModelFactory: MobileEngageRequestModelFactory = mock(),
override val mobileEngageSession: MobileEngageSession = mock(),
override val activityLifecycleWatchdog: ActivityLifecycleWatchdog = mock(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ import com.emarsys.mobileengage.push.NotificationInformationListenerProvider
import com.emarsys.mobileengage.push.PushInternal
import com.emarsys.mobileengage.push.PushTokenProvider
import com.emarsys.mobileengage.push.SilentNotificationInformationListenerProvider
import com.emarsys.mobileengage.request.CoreCompletionHandlerRefreshTokenProxyProvider
import com.emarsys.mobileengage.request.MobileEngageRequestModelFactory
import com.emarsys.mobileengage.responsehandler.MobileEngageTokenResponseHandler
import com.emarsys.mobileengage.service.mapper.RemoteMessageMapperFactory
Expand Down Expand Up @@ -121,7 +120,6 @@ class FakeHuaweiDependencyContainer(
override val appLifecycleObserver: AppLifecycleObserver = mock(),
override val requestModelHelper: RequestModelHelper = mock(),
override val sessionIdHolder: SessionIdHolder = mock(),
override val coreCompletionHandlerRefreshTokenProxyProvider: CoreCompletionHandlerRefreshTokenProxyProvider = mock(),
override val mobileEngageRequestModelFactory: MobileEngageRequestModelFactory = mock(),
override val mobileEngageSession: MobileEngageSession = mock(),
override val activityLifecycleWatchdog: ActivityLifecycleWatchdog = mock(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ import com.emarsys.mobileengage.push.NotificationInformationListenerProvider
import com.emarsys.mobileengage.push.PushInternal
import com.emarsys.mobileengage.push.PushTokenProvider
import com.emarsys.mobileengage.push.SilentNotificationInformationListenerProvider
import com.emarsys.mobileengage.request.CoreCompletionHandlerRefreshTokenProxyProvider
import com.emarsys.request.CoreCompletionHandlerRefreshTokenProxyProvider
import com.emarsys.mobileengage.request.MobileEngageRequestModelFactory
import com.emarsys.mobileengage.responsehandler.MobileEngageTokenResponseHandler
import com.emarsys.mobileengage.service.mapper.RemoteMessageMapperFactory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ import com.emarsys.mobileengage.push.NotificationInformationListenerProvider
import com.emarsys.mobileengage.push.PushInternal
import com.emarsys.mobileengage.push.PushTokenProvider
import com.emarsys.mobileengage.push.SilentNotificationInformationListenerProvider
import com.emarsys.mobileengage.request.CoreCompletionHandlerRefreshTokenProxyProvider
import com.emarsys.request.CoreCompletionHandlerRefreshTokenProxyProvider
import com.emarsys.mobileengage.request.MobileEngageRequestModelFactory
import com.emarsys.mobileengage.request.mapper.ContactTokenHeaderMapper
import com.emarsys.mobileengage.request.mapper.DefaultRequestHeaderMapper
Expand Down
3 changes: 3 additions & 0 deletions emarsys-sdk/src/main/java/com/emarsys/di/EmarsysComponent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import com.emarsys.predict.PredictApi
import com.emarsys.predict.PredictRestrictedApi
import com.emarsys.predict.di.PredictComponent
import com.emarsys.push.PushApi
import com.emarsys.request.CoreCompletionHandlerRefreshTokenProxyProvider

fun emarsys() = EmarsysComponent.instance
?: throw IllegalStateException("DependencyContainer has to be setup first!")
Expand Down Expand Up @@ -92,4 +93,6 @@ interface EmarsysComponent : MobileEngageComponent, PredictComponent {
val loggingEventService: EventServiceApi

val isGooglePlayServiceAvailable: Boolean

val coreCompletionHandlerRefreshTokenProxyProvider: CoreCompletionHandlerRefreshTokenProxyProvider
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ import com.emarsys.mobileengage.push.NotificationInformationListenerProvider
import com.emarsys.mobileengage.push.PushInternal
import com.emarsys.mobileengage.push.PushTokenProvider
import com.emarsys.mobileengage.push.SilentNotificationInformationListenerProvider
import com.emarsys.mobileengage.request.CoreCompletionHandlerRefreshTokenProxyProvider
import com.emarsys.mobileengage.request.MobileEngageRequestModelFactory
import com.emarsys.mobileengage.responsehandler.MobileEngageTokenResponseHandler
import com.emarsys.mobileengage.service.mapper.RemoteMessageMapperFactory
Expand Down Expand Up @@ -122,7 +121,6 @@ class FakeEmarsysDependencyContainer(
override val appLifecycleObserver: AppLifecycleObserver = mock(),
override val requestModelHelper: RequestModelHelper = mock(),
override val sessionIdHolder: SessionIdHolder = mock(),
override val coreCompletionHandlerRefreshTokenProxyProvider: CoreCompletionHandlerRefreshTokenProxyProvider = mock(),
override val mobileEngageRequestModelFactory: MobileEngageRequestModelFactory = mock(),
override val mobileEngageSession: MobileEngageSession = mock(),
override val activityLifecycleWatchdog: ActivityLifecycleWatchdog = mock(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.emarsys.mobileengage.request
package com.emarsys.request


import com.emarsys.core.CoreCompletionHandler
Expand All @@ -8,6 +8,7 @@ import com.emarsys.core.request.factory.CoreCompletionHandlerMiddlewareProvider
import com.emarsys.core.storage.StringStorage
import com.emarsys.core.worker.CoreCompletionHandlerMiddleware
import com.emarsys.core.worker.Worker
import com.emarsys.mobileengage.request.MobileEngageRequestModelFactory
import com.emarsys.mobileengage.responsehandler.MobileEngageTokenResponseHandler
import com.emarsys.mobileengage.util.RequestModelHelper
import com.emarsys.testUtil.AnnotationSpec
Expand Down Expand Up @@ -53,7 +54,7 @@ class CoreCompletionHandlerRefreshTokenProxyProviderTest : AnnotationSpec() {
mockRequestModelFactory = mock()

coreCompletionHandlerRefreshTokenProxyProvider =
CoreCompletionHandlerRefreshTokenProxyProvider(
com.emarsys.request.CoreCompletionHandlerRefreshTokenProxyProvider(
mockCoreCompletionHandlerMiddlewareProvider,
mockRestClient,
mockContactTokenStorage,
Expand All @@ -74,7 +75,7 @@ class CoreCompletionHandlerRefreshTokenProxyProviderTest : AnnotationSpec() {
mockCoreCompletionHandler
)
).thenReturn(mockCoreCompletionHandlerMiddleware)
val expectedProxy = CoreCompletionHandlerRefreshTokenProxy(
val expectedProxy = com.emarsys.request.CoreCompletionHandlerRefreshTokenProxy(
mockCoreCompletionHandlerMiddleware,
mockRestClient,
mockContactTokenStorage,
Expand All @@ -100,7 +101,7 @@ class CoreCompletionHandlerRefreshTokenProxyProviderTest : AnnotationSpec() {

val result = coreCompletionHandlerRefreshTokenProxyProvider.provideProxy(null, null)

result.javaClass shouldBe CoreCompletionHandlerRefreshTokenProxy::class.java
result.javaClass shouldBe com.emarsys.request.CoreCompletionHandlerRefreshTokenProxy::class.java
}

@Test
Expand All @@ -118,6 +119,6 @@ class CoreCompletionHandlerRefreshTokenProxyProviderTest : AnnotationSpec() {
mockCoreCompletionHandler
)

result.javaClass shouldBe CoreCompletionHandlerRefreshTokenProxy::class.java
result.javaClass shouldBe com.emarsys.request.CoreCompletionHandlerRefreshTokenProxy::class.java
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.emarsys.mobileengage.request
package com.emarsys.request


import com.emarsys.core.CoreCompletionHandler
Expand All @@ -7,6 +7,7 @@ import com.emarsys.core.request.model.RequestMethod
import com.emarsys.core.request.model.RequestModel
import com.emarsys.core.response.ResponseModel
import com.emarsys.core.storage.Storage
import com.emarsys.mobileengage.request.MobileEngageRequestModelFactory
import com.emarsys.mobileengage.responsehandler.MobileEngageTokenResponseHandler
import com.emarsys.mobileengage.util.RequestModelHelper
import com.emarsys.testUtil.AnnotationSpec
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package com.emarsys.mobileengage.request
package com.emarsys.request

import com.emarsys.core.CoreCompletionHandler
import com.emarsys.core.request.RestClient
import com.emarsys.core.request.model.RequestModel
import com.emarsys.core.response.ResponseModel
import com.emarsys.core.storage.Storage
import com.emarsys.mobileengage.request.MobileEngageRequestModelFactory
import com.emarsys.mobileengage.responsehandler.MobileEngageTokenResponseHandler
import com.emarsys.mobileengage.util.RequestModelHelper

Expand Down Expand Up @@ -43,7 +44,8 @@ class CoreCompletionHandlerRefreshTokenProxy(
reset()
coreCompletionHandler.onError(id, response!!.copy(statusCode = 418))
} else if (responseModel.statusCode == 401
&& requestModelHelper.isMobileEngageRequest(responseModel.requestModel)) {
&& requestModelHelper.isMobileEngageRequest(responseModel.requestModel)
) {
pushTokenStorage.remove()
originalResponseModel = responseModel
val refreshTokenRequestModel = requestModelFactory.createRefreshContactTokenRequest()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.emarsys.mobileengage.request
package com.emarsys.request

import com.emarsys.core.CoreCompletionHandler
import com.emarsys.core.Mockable
Expand All @@ -7,6 +7,7 @@ import com.emarsys.core.request.factory.CompletionHandlerProxyProvider
import com.emarsys.core.request.factory.CoreCompletionHandlerMiddlewareProvider
import com.emarsys.core.storage.Storage
import com.emarsys.core.worker.Worker
import com.emarsys.mobileengage.request.MobileEngageRequestModelFactory
import com.emarsys.mobileengage.responsehandler.MobileEngageTokenResponseHandler
import com.emarsys.mobileengage.util.RequestModelHelper

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ import com.emarsys.mobileengage.push.NotificationInformationListenerProvider
import com.emarsys.mobileengage.push.PushInternal
import com.emarsys.mobileengage.push.PushTokenProvider
import com.emarsys.mobileengage.push.SilentNotificationInformationListenerProvider
import com.emarsys.mobileengage.request.CoreCompletionHandlerRefreshTokenProxyProvider
import com.emarsys.mobileengage.request.MobileEngageRequestModelFactory
import com.emarsys.mobileengage.responsehandler.MobileEngageTokenResponseHandler
import com.emarsys.mobileengage.service.mapper.RemoteMessageMapperFactory
Expand Down Expand Up @@ -121,7 +120,6 @@ class FakeMobileEngageDependencyContainer(
override val appLifecycleObserver: AppLifecycleObserver = mock(),
override val requestModelHelper: RequestModelHelper = mock(),
override val sessionIdHolder: SessionIdHolder = mock(),
override val coreCompletionHandlerRefreshTokenProxyProvider: CoreCompletionHandlerRefreshTokenProxyProvider = mock(),
override val mobileEngageRequestModelFactory: MobileEngageRequestModelFactory = mock(),
override val mobileEngageSession: MobileEngageSession = mock(),
override val activityLifecycleWatchdog: ActivityLifecycleWatchdog = mock(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import com.emarsys.mobileengage.push.NotificationInformationListenerProvider
import com.emarsys.mobileengage.push.PushInternal
import com.emarsys.mobileengage.push.PushTokenProvider
import com.emarsys.mobileengage.push.SilentNotificationInformationListenerProvider
import com.emarsys.mobileengage.request.CoreCompletionHandlerRefreshTokenProxyProvider
import com.emarsys.mobileengage.request.MobileEngageRequestModelFactory
import com.emarsys.mobileengage.responsehandler.MobileEngageTokenResponseHandler
import com.emarsys.mobileengage.service.mapper.RemoteMessageMapperFactory
Expand Down Expand Up @@ -184,8 +183,6 @@ interface MobileEngageComponent : CoreComponent {

val sessionIdHolder: SessionIdHolder

val coreCompletionHandlerRefreshTokenProxyProvider: CoreCompletionHandlerRefreshTokenProxyProvider

val mobileEngageRequestModelFactory: MobileEngageRequestModelFactory

val mobileEngageSession: MobileEngageSession
Expand Down

0 comments on commit 4421d55

Please sign in to comment.