diff --git a/widgetssdk/src/main/java/com/glia/widgets/call/CallController.kt b/widgetssdk/src/main/java/com/glia/widgets/call/CallController.kt index 53dfc7c80..c16c26330 100644 --- a/widgetssdk/src/main/java/com/glia/widgets/call/CallController.kt +++ b/widgetssdk/src/main/java/com/glia/widgets/call/CallController.kt @@ -35,7 +35,7 @@ import com.glia.widgets.engagement.domain.EnqueueForEngagementUseCase import com.glia.widgets.engagement.domain.FlipCameraButtonStateUseCase import com.glia.widgets.engagement.domain.FlipVisitorCameraUseCase import com.glia.widgets.engagement.domain.IsCurrentEngagementCallVisualizerUseCase -import com.glia.widgets.engagement.domain.IsQueueingOrEngagementUseCase +import com.glia.widgets.engagement.domain.IsQueueingOrLiveEngagementUseCase import com.glia.widgets.engagement.domain.OperatorMediaUseCase import com.glia.widgets.engagement.domain.ScreenSharingUseCase import com.glia.widgets.engagement.domain.ToggleVisitorAudioMediaStateUseCase @@ -88,7 +88,7 @@ internal class CallController( private val toggleVisitorVideoMediaStateUseCase: ToggleVisitorVideoMediaStateUseCase, private val flipVisitorCameraUseCase: FlipVisitorCameraUseCase, private val flipCameraButtonStateUseCase: FlipCameraButtonStateUseCase, - private val isQueueingOrEngagementUseCase: IsQueueingOrEngagementUseCase, + private val isQueueingOrLiveEngagementUseCase: IsQueueingOrLiveEngagementUseCase, private val enqueueForEngagementUseCase: EnqueueForEngagementUseCase, private val decideOnQueueingUseCase: DecideOnQueueingUseCase, private val screenSharingUseCase: ScreenSharingUseCase, @@ -219,7 +219,7 @@ internal class CallController( } private fun tryToQueueForEngagement() { - if (!isQueueingOrEngagementUseCase()) { + if (!isQueueingOrLiveEngagementUseCase()) { confirmationDialogUseCase { shouldShow: Boolean -> if (shouldShow) { dialogController.showEngagementConfirmationDialog() @@ -231,7 +231,7 @@ internal class CallController( } override fun onLiveObservationDialogRequested() { - if (isQueueingOrEngagementUseCase()) return + if (isQueueingOrLiveEngagementUseCase()) return view?.showEngagementConfirmationDialog() } @@ -403,7 +403,7 @@ internal class CallController( } private fun onNewOperatorMediaState(operatorMediaState: MediaState) { - if (!isQueueingOrEngagementUseCase.hasOngoingEngagement) return + if (!isQueueingOrLiveEngagementUseCase.hasOngoingLiveEngagement) return d(TAG, "newOperatorMediaState: $operatorMediaState, timer task running: ${callTimer.isRunning}") if (operatorMediaState.video != null) { onOperatorMediaStateVideo(operatorMediaState) diff --git a/widgetssdk/src/main/java/com/glia/widgets/callvisualizer/controller/VisitorCodeController.kt b/widgetssdk/src/main/java/com/glia/widgets/callvisualizer/controller/VisitorCodeController.kt index 12703fd0a..2db9d6a4e 100644 --- a/widgetssdk/src/main/java/com/glia/widgets/callvisualizer/controller/VisitorCodeController.kt +++ b/widgetssdk/src/main/java/com/glia/widgets/callvisualizer/controller/VisitorCodeController.kt @@ -5,7 +5,7 @@ import com.glia.widgets.callvisualizer.VisitorCodeContract import com.glia.widgets.core.callvisualizer.domain.VisitorCodeRepository import com.glia.widgets.engagement.State import com.glia.widgets.engagement.domain.EngagementStateUseCase -import com.glia.widgets.engagement.domain.IsQueueingOrEngagementUseCase +import com.glia.widgets.engagement.domain.IsQueueingOrLiveEngagementUseCase import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers import io.reactivex.rxjava3.disposables.Disposable import io.reactivex.rxjava3.schedulers.Schedulers @@ -14,7 +14,7 @@ internal class VisitorCodeController( private val callVisualizerController: CallVisualizerContract.Controller, private val visitorCodeRepository: VisitorCodeRepository, private val engagementStateUseCase: EngagementStateUseCase, - private val isQueueingOrEngagementUseCase: IsQueueingOrEngagementUseCase + private val isQueueingOrLiveEngagementUseCase: IsQueueingOrLiveEngagementUseCase ) : VisitorCodeContract.Controller { private var disposable: Disposable? = null @@ -63,7 +63,7 @@ internal class VisitorCodeController( } private fun autoCloseOnEngagement() { - if (isQueueingOrEngagementUseCase.hasOngoingEngagement) { + if (isQueueingOrLiveEngagementUseCase.hasOngoingLiveEngagement) { // Normally, there is no need for visitor code if there is already ongoing engagement. // But it also doesn't seem right to just close it if right away when it was open return diff --git a/widgetssdk/src/main/java/com/glia/widgets/chat/ChatManager.kt b/widgetssdk/src/main/java/com/glia/widgets/chat/ChatManager.kt index 5be30c4e9..ec842ba03 100644 --- a/widgetssdk/src/main/java/com/glia/widgets/chat/ChatManager.kt +++ b/widgetssdk/src/main/java/com/glia/widgets/chat/ChatManager.kt @@ -31,7 +31,7 @@ import com.glia.widgets.chat.model.VisitorChatItem import com.glia.widgets.core.engagement.domain.model.ChatHistoryResponse import com.glia.widgets.core.engagement.domain.model.ChatMessageInternal import com.glia.widgets.core.secureconversations.domain.MarkMessagesReadWithDelayUseCase -import com.glia.widgets.engagement.domain.IsQueueingOrEngagementUseCase +import com.glia.widgets.engagement.domain.IsQueueingOrLiveEngagementUseCase import com.glia.widgets.helper.Logger import com.glia.widgets.helper.TAG import com.glia.widgets.helper.isValid @@ -53,7 +53,7 @@ internal class ChatManager( private val sendUnsentMessagesUseCase: SendUnsentMessagesUseCase, private val handleCustomCardClickUseCase: HandleCustomCardClickUseCase, private val isAuthenticatedUseCase: IsAuthenticatedUseCase, - private val isQueueingOrEngagementUseCase: IsQueueingOrEngagementUseCase, + private val isQueueingOrLiveEngagementUseCase: IsQueueingOrLiveEngagementUseCase, private val compositeDisposable: CompositeDisposable = CompositeDisposable(), private val state: BehaviorProcessor = BehaviorProcessor.createDefault(State()), private val quickReplies: BehaviorProcessor> = BehaviorProcessor.create(), @@ -108,7 +108,7 @@ internal class ChatManager( @VisibleForTesting fun loadHistory(onHistoryLoaded: (hasHistory: Boolean) -> Unit): Flowable { - val historyEvent = if (isAuthenticatedUseCase() || isQueueingOrEngagementUseCase.hasOngoingEngagement) { + val historyEvent = if (isAuthenticatedUseCase() || isQueueingOrLiveEngagementUseCase.hasOngoingLiveEngagement) { loadHistoryUseCase() .doOnSuccess { historyLoaded.onNext(true) } .zipWith(state.firstOrError(), ::mapChatHistory) diff --git a/widgetssdk/src/main/java/com/glia/widgets/chat/controller/ChatController.kt b/widgetssdk/src/main/java/com/glia/widgets/chat/controller/ChatController.kt index f95973ed8..f3ae57586 100644 --- a/widgetssdk/src/main/java/com/glia/widgets/chat/controller/ChatController.kt +++ b/widgetssdk/src/main/java/com/glia/widgets/chat/controller/ChatController.kt @@ -67,7 +67,7 @@ import com.glia.widgets.engagement.domain.EndEngagementUseCase import com.glia.widgets.engagement.domain.EngagementStateUseCase import com.glia.widgets.engagement.domain.EnqueueForEngagementUseCase import com.glia.widgets.engagement.domain.IsCurrentEngagementCallVisualizerUseCase -import com.glia.widgets.engagement.domain.IsQueueingOrEngagementUseCase +import com.glia.widgets.engagement.domain.IsQueueingOrLiveEngagementUseCase import com.glia.widgets.engagement.domain.OperatorMediaUseCase import com.glia.widgets.engagement.domain.OperatorTypingUseCase import com.glia.widgets.engagement.domain.ReleaseResourcesUseCase @@ -125,7 +125,7 @@ internal class ChatController( private val engagementStateUseCase: EngagementStateUseCase, private val operatorMediaUseCase: OperatorMediaUseCase, private val acceptMediaUpgradeOfferUseCase: AcceptMediaUpgradeOfferUseCase, - private val isQueueingOrEngagementUseCase: IsQueueingOrEngagementUseCase, + private val isQueueingOrLiveEngagementUseCase: IsQueueingOrLiveEngagementUseCase, private val enqueueForEngagementUseCase: EnqueueForEngagementUseCase, private val decideOnQueueingUseCase: DecideOnQueueingUseCase, private val screenSharingUseCase: ScreenSharingUseCase, @@ -195,7 +195,7 @@ internal class ChatController( @Volatile private var chatState: ChatState - private val isQueueingOrOngoingEngagement get() = isQueueingOrEngagementUseCase() + private val isQueueingOrOngoingEngagement get() = isQueueingOrLiveEngagementUseCase() override val isChatVisible: Boolean get() = chatState.isVisible @@ -322,7 +322,7 @@ internal class ChatController( } override fun onEngagementConfirmationDialogRequested() { - if (isQueueingOrEngagementUseCase()) return + if (isQueueingOrLiveEngagementUseCase()) return view?.showEngagementConfirmationDialog() } @@ -584,6 +584,7 @@ internal class ChatController( is State.Update -> handleEngagementStateUpdate(state.updateState) is State.PreQueuing, is State.Queuing -> queueForEngagementStarted() is State.QueueUnstaffed, is State.UnexpectedErrorHappened, is State.QueueingCanceled -> emitViewState { chatState.chatUnavailableState() } + State.TransferredToSecureConversation -> onTransferredToSecureConversation() else -> { // no op @@ -591,6 +592,10 @@ internal class ChatController( } } + private fun onTransferredToSecureConversation() { + emitViewState { chatState.setSecureMessagingState().setSecureMessagingAvailable() } + } + private fun handleEngagementStateUpdate(state: EngagementUpdateState) { when (state) { is EngagementUpdateState.Ongoing -> onEngagementOngoing(state.operator) @@ -681,7 +686,7 @@ internal class ChatController( chatManager.onChatAction( ChatManager.Action.OperatorJoined(formattedOperatorName, profileImgUrl) ) - emitViewState { chatState.operatorConnected(formattedOperatorName, profileImgUrl) } + emitViewState { chatState.operatorConnected(formattedOperatorName, profileImgUrl).setLiveChatState() } } private fun endChat() { @@ -784,7 +789,7 @@ internal class ChatController( private fun onHistoryLoaded(hasHistory: Boolean) { Logger.d(TAG, "historyLoaded") - val isSecureEngagement = manageSecureMessagingStatusUseCase.shouldBehaveAsSecureMessaging() + val isSecureEngagement = manageSecureMessagingStatusUseCase.shouldBehaveAsSecureMessaging if (!hasHistory) { if (!isSecureEngagement && !isQueueingOrOngoingEngagement) { @@ -796,7 +801,7 @@ internal class ChatController( when { isSecureEngagement -> { /* to prevent calling chatState.liveChatHistoryLoaded() */ } - isQueueingOrEngagementUseCase.hasOngoingEngagement -> emitViewState { chatState.engagementStarted() } + isQueueingOrLiveEngagementUseCase.hasOngoingLiveEngagement -> emitViewState { chatState.engagementStarted() } else -> emitViewState { chatState.liveChatHistoryLoaded() } } diff --git a/widgetssdk/src/main/java/com/glia/widgets/chat/domain/GliaLoadHistoryUseCase.kt b/widgetssdk/src/main/java/com/glia/widgets/chat/domain/GliaLoadHistoryUseCase.kt index 4c36195a5..fae1c328b 100644 --- a/widgetssdk/src/main/java/com/glia/widgets/chat/domain/GliaLoadHistoryUseCase.kt +++ b/widgetssdk/src/main/java/com/glia/widgets/chat/domain/GliaLoadHistoryUseCase.kt @@ -18,7 +18,7 @@ internal class GliaLoadHistoryUseCase( private val getUnreadMessagesCountUseCase: GetUnreadMessagesCountWithTimeoutUseCase ) { - private val isSecureEngagement get() = shouldUseSecureMessagingApis.shouldUseSecureMessagingEndpoints() + private val isSecureEngagement get() = shouldUseSecureMessagingApis.shouldUseSecureMessagingEndpoints operator fun invoke(): Single = if (isSecureEngagement) { loadHistoryWithNewMessagesCount() diff --git a/widgetssdk/src/main/java/com/glia/widgets/chat/domain/GliaSendMessageUseCase.kt b/widgetssdk/src/main/java/com/glia/widgets/chat/domain/GliaSendMessageUseCase.kt index b4f0f4a84..292cb9111 100644 --- a/widgetssdk/src/main/java/com/glia/widgets/chat/domain/GliaSendMessageUseCase.kt +++ b/widgetssdk/src/main/java/com/glia/widgets/chat/domain/GliaSendMessageUseCase.kt @@ -32,7 +32,7 @@ internal class GliaSendMessageUseCase( } private val isSecureEngagement: Boolean - get() = shouldUseSecureMessagingApis.shouldUseSecureMessagingEndpoints() + get() = shouldUseSecureMessagingApis.shouldUseSecureMessagingEndpoints private fun sendMessage(payload: SendMessagePayload, listener: Listener) { if (isSecureEngagement) { diff --git a/widgetssdk/src/main/java/com/glia/widgets/chat/domain/IsShowSendButtonUseCase.kt b/widgetssdk/src/main/java/com/glia/widgets/chat/domain/IsShowSendButtonUseCase.kt index 22be80894..2df144b77 100644 --- a/widgetssdk/src/main/java/com/glia/widgets/chat/domain/IsShowSendButtonUseCase.kt +++ b/widgetssdk/src/main/java/com/glia/widgets/chat/domain/IsShowSendButtonUseCase.kt @@ -2,16 +2,16 @@ package com.glia.widgets.chat.domain import com.glia.widgets.core.fileupload.FileAttachmentRepository import com.glia.widgets.core.secureconversations.domain.ManageSecureMessagingStatusUseCase -import com.glia.widgets.engagement.domain.IsQueueingOrEngagementUseCase +import com.glia.widgets.engagement.domain.IsQueueingOrLiveEngagementUseCase internal class IsShowSendButtonUseCase( - private val isQueueingOrEngagementUseCase: IsQueueingOrEngagementUseCase, + private val isQueueingOrLiveEngagementUseCase: IsQueueingOrLiveEngagementUseCase, private val fileAttachmentRepository: FileAttachmentRepository, private val manageSecureMessagingStatusUseCase: ManageSecureMessagingStatusUseCase ) { operator fun invoke(message: String?): Boolean { return when { - manageSecureMessagingStatusUseCase.shouldBehaveAsSecureMessaging() -> hasText(message) || hadReadyToSendUnsentAttachments() + manageSecureMessagingStatusUseCase.shouldBehaveAsSecureMessaging -> hasText(message) || hadReadyToSendUnsentAttachments() else -> hasText(message) || hasEngagementOngoingAndReadyToSendUnsentAttachments() } } @@ -25,6 +25,6 @@ internal class IsShowSendButtonUseCase( } private fun hasEngagementOngoingAndReadyToSendUnsentAttachments(): Boolean { - return isQueueingOrEngagementUseCase.hasOngoingEngagement && hadReadyToSendUnsentAttachments() + return isQueueingOrLiveEngagementUseCase.hasOngoingLiveEngagement && hadReadyToSendUnsentAttachments() } } diff --git a/widgetssdk/src/main/java/com/glia/widgets/chat/domain/SendUnsentMessagesUseCase.kt b/widgetssdk/src/main/java/com/glia/widgets/chat/domain/SendUnsentMessagesUseCase.kt index 9f343e096..75e0f01fc 100644 --- a/widgetssdk/src/main/java/com/glia/widgets/chat/domain/SendUnsentMessagesUseCase.kt +++ b/widgetssdk/src/main/java/com/glia/widgets/chat/domain/SendUnsentMessagesUseCase.kt @@ -30,7 +30,7 @@ internal class SendUnsentMessagesUseCase( } private fun sendMessage(payload: SendMessagePayload, callback: RequestCallback) { - if (shouldUseSecureMessagingApis.shouldUseSecureMessagingEndpoints()) { + if (shouldUseSecureMessagingApis.shouldUseSecureMessagingEndpoints) { secureConversationsRepository.send(payload, callback) } else { chatRepository.sendMessage(payload, callback) diff --git a/widgetssdk/src/main/java/com/glia/widgets/core/chathead/domain/IsDisplayBubbleInsideAppUseCase.kt b/widgetssdk/src/main/java/com/glia/widgets/core/chathead/domain/IsDisplayBubbleInsideAppUseCase.kt index 0bc93064c..70e435f52 100644 --- a/widgetssdk/src/main/java/com/glia/widgets/core/chathead/domain/IsDisplayBubbleInsideAppUseCase.kt +++ b/widgetssdk/src/main/java/com/glia/widgets/core/chathead/domain/IsDisplayBubbleInsideAppUseCase.kt @@ -3,19 +3,19 @@ package com.glia.widgets.core.chathead.domain import com.glia.widgets.core.permissions.PermissionManager import com.glia.widgets.engagement.domain.EngagementTypeUseCase import com.glia.widgets.engagement.domain.IsCurrentEngagementCallVisualizerUseCase -import com.glia.widgets.engagement.domain.IsQueueingOrEngagementUseCase +import com.glia.widgets.engagement.domain.IsQueueingOrLiveEngagementUseCase import com.glia.widgets.engagement.domain.ScreenSharingUseCase import com.glia.widgets.launcher.ConfigurationManager internal class IsDisplayBubbleInsideAppUseCase( - isQueueingOrEngagementUseCase: IsQueueingOrEngagementUseCase, + isQueueingOrLiveEngagementUseCase: IsQueueingOrLiveEngagementUseCase, isCurrentEngagementCallVisualizerUseCase: IsCurrentEngagementCallVisualizerUseCase, screenSharingUseCase: ScreenSharingUseCase, permissionManager: PermissionManager, configurationManager: ConfigurationManager, engagementTypeUseCase: EngagementTypeUseCase ) : IsDisplayBubbleUseCase( - isQueueingOrEngagementUseCase, + isQueueingOrLiveEngagementUseCase, isCurrentEngagementCallVisualizerUseCase, screenSharingUseCase, permissionManager, diff --git a/widgetssdk/src/main/java/com/glia/widgets/core/chathead/domain/IsDisplayBubbleOutsideAppUseCase.kt b/widgetssdk/src/main/java/com/glia/widgets/core/chathead/domain/IsDisplayBubbleOutsideAppUseCase.kt index 14fe24056..0f1e6854b 100644 --- a/widgetssdk/src/main/java/com/glia/widgets/core/chathead/domain/IsDisplayBubbleOutsideAppUseCase.kt +++ b/widgetssdk/src/main/java/com/glia/widgets/core/chathead/domain/IsDisplayBubbleOutsideAppUseCase.kt @@ -4,7 +4,7 @@ import com.glia.widgets.core.chathead.ChatHeadManager import com.glia.widgets.core.permissions.PermissionManager import com.glia.widgets.engagement.domain.EngagementTypeUseCase import com.glia.widgets.engagement.domain.IsCurrentEngagementCallVisualizerUseCase -import com.glia.widgets.engagement.domain.IsQueueingOrEngagementUseCase +import com.glia.widgets.engagement.domain.IsQueueingOrLiveEngagementUseCase import com.glia.widgets.engagement.domain.ScreenSharingUseCase import com.glia.widgets.helper.Logger import com.glia.widgets.helper.TAG @@ -16,7 +16,7 @@ import com.glia.widgets.launcher.ConfigurationManager * 2) starts or stops the chat head service (bubble outside the app) */ internal class IsDisplayBubbleOutsideAppUseCase( - isQueueingOrEngagementUseCase: IsQueueingOrEngagementUseCase, + isQueueingOrLiveEngagementUseCase: IsQueueingOrLiveEngagementUseCase, isCurrentEngagementCallVisualizerUseCase: IsCurrentEngagementCallVisualizerUseCase, screenSharingUseCase: ScreenSharingUseCase, private val chatHeadManager: ChatHeadManager, @@ -24,7 +24,7 @@ internal class IsDisplayBubbleOutsideAppUseCase( configurationManager: ConfigurationManager, engagementTypeUseCase: EngagementTypeUseCase ) : IsDisplayBubbleUseCase( - isQueueingOrEngagementUseCase, + isQueueingOrLiveEngagementUseCase, isCurrentEngagementCallVisualizerUseCase, screenSharingUseCase, permissionManager, diff --git a/widgetssdk/src/main/java/com/glia/widgets/core/chathead/domain/IsDisplayBubbleUseCase.kt b/widgetssdk/src/main/java/com/glia/widgets/core/chathead/domain/IsDisplayBubbleUseCase.kt index f876a9ffa..8f04469a9 100644 --- a/widgetssdk/src/main/java/com/glia/widgets/core/chathead/domain/IsDisplayBubbleUseCase.kt +++ b/widgetssdk/src/main/java/com/glia/widgets/core/chathead/domain/IsDisplayBubbleUseCase.kt @@ -6,7 +6,7 @@ import com.glia.widgets.chat.ChatView import com.glia.widgets.core.permissions.PermissionManager import com.glia.widgets.engagement.domain.EngagementTypeUseCase import com.glia.widgets.engagement.domain.IsCurrentEngagementCallVisualizerUseCase -import com.glia.widgets.engagement.domain.IsQueueingOrEngagementUseCase +import com.glia.widgets.engagement.domain.IsQueueingOrLiveEngagementUseCase import com.glia.widgets.engagement.domain.ScreenSharingUseCase import com.glia.widgets.filepreview.ui.ImagePreviewView import com.glia.widgets.helper.DialogHolderView @@ -14,7 +14,7 @@ import com.glia.widgets.launcher.ConfigurationManager import com.glia.widgets.messagecenter.MessageCenterView internal abstract class IsDisplayBubbleUseCase( - private val isQueueingOrEngagementUseCase: IsQueueingOrEngagementUseCase, + private val isQueueingOrLiveEngagementUseCase: IsQueueingOrLiveEngagementUseCase, private val isCurrentEngagementCallVisualizerUseCase: IsCurrentEngagementCallVisualizerUseCase, private val screenSharingUseCase: ScreenSharingUseCase, val permissionManager: PermissionManager, @@ -60,8 +60,8 @@ internal abstract class IsDisplayBubbleUseCase( private val isChatEngagementOrQueueingOngoing: Boolean get() = isChatEngagementOngoing || isChatQueueingOngoing private val isMediaEngagementOrQueueingOngoing: Boolean get() = isMediaEngagementOngoing || isMediaQueueingOngoing - private val isMediaQueueingOngoing: Boolean get() = isQueueingOrEngagementUseCase.isQueueingForMedia + private val isMediaQueueingOngoing: Boolean get() = isQueueingOrLiveEngagementUseCase.isQueueingForMedia private val isMediaEngagementOngoing: Boolean get() = engagementTypeUseCase.isMediaEngagement - private val isChatQueueingOngoing: Boolean get() = isQueueingOrEngagementUseCase.isQueueingForChat + private val isChatQueueingOngoing: Boolean get() = isQueueingOrLiveEngagementUseCase.isQueueingForLiveChat private val isChatEngagementOngoing: Boolean get() = engagementTypeUseCase.isChatEngagement } diff --git a/widgetssdk/src/main/java/com/glia/widgets/core/chathead/domain/ResolveChatHeadNavigationUseCase.java b/widgetssdk/src/main/java/com/glia/widgets/core/chathead/domain/ResolveChatHeadNavigationUseCase.java index 94eaa3602..3bc196e1a 100644 --- a/widgetssdk/src/main/java/com/glia/widgets/core/chathead/domain/ResolveChatHeadNavigationUseCase.java +++ b/widgetssdk/src/main/java/com/glia/widgets/core/chathead/domain/ResolveChatHeadNavigationUseCase.java @@ -2,22 +2,22 @@ import com.glia.widgets.core.callvisualizer.domain.IsCallVisualizerScreenSharingUseCase; import com.glia.widgets.engagement.domain.EngagementTypeUseCase; -import com.glia.widgets.engagement.domain.IsQueueingOrEngagementUseCase; +import com.glia.widgets.engagement.domain.IsQueueingOrLiveEngagementUseCase; /** * @hide */ public class ResolveChatHeadNavigationUseCase { - private final IsQueueingOrEngagementUseCase isQueueingOrEngagementUseCase; + private final IsQueueingOrLiveEngagementUseCase isQueueingOrLiveEngagementUseCase; private final EngagementTypeUseCase engagementTypeUseCase; private final IsCallVisualizerScreenSharingUseCase isCallVisualizerScreenSharingUseCase; public ResolveChatHeadNavigationUseCase( - IsQueueingOrEngagementUseCase isQueueingOrEngagementUseCase, + IsQueueingOrLiveEngagementUseCase isQueueingOrLiveEngagementUseCase, EngagementTypeUseCase engagementTypeUseCase, IsCallVisualizerScreenSharingUseCase isCallVisualizerScreenSharingUseCase ) { - this.isQueueingOrEngagementUseCase = isQueueingOrEngagementUseCase; + this.isQueueingOrLiveEngagementUseCase = isQueueingOrLiveEngagementUseCase; this.engagementTypeUseCase = engagementTypeUseCase; this.isCallVisualizerScreenSharingUseCase = isCallVisualizerScreenSharingUseCase; } @@ -42,11 +42,11 @@ public enum Destinations { } private boolean isMediaQueueingOngoing() { - return isQueueingOrEngagementUseCase.isQueueingForMedia(); + return isQueueingOrLiveEngagementUseCase.isQueueingForMedia(); } private boolean isMediaEngagementOngoing() { - return isQueueingOrEngagementUseCase.getHasOngoingEngagement() && engagementTypeUseCase.isMediaEngagement(); + return isQueueingOrLiveEngagementUseCase.getHasOngoingLiveEngagement() && engagementTypeUseCase.isMediaEngagement(); } private boolean isSharingScreen() { diff --git a/widgetssdk/src/main/java/com/glia/widgets/core/engagement/domain/ShouldShowMediaEngagementViewUseCase.java b/widgetssdk/src/main/java/com/glia/widgets/core/engagement/domain/ShouldShowMediaEngagementViewUseCase.java index d6052e494..566627656 100644 --- a/widgetssdk/src/main/java/com/glia/widgets/core/engagement/domain/ShouldShowMediaEngagementViewUseCase.java +++ b/widgetssdk/src/main/java/com/glia/widgets/core/engagement/domain/ShouldShowMediaEngagementViewUseCase.java @@ -1,19 +1,19 @@ package com.glia.widgets.core.engagement.domain; import com.glia.widgets.engagement.domain.EngagementTypeUseCase; -import com.glia.widgets.engagement.domain.IsQueueingOrEngagementUseCase; +import com.glia.widgets.engagement.domain.IsQueueingOrLiveEngagementUseCase; /** * @hide */ public class ShouldShowMediaEngagementViewUseCase { - private final IsQueueingOrEngagementUseCase isQueueingOrEngagementUseCase; + private final IsQueueingOrLiveEngagementUseCase isQueueingOrLiveEngagementUseCase; private final EngagementTypeUseCase engagementTypeUseCase; public ShouldShowMediaEngagementViewUseCase( - IsQueueingOrEngagementUseCase isQueueingOrEngagementUseCase, + IsQueueingOrLiveEngagementUseCase isQueueingOrLiveEngagementUseCase, EngagementTypeUseCase engagementTypeUseCase) { - this.isQueueingOrEngagementUseCase = isQueueingOrEngagementUseCase; + this.isQueueingOrLiveEngagementUseCase = isQueueingOrLiveEngagementUseCase; this.engagementTypeUseCase = engagementTypeUseCase; } @@ -25,11 +25,11 @@ public boolean execute(boolean isUpgradeToCall) { } private boolean hasNoQueueingAndEngagementOngoing() { - return !isQueueingOrEngagementUseCase.invoke(); + return !isQueueingOrLiveEngagementUseCase.invoke(); } private boolean hasMediaQueueingOngoing() { - return isQueueingOrEngagementUseCase.isQueueingForMedia(); + return isQueueingOrLiveEngagementUseCase.isQueueingForMedia(); } private boolean hasOngoingMediaEngagement() { diff --git a/widgetssdk/src/main/java/com/glia/widgets/core/fileupload/domain/AddFileToAttachmentAndUploadUseCase.kt b/widgetssdk/src/main/java/com/glia/widgets/core/fileupload/domain/AddFileToAttachmentAndUploadUseCase.kt index 6d731437d..6b09cec3c 100644 --- a/widgetssdk/src/main/java/com/glia/widgets/core/fileupload/domain/AddFileToAttachmentAndUploadUseCase.kt +++ b/widgetssdk/src/main/java/com/glia/widgets/core/fileupload/domain/AddFileToAttachmentAndUploadUseCase.kt @@ -8,20 +8,16 @@ import com.glia.widgets.core.fileupload.exception.SupportedFileCountExceededExce import com.glia.widgets.core.fileupload.exception.SupportedFileSizeExceededException import com.glia.widgets.core.fileupload.model.LocalAttachment import com.glia.widgets.core.secureconversations.domain.ManageSecureMessagingStatusUseCase -import com.glia.widgets.engagement.domain.IsQueueingOrEngagementUseCase +import com.glia.widgets.engagement.domain.IsQueueingOrLiveEngagementUseCase internal class AddFileToAttachmentAndUploadUseCase( - private val isQueueingOrEngagementUseCase: IsQueueingOrEngagementUseCase, + private val isQueueingOrLiveEngagementUseCase: IsQueueingOrLiveEngagementUseCase, private val fileAttachmentRepository: FileAttachmentRepository, private val manageSecureMessagingStatusUseCase: ManageSecureMessagingStatusUseCase ) { private val isSupportedFileCountExceeded: Boolean get() = fileAttachmentRepository.attachedFilesCount > SupportedFileCountCheckUseCase.SUPPORTED_FILE_COUNT - private val hasNoOngoingEngagement: Boolean - get() = !isQueueingOrEngagementUseCase.hasOngoingEngagement - - fun execute(file: LocalAttachment, listener: Listener) { if (fileAttachmentRepository.isFileAttached(file.uri)) { listener.onError(RemoveBeforeReUploadingException()) @@ -32,11 +28,11 @@ internal class AddFileToAttachmentAndUploadUseCase( private fun onFileNotAttached(file: LocalAttachment, listener: Listener) { fileAttachmentRepository.attachFile(file) - if (hasNoOngoingEngagement && !manageSecureMessagingStatusUseCase.shouldUseSecureMessagingEndpoints()) { + if (isQueueingOrLiveEngagementUseCase.hasOngoingLiveEngagement || manageSecureMessagingStatusUseCase.shouldBehaveAsSecureMessaging) { + onHasOngoingOrSecureEngagement(file, listener) + } else { fileAttachmentRepository.setFileAttachmentEngagementMissing(file.uri) listener.onError(EngagementMissingException()) - } else { - onHasOngoingOrSecureEngagement(file, listener) } } @@ -49,7 +45,7 @@ internal class AddFileToAttachmentAndUploadUseCase( listener.onError(SupportedFileSizeExceededException()) } else { listener.onStarted() - fileAttachmentRepository.uploadFile(manageSecureMessagingStatusUseCase.shouldUseSecureMessagingEndpoints(), file, listener) + fileAttachmentRepository.uploadFile(manageSecureMessagingStatusUseCase.shouldUseSecureMessagingEndpoints, file, listener) } } diff --git a/widgetssdk/src/main/java/com/glia/widgets/core/secureconversations/domain/IsMessagingAvailableUseCase.kt b/widgetssdk/src/main/java/com/glia/widgets/core/secureconversations/domain/IsMessagingAvailableUseCase.kt index 321d0c5da..0d4663d19 100644 --- a/widgetssdk/src/main/java/com/glia/widgets/core/secureconversations/domain/IsMessagingAvailableUseCase.kt +++ b/widgetssdk/src/main/java/com/glia/widgets/core/secureconversations/domain/IsMessagingAvailableUseCase.kt @@ -4,19 +4,22 @@ import com.glia.androidsdk.queuing.Queue import com.glia.androidsdk.queuing.QueueState import com.glia.widgets.core.queue.QueueRepository import com.glia.widgets.core.queue.QueuesState +import com.glia.widgets.engagement.EngagementRepository +import com.glia.widgets.engagement.State import com.glia.widgets.helper.supportMessaging import io.reactivex.rxjava3.core.Flowable -internal class IsMessagingAvailableUseCase(private val queueRepository: QueueRepository) { +internal class IsMessagingAvailableUseCase(private val queueRepository: QueueRepository, private val engagementRepository: EngagementRepository) { - operator fun invoke(): Flowable> = queueRepository.queuesState - .filter { it !is QueuesState.Loading } - .map { mapResult(it) } - .distinctUntilChanged() + operator fun invoke(): Flowable> = + Flowable.combineLatest(queueRepository.queuesState, engagementRepository.engagementState) { queueState, engagementState -> + mapResult(queueState, engagementState) + }.distinctUntilChanged() - private fun mapResult(queueMonitorState: QueuesState): Result = when (queueMonitorState) { - is QueuesState.Error -> Result.failure(queueMonitorState.error) - is QueuesState.Queues -> Result.success(isMessagingAvailable(queueMonitorState.queues)) + private fun mapResult(queuesState: QueuesState, engagementState: State): Result = when { + engagementState is State.TransferredToSecureConversation -> Result.success(true) + queuesState is QueuesState.Queues -> Result.success(isMessagingAvailable(queuesState.queues)) + queuesState is QueuesState.Error -> Result.failure(queuesState.error) else -> Result.success(false) } diff --git a/widgetssdk/src/main/java/com/glia/widgets/core/secureconversations/domain/ManageSecureMessagingStatusUseCase.kt b/widgetssdk/src/main/java/com/glia/widgets/core/secureconversations/domain/ManageSecureMessagingStatusUseCase.kt index 065aef358..733bca6a7 100644 --- a/widgetssdk/src/main/java/com/glia/widgets/core/secureconversations/domain/ManageSecureMessagingStatusUseCase.kt +++ b/widgetssdk/src/main/java/com/glia/widgets/core/secureconversations/domain/ManageSecureMessagingStatusUseCase.kt @@ -1,21 +1,16 @@ package com.glia.widgets.core.secureconversations.domain import com.glia.widgets.engagement.EngagementRepository -import com.glia.widgets.engagement.domain.IsQueueingOrEngagementUseCase -internal class ManageSecureMessagingStatusUseCase( - private val isQueueingOrEngagementUseCase: IsQueueingOrEngagementUseCase, - private val engagementRepository: EngagementRepository -) { - //TODO this function should be changed for GVA -> SC transfer - fun shouldUseSecureMessagingEndpoints(): Boolean { - return engagementRepository.isSecureMessagingRequested && !isQueueingOrEngagementUseCase() - } +internal class ManageSecureMessagingStatusUseCase(private val engagementRepository: EngagementRepository) { - //TODO this function should be changed for GVA -> SC transfer - fun shouldBehaveAsSecureMessaging(): Boolean { - return engagementRepository.isSecureMessagingRequested - } + val shouldUseSecureMessagingEndpoints: Boolean + get() = engagementRepository.isSecureMessagingRequested + && !engagementRepository.isQueueingOrLiveEngagement + && !engagementRepository.isTransferredSecureConversation + + val shouldBehaveAsSecureMessaging: Boolean + get() = engagementRepository.isSecureMessagingRequested || engagementRepository.isTransferredSecureConversation fun updateSecureMessagingStatus(isRequested: Boolean) = engagementRepository.updateIsSecureMessagingRequested(isRequested) } diff --git a/widgetssdk/src/main/java/com/glia/widgets/core/secureconversations/domain/SendSecureMessageUseCase.kt b/widgetssdk/src/main/java/com/glia/widgets/core/secureconversations/domain/SendSecureMessageUseCase.kt index 1ee0437ea..1d03760d3 100644 --- a/widgetssdk/src/main/java/com/glia/widgets/core/secureconversations/domain/SendSecureMessageUseCase.kt +++ b/widgetssdk/src/main/java/com/glia/widgets/core/secureconversations/domain/SendSecureMessageUseCase.kt @@ -9,18 +9,18 @@ import com.glia.widgets.core.fileupload.SecureFileAttachmentRepository import com.glia.widgets.core.fileupload.model.LocalAttachment import com.glia.widgets.core.secureconversations.SecureConversationsRepository import com.glia.widgets.core.secureconversations.SendMessageRepository -import com.glia.widgets.engagement.domain.IsQueueingOrEngagementUseCase +import com.glia.widgets.engagement.domain.IsQueueingOrLiveEngagementUseCase internal class SendSecureMessageUseCase( private val sendMessageRepository: SendMessageRepository, private val secureConversationsRepository: SecureConversationsRepository, private val fileAttachmentRepository: SecureFileAttachmentRepository, private val chatRepository: GliaChatRepository, - private val isQueueingOrEngagementUseCase: IsQueueingOrEngagementUseCase + private val isQueueingOrLiveEngagementUseCase: IsQueueingOrLiveEngagementUseCase ) { private val hasOngoingEngagement: Boolean - get() = isQueueingOrEngagementUseCase.hasOngoingEngagement + get() = isQueueingOrLiveEngagementUseCase.hasOngoingLiveEngagement operator fun invoke( callback: RequestCallback diff --git a/widgetssdk/src/main/java/com/glia/widgets/di/ManagerFactory.kt b/widgetssdk/src/main/java/com/glia/widgets/di/ManagerFactory.kt index 7bc36f103..4abce5d23 100644 --- a/widgetssdk/src/main/java/com/glia/widgets/di/ManagerFactory.kt +++ b/widgetssdk/src/main/java/com/glia/widgets/di/ManagerFactory.kt @@ -15,7 +15,7 @@ internal class ManagerFactory(private val useCaseFactory: UseCaseFactory) { sendUnsentMessagesUseCase = createSendUnsentMessagesUseCase(), handleCustomCardClickUseCase = createHandleCustomCardClickUseCase(), isAuthenticatedUseCase = createIsAuthenticatedUseCase(), - isQueueingOrEngagementUseCase = isQueueingOrEngagementUseCase + isQueueingOrLiveEngagementUseCase = isQueueingOrEngagementUseCase ) } } diff --git a/widgetssdk/src/main/java/com/glia/widgets/di/UseCaseFactory.java b/widgetssdk/src/main/java/com/glia/widgets/di/UseCaseFactory.java index 0bb525c41..e3644a091 100644 --- a/widgetssdk/src/main/java/com/glia/widgets/di/UseCaseFactory.java +++ b/widgetssdk/src/main/java/com/glia/widgets/di/UseCaseFactory.java @@ -148,8 +148,8 @@ import com.glia.widgets.engagement.domain.IsCurrentEngagementCallVisualizerUseCaseImpl; import com.glia.widgets.engagement.domain.IsOperatorPresentUseCase; import com.glia.widgets.engagement.domain.IsOperatorPresentUseCaseImpl; -import com.glia.widgets.engagement.domain.IsQueueingOrEngagementUseCase; -import com.glia.widgets.engagement.domain.IsQueueingOrEngagementUseCaseImpl; +import com.glia.widgets.engagement.domain.IsQueueingOrLiveEngagementUseCase; +import com.glia.widgets.engagement.domain.IsQueueingOrLiveEngagementUseCaseImpl; import com.glia.widgets.engagement.domain.OnIncomingEngagementRequestTimeoutUseCase; import com.glia.widgets.engagement.domain.OnIncomingEngagementRequestTimeoutUseCaseImpl; import com.glia.widgets.engagement.domain.OperatorMediaUpgradeOfferUseCase; @@ -585,7 +585,7 @@ public RemoveSecureFileAttachmentUseCase createRemoveSecureFileAttachmentUseCase @NonNull public ManageSecureMessagingStatusUseCase createManageSecureMessagingStatusUseCase() { - return new ManageSecureMessagingStatusUseCase(getIsQueueingOrEngagementUseCase(), repositoryFactory.getEngagementRepository()); + return new ManageSecureMessagingStatusUseCase(repositoryFactory.getEngagementRepository()); } @NonNull @@ -595,7 +595,7 @@ public IsAuthenticatedUseCase createIsAuthenticatedUseCase() { @NonNull public IsMessagingAvailableUseCase createIsMessagingAvailableUseCase() { - return new IsMessagingAvailableUseCase(repositoryFactory.getQueueRepository()); + return new IsMessagingAvailableUseCase(repositoryFactory.getQueueRepository(), repositoryFactory.getEngagementRepository()); } @NonNull @@ -871,8 +871,8 @@ public EndEngagementUseCase getEndEngagementUseCase() { } @NonNull - public IsQueueingOrEngagementUseCase getIsQueueingOrEngagementUseCase() { - return new IsQueueingOrEngagementUseCaseImpl(repositoryFactory.getEngagementRepository()); + public IsQueueingOrLiveEngagementUseCase getIsQueueingOrEngagementUseCase() { + return new IsQueueingOrLiveEngagementUseCaseImpl(repositoryFactory.getEngagementRepository()); } @NonNull diff --git a/widgetssdk/src/main/java/com/glia/widgets/engagement/EngagementRepository.kt b/widgetssdk/src/main/java/com/glia/widgets/engagement/EngagementRepository.kt index 6a8395e05..1fdeb835f 100644 --- a/widgetssdk/src/main/java/com/glia/widgets/engagement/EngagementRepository.kt +++ b/widgetssdk/src/main/java/com/glia/widgets/engagement/EngagementRepository.kt @@ -31,8 +31,9 @@ internal interface EngagementRepository { val visitorCameraState: Flowable val currentOperatorValue: Operator? - val isQueueingOrEngagement: Boolean - val hasOngoingEngagement: Boolean + val isQueueingOrLiveEngagement: Boolean + val hasOngoingLiveEngagement: Boolean + val isTransferredSecureConversation: Boolean val isQueueing: Boolean val isQueueingForMedia: Boolean val isCallVisualizerEngagement: Boolean diff --git a/widgetssdk/src/main/java/com/glia/widgets/engagement/EngagementRepositoryImpl.kt b/widgetssdk/src/main/java/com/glia/widgets/engagement/EngagementRepositoryImpl.kt index fc5d15c89..ed4bc453d 100644 --- a/widgetssdk/src/main/java/com/glia/widgets/engagement/EngagementRepositoryImpl.kt +++ b/widgetssdk/src/main/java/com/glia/widgets/engagement/EngagementRepositoryImpl.kt @@ -78,13 +78,13 @@ internal class EngagementRepositoryImpl( private val queueTicketCallback = Consumer(::handleQueueTicket) private val _engagementState: BehaviorProcessor = BehaviorProcessor.createDefault(State.NoEngagement) - override val engagementState: Flowable = _engagementState.onBackpressureBuffer() + override val engagementState: Flowable = _engagementState.onBackpressureBuffer().distinctUntilChanged() private val _survey: PublishProcessor = PublishProcessor.create() override val survey: Flowable = _survey private val _currentOperator: BehaviorProcessor> = BehaviorProcessor.createDefault(Data.Empty) - override val currentOperator: Flowable> = _currentOperator.onBackpressureLatest() + override val currentOperator: Flowable> = _currentOperator.onBackpressureLatest().distinctUntilChanged() override val currentOperatorValue: Operator? get() = with(_currentOperator.value as? Data.Value) { this?.result } override val isOperatorPresent: Boolean get() = currentOperatorValue != null private val currentState: State? get() = _engagementState.value @@ -139,19 +139,23 @@ internal class EngagementRepositoryImpl( private val queueIngDisposable = CompositeDisposable() - override val hasOngoingEngagement: Boolean - get() = currentEngagement != null + override val hasOngoingLiveEngagement: Boolean + get() = currentEngagement != null && currentState?.isLiveEngagement == true + + override val isTransferredSecureConversation: Boolean + get() = currentState is State.TransferredToSecureConversation override val isQueueing: Boolean - get() = currentState is State.Queuing || currentState is State.PreQueuing + get() = currentState?.isQueueing == true + override val isQueueingForMedia: Boolean get() = currentState?.queueingMediaType?.isAudioOrVideo() == true override val isCallVisualizerEngagement: Boolean get() = currentEngagement is OmnibrowseEngagement - override val isQueueingOrEngagement: Boolean - get() = isQueueing || hasOngoingEngagement + override val isQueueingOrLiveEngagement: Boolean + get() = isQueueing || hasOngoingLiveEngagement override val isSharingScreen: Boolean get() = currentEngagement != null && _screenSharingState.run { value == ScreenSharingState.Started || value == ScreenSharingState.RequestAccepted } @@ -212,7 +216,7 @@ internal class EngagementRepositoryImpl( } override fun queueForEngagement(mediaType: MediaType) { - if (isQueueingOrEngagement) return + if (isQueueingOrLiveEngagement) return _engagementState.onNext(State.PreQueuing(mediaType)) @@ -385,14 +389,22 @@ internal class EngagementRepositoryImpl( private fun handleOmniCoreEngagement(engagement: OmnicoreEngagement) { Logger.i(TAG, "Omnicore Engagement started") - currentEngagement?.also { - unsubscribeFromEvents(it) - currentEngagement = null - resetState() - } ?: _engagementState.onNext(State.StartedOmniCore) + when { + currentEngagement != null -> { + unsubscribeFromEvents(currentEngagement!!) + currentEngagement = null + resetState() + } + + engagement.state.visitorStatus == EngagementState.VisitorStatus.TRANSFERRING && engagement.state.capabilities.isText -> { + _engagementState.onNext(State.TransferredToSecureConversation) + } + + else -> _engagementState.onNext(State.StartedOmniCore) + } currentEngagement = engagement - operatorRepository.emit(engagement.state.operator) + handleEngagementState(engagement.state) subscribeToEngagementEvents(engagement) subscribeToEngagementMediaEvents(engagement.media) @@ -411,7 +423,7 @@ internal class EngagementRepositoryImpl( } ?: _engagementState.onNext(State.StartedCallVisualizer) currentEngagement = engagement - operatorRepository.emit(engagement.state.operator) + handleEngagementState(engagement.state) subscribeToEngagementEvents(engagement) subscribeToEngagementMediaEvents(engagement.media) @@ -474,29 +486,36 @@ internal class EngagementRepositoryImpl( } private fun handleEngagementState(state: EngagementState) { + // keeping the current operator value, to use inside this function, + // because in some cases we need to globally have up to date operator before emitting new state + val currentOperator: Operator? = currentOperatorValue + operatorRepository.emit(state.operator) + _currentOperator.onNext(Data.Value(state.operator)) + + when { + state.visitorStatus == EngagementState.VisitorStatus.TRANSFERRING && state.capabilities.isText -> { + Logger.i(TAG, "Transfer to Secure Conversation") + _engagementState.onNext(State.TransferredToSecureConversation) + } - val updateState = when { state.visitorStatus == EngagementState.VisitorStatus.TRANSFERRING -> { Logger.i(TAG, "Transfer engagement") - EngagementUpdateState.Transferring + _engagementState.onNext(State.Update(state, EngagementUpdateState.Transferring)) } - !isOperatorPresent -> { + currentOperator == null -> { Logger.i(TAG, "Operator connected") - EngagementUpdateState.OperatorConnected(state.operator) + _engagementState.onNext(State.Update(state, EngagementUpdateState.OperatorConnected(state.operator))) } - currentOperatorValue?.id != state.operator.id -> { + currentOperator.id != state.operator.id -> { Logger.i(TAG, "Operator changed") - EngagementUpdateState.OperatorChanged(state.operator) + _engagementState.onNext(State.Update(state, EngagementUpdateState.OperatorChanged(state.operator))) } - else -> EngagementUpdateState.Ongoing(state.operator) + currentOperator != state.operator -> _engagementState.onNext(State.Update(state, EngagementUpdateState.Ongoing(state.operator))) } - _currentOperator.onNext(Data.Value(state.operator)) - - _engagementState.onNext(State.Update(state, updateState)) } private fun handleEngagementEnd() { diff --git a/widgetssdk/src/main/java/com/glia/widgets/engagement/States.kt b/widgetssdk/src/main/java/com/glia/widgets/engagement/States.kt index e25f978bd..e3d27ee4a 100644 --- a/widgetssdk/src/main/java/com/glia/widgets/engagement/States.kt +++ b/widgetssdk/src/main/java/com/glia/widgets/engagement/States.kt @@ -16,8 +16,18 @@ internal sealed interface State { data object StartedCallVisualizer : State data object FinishedOmniCore : State data object FinishedCallVisualizer : State + data object TransferredToSecureConversation : State data class Update(val state: EngagementState, val updateState: EngagementUpdateState) : State + val isQueueing: Boolean + get() = this is Queuing || this is PreQueuing + + val isLiveEngagement: Boolean + get() = when (this) { + is Update, StartedOmniCore, StartedCallVisualizer -> true + else -> false + } + val queueingMediaType: MediaType? get() = when (this) { is PreQueuing -> mediaType diff --git a/widgetssdk/src/main/java/com/glia/widgets/engagement/domain/EngagementTypeUseCase.kt b/widgetssdk/src/main/java/com/glia/widgets/engagement/domain/EngagementTypeUseCase.kt index adbac140f..161267415 100644 --- a/widgetssdk/src/main/java/com/glia/widgets/engagement/domain/EngagementTypeUseCase.kt +++ b/widgetssdk/src/main/java/com/glia/widgets/engagement/domain/EngagementTypeUseCase.kt @@ -7,13 +7,13 @@ internal interface EngagementTypeUseCase { } internal class EngagementTypeUseCaseImpl( - private val isQueueingOrEngagementUseCase: IsQueueingOrEngagementUseCase, + private val isQueueingOrLiveEngagementUseCase: IsQueueingOrLiveEngagementUseCase, private val isCurrentEngagementCallVisualizerUseCase: IsCurrentEngagementCallVisualizerUseCase, private val operatorMediaUseCase: OperatorMediaUseCase, private val visitorMediaUseCase: VisitorMediaUseCase, private val isOperatorPresentUseCase: IsOperatorPresentUseCase ) : EngagementTypeUseCase { - private val hasOngoingEngagement get() = isQueueingOrEngagementUseCase.hasOngoingEngagement + private val hasOngoingEngagement get() = isQueueingOrLiveEngagementUseCase.hasOngoingLiveEngagement private val hasAnyMedia: Boolean get() = visitorMediaUseCase.hasMedia || operatorMediaUseCase.hasMedia override val isMediaEngagement: Boolean get() = hasOngoingEngagement && isOperatorPresentUseCase() && hasAnyMedia override val isChatEngagement: Boolean get() = hasOngoingEngagement && !isCurrentEngagementCallVisualizerUseCase() && isOperatorPresentUseCase() && !hasAnyMedia diff --git a/widgetssdk/src/main/java/com/glia/widgets/engagement/domain/IsQueueingOrEngagementUseCase.kt b/widgetssdk/src/main/java/com/glia/widgets/engagement/domain/IsQueueingOrEngagementUseCase.kt deleted file mode 100644 index 0954604f2..000000000 --- a/widgetssdk/src/main/java/com/glia/widgets/engagement/domain/IsQueueingOrEngagementUseCase.kt +++ /dev/null @@ -1,17 +0,0 @@ -package com.glia.widgets.engagement.domain - -import com.glia.widgets.engagement.EngagementRepository - -internal interface IsQueueingOrEngagementUseCase { - val hasOngoingEngagement: Boolean - val isQueueingForMedia: Boolean - val isQueueingForChat: Boolean - operator fun invoke(): Boolean -} - -internal class IsQueueingOrEngagementUseCaseImpl(private val engagementRepository: EngagementRepository) : IsQueueingOrEngagementUseCase { - override val hasOngoingEngagement: Boolean get() = engagementRepository.hasOngoingEngagement - override val isQueueingForMedia: Boolean get() = engagementRepository.isQueueingForMedia - override val isQueueingForChat: Boolean get() = engagementRepository.isQueueing && !isQueueingForMedia - override fun invoke(): Boolean = engagementRepository.isQueueingOrEngagement -} diff --git a/widgetssdk/src/main/java/com/glia/widgets/engagement/domain/IsQueueingOrLiveEngagementUseCase.kt b/widgetssdk/src/main/java/com/glia/widgets/engagement/domain/IsQueueingOrLiveEngagementUseCase.kt new file mode 100644 index 000000000..61f017685 --- /dev/null +++ b/widgetssdk/src/main/java/com/glia/widgets/engagement/domain/IsQueueingOrLiveEngagementUseCase.kt @@ -0,0 +1,17 @@ +package com.glia.widgets.engagement.domain + +import com.glia.widgets.engagement.EngagementRepository + +internal interface IsQueueingOrLiveEngagementUseCase { + val hasOngoingLiveEngagement: Boolean + val isQueueingForMedia: Boolean + val isQueueingForLiveChat: Boolean + operator fun invoke(): Boolean +} + +internal class IsQueueingOrLiveEngagementUseCaseImpl(private val engagementRepository: EngagementRepository) : IsQueueingOrLiveEngagementUseCase { + override val hasOngoingLiveEngagement: Boolean get() = engagementRepository.hasOngoingLiveEngagement + override val isQueueingForMedia: Boolean get() = engagementRepository.isQueueingForMedia + override val isQueueingForLiveChat: Boolean get() = engagementRepository.isQueueing && !isQueueingForMedia + override fun invoke(): Boolean = engagementRepository.isQueueingOrLiveEngagement +} diff --git a/widgetssdk/src/main/java/com/glia/widgets/filepreview/domain/usecase/DownloadFileUseCase.kt b/widgetssdk/src/main/java/com/glia/widgets/filepreview/domain/usecase/DownloadFileUseCase.kt index a45d42f76..fada0ad3f 100644 --- a/widgetssdk/src/main/java/com/glia/widgets/filepreview/domain/usecase/DownloadFileUseCase.kt +++ b/widgetssdk/src/main/java/com/glia/widgets/filepreview/domain/usecase/DownloadFileUseCase.kt @@ -14,6 +14,6 @@ internal class DownloadFileUseCase( operator fun invoke(file: AttachmentFile): Completable = when { file.name.isEmpty() -> Completable.error(FileNameMissingException()) file.isDeleted -> Completable.error(RemoteFileIsDeletedException()) - else -> fileRepository.downloadFileFromNetwork(manageSecureMessagingStatusUseCase.shouldUseSecureMessagingEndpoints(), file) + else -> fileRepository.downloadFileFromNetwork(manageSecureMessagingStatusUseCase.shouldUseSecureMessagingEndpoints, file) } } diff --git a/widgetssdk/src/main/java/com/glia/widgets/filepreview/domain/usecase/GetImageFileFromNetworkUseCase.kt b/widgetssdk/src/main/java/com/glia/widgets/filepreview/domain/usecase/GetImageFileFromNetworkUseCase.kt index c27ff68be..6a661f29d 100644 --- a/widgetssdk/src/main/java/com/glia/widgets/filepreview/domain/usecase/GetImageFileFromNetworkUseCase.kt +++ b/widgetssdk/src/main/java/com/glia/widgets/filepreview/domain/usecase/GetImageFileFromNetworkUseCase.kt @@ -18,7 +18,7 @@ internal class GetImageFileFromNetworkUseCase( operator fun invoke(file: AttachmentFile?): Maybe = when { file?.name.isNullOrBlank() -> Maybe.error(FileNameMissingException()) file!!.isDeleted -> Maybe.error(RemoteFileIsDeletedException()) - else -> gliaFileRepository.loadImageFileFromNetwork(manageSecureMessagingStatusUseCase.shouldUseSecureMessagingEndpoints(), file) + else -> gliaFileRepository.loadImageFileFromNetwork(manageSecureMessagingStatusUseCase.shouldUseSecureMessagingEndpoints, file) .flatMap { decodeSampledBitmapFromInputStreamUseCase(it) } .doOnSuccess { gliaFileRepository.putImageToCache(file.fileName, it) } } diff --git a/widgetssdk/src/main/java/com/glia/widgets/helper/Data.kt b/widgetssdk/src/main/java/com/glia/widgets/helper/Data.kt index 91f556875..95ef18b7d 100644 --- a/widgetssdk/src/main/java/com/glia/widgets/helper/Data.kt +++ b/widgetssdk/src/main/java/com/glia/widgets/helper/Data.kt @@ -5,7 +5,7 @@ internal sealed class Data { val valueOrNull: T? get() = (this as? Value)?.result data class Value(val result: T) : Data() - object Empty : Data() + data object Empty : Data() companion object } diff --git a/widgetssdk/src/test/java/com/glia/widgets/callvisualizer/controller/VisitorCodeControllerTest.kt b/widgetssdk/src/test/java/com/glia/widgets/callvisualizer/controller/VisitorCodeControllerTest.kt index 1a1c975ba..3c11fcc51 100644 --- a/widgetssdk/src/test/java/com/glia/widgets/callvisualizer/controller/VisitorCodeControllerTest.kt +++ b/widgetssdk/src/test/java/com/glia/widgets/callvisualizer/controller/VisitorCodeControllerTest.kt @@ -5,7 +5,7 @@ import com.glia.widgets.callvisualizer.VisitorCodeContract import com.glia.widgets.core.callvisualizer.domain.VisitorCodeRepository import com.glia.widgets.engagement.State import com.glia.widgets.engagement.domain.EngagementStateUseCase -import com.glia.widgets.engagement.domain.IsQueueingOrEngagementUseCase +import com.glia.widgets.engagement.domain.IsQueueingOrLiveEngagementUseCase import io.reactivex.rxjava3.android.plugins.RxAndroidPlugins import io.reactivex.rxjava3.core.Observable import io.reactivex.rxjava3.plugins.RxJavaPlugins @@ -27,11 +27,11 @@ internal class VisitorCodeControllerTest { private val engagementStateUseCase: EngagementStateUseCase = org.mockito.kotlin.mock { on { invoke() } doReturn engagementState } - private val isQueueingOrEngagementUseCase: IsQueueingOrEngagementUseCase = mock() + private val isQueueingOrLiveEngagementUseCase: IsQueueingOrLiveEngagementUseCase = mock() private val callVisualizerController: CallVisualizerContract.Controller = mock() private val visitorCodeRepository: VisitorCodeRepository = mock() private val controller = - VisitorCodeController(callVisualizerController, visitorCodeRepository, engagementStateUseCase, isQueueingOrEngagementUseCase) + VisitorCodeController(callVisualizerController, visitorCodeRepository, engagementStateUseCase, isQueueingOrLiveEngagementUseCase) private val view: VisitorCodeContract.View = mock() private val refreshTime = 1000L diff --git a/widgetssdk/src/test/java/com/glia/widgets/chat/ChatManagerTest.kt b/widgetssdk/src/test/java/com/glia/widgets/chat/ChatManagerTest.kt index ca5ccb233..ee9113d82 100644 --- a/widgetssdk/src/test/java/com/glia/widgets/chat/ChatManagerTest.kt +++ b/widgetssdk/src/test/java/com/glia/widgets/chat/ChatManagerTest.kt @@ -33,7 +33,7 @@ import com.glia.widgets.chat.model.VisitorMessageItem import com.glia.widgets.core.engagement.domain.model.ChatHistoryResponse import com.glia.widgets.core.engagement.domain.model.ChatMessageInternal import com.glia.widgets.core.secureconversations.domain.MarkMessagesReadWithDelayUseCase -import com.glia.widgets.engagement.domain.IsQueueingOrEngagementUseCase +import com.glia.widgets.engagement.domain.IsQueueingOrLiveEngagementUseCase import io.reactivex.rxjava3.android.plugins.RxAndroidPlugins import io.reactivex.rxjava3.core.Completable import io.reactivex.rxjava3.core.Observable @@ -76,7 +76,7 @@ class ChatManagerTest { private lateinit var sendUnsentMessagesUseCase: SendUnsentMessagesUseCase private lateinit var handleCustomCardClickUseCase: HandleCustomCardClickUseCase private lateinit var isAuthenticatedUseCase: IsAuthenticatedUseCase - private lateinit var isQueueingOrEngagementUseCase: IsQueueingOrEngagementUseCase + private lateinit var isQueueingOrLiveEngagementUseCase: IsQueueingOrLiveEngagementUseCase private lateinit var subjectUnderTest: ChatManager private lateinit var state: ChatManager.State private lateinit var compositeDisposable: CompositeDisposable @@ -98,7 +98,7 @@ class ChatManagerTest { sendUnsentMessagesUseCase = mock() handleCustomCardClickUseCase = mock() isAuthenticatedUseCase = mock() - isQueueingOrEngagementUseCase = mock() + isQueueingOrLiveEngagementUseCase = mock() compositeDisposable = spy() stateProcessor = BehaviorProcessor.createDefault(state) quickReplies = BehaviorProcessor.create() @@ -115,7 +115,7 @@ class ChatManagerTest { sendUnsentMessagesUseCase, handleCustomCardClickUseCase, isAuthenticatedUseCase, - isQueueingOrEngagementUseCase, + isQueueingOrLiveEngagementUseCase, compositeDisposable, stateProcessor, quickReplies, @@ -690,7 +690,7 @@ class ChatManagerTest { @Test fun `loadHistory loads history when authenticated`() { whenever(isAuthenticatedUseCase()) doReturn true - whenever(isQueueingOrEngagementUseCase.hasOngoingEngagement) doReturn false + whenever(isQueueingOrLiveEngagementUseCase.hasOngoingLiveEngagement) doReturn false whenever(loadHistoryUseCase()) doReturn Single.just(mock()) @@ -710,7 +710,7 @@ class ChatManagerTest { @Test fun `loadHistory loads history when engagement is ongoing`() { whenever(isAuthenticatedUseCase()) doReturn false - whenever(isQueueingOrEngagementUseCase.hasOngoingEngagement) doReturn true + whenever(isQueueingOrLiveEngagementUseCase.hasOngoingLiveEngagement) doReturn true whenever(loadHistoryUseCase()) doReturn Single.just(mock()) @@ -730,7 +730,7 @@ class ChatManagerTest { @Test fun `loadHistory skips history when there is no ongoing engagement and not authenticated`() { whenever(isAuthenticatedUseCase()) doReturn false - whenever(isQueueingOrEngagementUseCase.hasOngoingEngagement) doReturn false + whenever(isQueueingOrLiveEngagementUseCase.hasOngoingLiveEngagement) doReturn false whenever(loadHistoryUseCase()) doReturn Single.just(mock()) diff --git a/widgetssdk/src/test/java/com/glia/widgets/chat/controller/ChatControllerTest.kt b/widgetssdk/src/test/java/com/glia/widgets/chat/controller/ChatControllerTest.kt index 98e599c8a..d74a9a9ba 100644 --- a/widgetssdk/src/test/java/com/glia/widgets/chat/controller/ChatControllerTest.kt +++ b/widgetssdk/src/test/java/com/glia/widgets/chat/controller/ChatControllerTest.kt @@ -46,7 +46,7 @@ import com.glia.widgets.engagement.domain.EndEngagementUseCase import com.glia.widgets.engagement.domain.EngagementStateUseCase import com.glia.widgets.engagement.domain.EnqueueForEngagementUseCase import com.glia.widgets.engagement.domain.IsCurrentEngagementCallVisualizerUseCase -import com.glia.widgets.engagement.domain.IsQueueingOrEngagementUseCase +import com.glia.widgets.engagement.domain.IsQueueingOrLiveEngagementUseCase import com.glia.widgets.engagement.domain.OperatorMediaUseCase import com.glia.widgets.engagement.domain.OperatorTypingUseCase import com.glia.widgets.engagement.domain.ReleaseResourcesUseCase @@ -113,7 +113,7 @@ class ChatControllerTest { private lateinit var operatorMediaUseCase: OperatorMediaUseCase private lateinit var acceptMediaUpgradeOfferUseCase: AcceptMediaUpgradeOfferUseCase private lateinit var declineMediaUpgradeOfferUseCase: DeclineMediaUpgradeOfferUseCase - private lateinit var isQueueingOrEngagementUseCase: IsQueueingOrEngagementUseCase + private lateinit var isQueueingOrLiveEngagementUseCase: IsQueueingOrLiveEngagementUseCase private lateinit var enqueueForEngagementUseCase: EnqueueForEngagementUseCase private lateinit var decideOnQueueingUseCase: DecideOnQueueingUseCase private lateinit var screenSharingUseCase: ScreenSharingUseCase @@ -177,7 +177,7 @@ class ChatControllerTest { } acceptMediaUpgradeOfferUseCase = mock() declineMediaUpgradeOfferUseCase = mock() - isQueueingOrEngagementUseCase = mock() + isQueueingOrLiveEngagementUseCase = mock() enqueueForEngagementUseCase = mock() chatView = mock() decideOnQueueingUseCase = mock { @@ -234,7 +234,7 @@ class ChatControllerTest { engagementStateUseCase = engagementStateUseCase, operatorMediaUseCase = operatorMediaUseCase, acceptMediaUpgradeOfferUseCase = acceptMediaUpgradeOfferUseCase, - isQueueingOrEngagementUseCase = isQueueingOrEngagementUseCase, + isQueueingOrLiveEngagementUseCase = isQueueingOrLiveEngagementUseCase, enqueueForEngagementUseCase = enqueueForEngagementUseCase, decideOnQueueingUseCase = decideOnQueueingUseCase, screenSharingUseCase = screenSharingUseCase, diff --git a/widgetssdk/src/test/java/com/glia/widgets/chat/domain/IsShowSendButtonUseCaseTest.kt b/widgetssdk/src/test/java/com/glia/widgets/chat/domain/IsShowSendButtonUseCaseTest.kt index b5d6588b6..1e660c9f0 100644 --- a/widgetssdk/src/test/java/com/glia/widgets/chat/domain/IsShowSendButtonUseCaseTest.kt +++ b/widgetssdk/src/test/java/com/glia/widgets/chat/domain/IsShowSendButtonUseCaseTest.kt @@ -2,7 +2,7 @@ package com.glia.widgets.chat.domain import com.glia.widgets.core.fileupload.FileAttachmentRepository import com.glia.widgets.core.secureconversations.domain.ManageSecureMessagingStatusUseCase -import com.glia.widgets.engagement.domain.IsQueueingOrEngagementUseCase +import com.glia.widgets.engagement.domain.IsQueueingOrLiveEngagementUseCase import org.junit.Assert.assertFalse import org.junit.Assert.assertTrue import org.junit.Before @@ -12,7 +12,7 @@ import org.mockito.kotlin.mock import org.mockito.kotlin.whenever class IsShowSendButtonUseCaseTest { - private lateinit var isQueueingOrEngagementUseCase: IsQueueingOrEngagementUseCase + private lateinit var isQueueingOrLiveEngagementUseCase: IsQueueingOrLiveEngagementUseCase private lateinit var fileAttachmentRepository: FileAttachmentRepository private lateinit var manageSecureMessagingStatusUseCase: ManageSecureMessagingStatusUseCase @@ -20,12 +20,12 @@ class IsShowSendButtonUseCaseTest { @Before fun setUp() { - isQueueingOrEngagementUseCase = mock() + isQueueingOrLiveEngagementUseCase = mock() fileAttachmentRepository = mock() manageSecureMessagingStatusUseCase = mock() useCase = IsShowSendButtonUseCase( - isQueueingOrEngagementUseCase, + isQueueingOrLiveEngagementUseCase, fileAttachmentRepository, manageSecureMessagingStatusUseCase ) @@ -33,7 +33,7 @@ class IsShowSendButtonUseCaseTest { @Test fun `invoke returns false if ongoing engagement and the message empty and files are not ready to send`() { - whenever(isQueueingOrEngagementUseCase.hasOngoingEngagement) doReturn true + whenever(isQueueingOrLiveEngagementUseCase.hasOngoingLiveEngagement) doReturn true whenever(fileAttachmentRepository.readyToSendLocalAttachments) doReturn emptyList() val result = useCase("") @@ -43,7 +43,7 @@ class IsShowSendButtonUseCaseTest { @Test fun `invoke returns true if ongoing engagement and the message is not empty and files are not ready to send`() { - whenever(isQueueingOrEngagementUseCase.hasOngoingEngagement) doReturn true + whenever(isQueueingOrLiveEngagementUseCase.hasOngoingLiveEngagement) doReturn true whenever(fileAttachmentRepository.readyToSendLocalAttachments) doReturn emptyList() val result = useCase("test") @@ -53,7 +53,7 @@ class IsShowSendButtonUseCaseTest { @Test fun `invoke returns true if ongoing engagement and the message is empty and files are ready to send`() { - whenever(isQueueingOrEngagementUseCase.hasOngoingEngagement) doReturn true + whenever(isQueueingOrLiveEngagementUseCase.hasOngoingLiveEngagement) doReturn true whenever(fileAttachmentRepository.readyToSendLocalAttachments) doReturn listOf(mock()) val result = useCase("") @@ -63,7 +63,7 @@ class IsShowSendButtonUseCaseTest { @Test fun `invoke returns true if ongoing engagement and the message is not empty and files are ready to send`() { - whenever(isQueueingOrEngagementUseCase.hasOngoingEngagement) doReturn true + whenever(isQueueingOrLiveEngagementUseCase.hasOngoingLiveEngagement) doReturn true whenever(fileAttachmentRepository.readyToSendLocalAttachments) doReturn listOf(mock()) val result = useCase("test") @@ -73,7 +73,7 @@ class IsShowSendButtonUseCaseTest { @Test fun `invoke returns false if no ongoing engagement and files are ready to send`() { - whenever(isQueueingOrEngagementUseCase.hasOngoingEngagement) doReturn false + whenever(isQueueingOrLiveEngagementUseCase.hasOngoingLiveEngagement) doReturn false whenever(fileAttachmentRepository.readyToSendLocalAttachments) doReturn listOf(mock()) val result = useCase("") @@ -83,7 +83,7 @@ class IsShowSendButtonUseCaseTest { @Test fun `invoke returns false if secure engagement and the message empty and files are not ready to send`() { - whenever(manageSecureMessagingStatusUseCase.shouldBehaveAsSecureMessaging()) doReturn true + whenever(manageSecureMessagingStatusUseCase.shouldBehaveAsSecureMessaging) doReturn true whenever(fileAttachmentRepository.readyToSendLocalAttachments) doReturn emptyList() val result = useCase("") @@ -93,7 +93,7 @@ class IsShowSendButtonUseCaseTest { @Test fun `invoke returns true if secure engagement and the message is not empty and files are not ready to send`() { - whenever(manageSecureMessagingStatusUseCase.shouldBehaveAsSecureMessaging()) doReturn true + whenever(manageSecureMessagingStatusUseCase.shouldBehaveAsSecureMessaging) doReturn true whenever(fileAttachmentRepository.readyToSendLocalAttachments) doReturn emptyList() val result = useCase("test") @@ -103,7 +103,7 @@ class IsShowSendButtonUseCaseTest { @Test fun `invoke returns true if secure engagement and the message is empty and files are ready to send`() { - whenever(manageSecureMessagingStatusUseCase.shouldBehaveAsSecureMessaging()) doReturn true + whenever(manageSecureMessagingStatusUseCase.shouldBehaveAsSecureMessaging) doReturn true whenever(fileAttachmentRepository.readyToSendLocalAttachments) doReturn listOf(mock()) val result = useCase("") @@ -113,7 +113,7 @@ class IsShowSendButtonUseCaseTest { @Test fun `invoke returns true if secure engagement and the message is not empty and files are ready to send`() { - whenever(manageSecureMessagingStatusUseCase.shouldBehaveAsSecureMessaging()) doReturn true + whenever(manageSecureMessagingStatusUseCase.shouldBehaveAsSecureMessaging) doReturn true whenever(fileAttachmentRepository.readyToSendLocalAttachments) doReturn listOf(mock()) val result = useCase("test") diff --git a/widgetssdk/src/test/java/com/glia/widgets/core/fileupload/domain/AddFileToAttachmentAndUploadUseCaseTest.kt b/widgetssdk/src/test/java/com/glia/widgets/core/fileupload/domain/AddFileToAttachmentAndUploadUseCaseTest.kt index 16f7b3557..fe2478910 100644 --- a/widgetssdk/src/test/java/com/glia/widgets/core/fileupload/domain/AddFileToAttachmentAndUploadUseCaseTest.kt +++ b/widgetssdk/src/test/java/com/glia/widgets/core/fileupload/domain/AddFileToAttachmentAndUploadUseCaseTest.kt @@ -7,7 +7,7 @@ import com.glia.widgets.core.fileupload.exception.SupportedFileCountExceededExce import com.glia.widgets.core.fileupload.exception.SupportedFileSizeExceededException import com.glia.widgets.core.fileupload.model.LocalAttachment import com.glia.widgets.core.secureconversations.domain.ManageSecureMessagingStatusUseCase -import com.glia.widgets.engagement.domain.IsQueueingOrEngagementUseCase +import com.glia.widgets.engagement.domain.IsQueueingOrLiveEngagementUseCase import io.mockk.every import io.mockk.mockk import io.mockk.verify @@ -17,17 +17,17 @@ import org.junit.Test class AddFileToAttachmentAndUploadUseCaseTest { private lateinit var fileAttachmentRepository: FileAttachmentRepository - private lateinit var isQueueingOrEngagementUseCase: IsQueueingOrEngagementUseCase + private lateinit var isQueueingOrLiveEngagementUseCase: IsQueueingOrLiveEngagementUseCase private lateinit var manageSecureMessagingStatusUseCase: ManageSecureMessagingStatusUseCase private lateinit var subjectUnderTest: AddFileToAttachmentAndUploadUseCase @Before fun setUp() { - isQueueingOrEngagementUseCase = mockk(relaxUnitFun = true) + isQueueingOrLiveEngagementUseCase = mockk(relaxUnitFun = true) fileAttachmentRepository = mockk(relaxUnitFun = true) manageSecureMessagingStatusUseCase = mockk(relaxUnitFun = true) subjectUnderTest = AddFileToAttachmentAndUploadUseCase( - isQueueingOrEngagementUseCase, + isQueueingOrLiveEngagementUseCase, fileAttachmentRepository, manageSecureMessagingStatusUseCase ) @@ -49,8 +49,8 @@ class AddFileToAttachmentAndUploadUseCaseTest { val localAttachment = mockk() val listener = mockk(relaxed = true) every { fileAttachmentRepository.isFileAttached(localAttachment.uri) } returns false - every { isQueueingOrEngagementUseCase.hasOngoingEngagement } returns false - every { manageSecureMessagingStatusUseCase.shouldUseSecureMessagingEndpoints() } returns false + every { isQueueingOrLiveEngagementUseCase.hasOngoingLiveEngagement } returns false + every { manageSecureMessagingStatusUseCase.shouldBehaveAsSecureMessaging } returns false subjectUnderTest.execute(localAttachment, listener) @@ -64,8 +64,8 @@ class AddFileToAttachmentAndUploadUseCaseTest { val listener = mockk(relaxed = true) every { fileAttachmentRepository.isFileAttached(localAttachment.uri) } returns false every { fileAttachmentRepository.attachedFilesCount } returns SupportedFileCountCheckUseCase.SUPPORTED_FILE_COUNT + 1 - every { isQueueingOrEngagementUseCase.hasOngoingEngagement } returns true - every { manageSecureMessagingStatusUseCase.shouldUseSecureMessagingEndpoints() } returns false + every { isQueueingOrLiveEngagementUseCase.hasOngoingLiveEngagement } returns true + every { manageSecureMessagingStatusUseCase.shouldUseSecureMessagingEndpoints } returns false subjectUnderTest.execute(localAttachment, listener) @@ -78,7 +78,7 @@ class AddFileToAttachmentAndUploadUseCaseTest { val listener = mockk(relaxed = true) every { fileAttachmentRepository.isFileAttached(localAttachment.uri) } returns false every { fileAttachmentRepository.attachedFilesCount } returns 1L - every { isQueueingOrEngagementUseCase.hasOngoingEngagement } returns true + every { isQueueingOrLiveEngagementUseCase.hasOngoingLiveEngagement } returns true every { localAttachment.size } returns AddFileToAttachmentAndUploadUseCase.SUPPORTED_FILE_SIZE subjectUnderTest.execute(localAttachment, listener) @@ -92,9 +92,9 @@ class AddFileToAttachmentAndUploadUseCaseTest { val listener = mockk(relaxed = true) every { fileAttachmentRepository.isFileAttached(localAttachment.uri) } returns false every { fileAttachmentRepository.attachedFilesCount } returns 1L - every { isQueueingOrEngagementUseCase.hasOngoingEngagement } returns true + every { isQueueingOrLiveEngagementUseCase.hasOngoingLiveEngagement } returns true every { localAttachment.size } returns AddFileToAttachmentAndUploadUseCase.SUPPORTED_FILE_SIZE - 1 - every { manageSecureMessagingStatusUseCase.shouldUseSecureMessagingEndpoints() } returns false + every { manageSecureMessagingStatusUseCase.shouldUseSecureMessagingEndpoints } returns false subjectUnderTest.execute(localAttachment, listener) @@ -106,10 +106,11 @@ class AddFileToAttachmentAndUploadUseCaseTest { val localAttachment = mockk() val listener = mockk(relaxed = true) every { fileAttachmentRepository.isFileAttached(localAttachment.uri) } returns false - every { isQueueingOrEngagementUseCase.hasOngoingEngagement } returns false + every { isQueueingOrLiveEngagementUseCase.hasOngoingLiveEngagement } returns false every { fileAttachmentRepository.attachedFilesCount } returns 1L every { localAttachment.size } returns AddFileToAttachmentAndUploadUseCase.SUPPORTED_FILE_SIZE - 1 - every { manageSecureMessagingStatusUseCase.shouldUseSecureMessagingEndpoints() } returns true + every { manageSecureMessagingStatusUseCase.shouldUseSecureMessagingEndpoints } returns true + every { manageSecureMessagingStatusUseCase.shouldBehaveAsSecureMessaging } returns true subjectUnderTest.execute(localAttachment, listener) diff --git a/widgetssdk/src/test/java/com/glia/widgets/core/secureconversations/domain/IsMessagingAvailableUseCaseTest.kt b/widgetssdk/src/test/java/com/glia/widgets/core/secureconversations/domain/IsMessagingAvailableUseCaseTest.kt index e1de6170d..543cf53ab 100644 --- a/widgetssdk/src/test/java/com/glia/widgets/core/secureconversations/domain/IsMessagingAvailableUseCaseTest.kt +++ b/widgetssdk/src/test/java/com/glia/widgets/core/secureconversations/domain/IsMessagingAvailableUseCaseTest.kt @@ -5,6 +5,8 @@ import com.glia.androidsdk.queuing.Queue import com.glia.androidsdk.queuing.QueueState import com.glia.widgets.core.queue.QueueRepository import com.glia.widgets.core.queue.QueuesState +import com.glia.widgets.engagement.EngagementRepository +import com.glia.widgets.engagement.State import com.glia.widgets.helper.supportMessaging import io.mockk.every import io.mockk.mockk @@ -19,12 +21,14 @@ import org.junit.Test class IsMessagingAvailableUseCaseTest { private lateinit var queueRepository: QueueRepository + private lateinit var engagementRepository: EngagementRepository private lateinit var isMessagingAvailableUseCase: IsMessagingAvailableUseCase @Before fun setUp() { - queueRepository = mockk() - isMessagingAvailableUseCase = IsMessagingAvailableUseCase(queueRepository) + queueRepository = mockk(relaxUnitFun = true) + engagementRepository = mockk(relaxUnitFun = true) + isMessagingAvailableUseCase = IsMessagingAvailableUseCase(queueRepository, engagementRepository) mockkStatic(COMMON_EXTENSIONS_CLASS_PATH) } @@ -33,11 +37,25 @@ class IsMessagingAvailableUseCaseTest { unmockkStatic(COMMON_EXTENSIONS_CLASS_PATH) } + @Test + fun `invoke returns true when transferred SC`() { + val nonMessagingQueue = createQueueWithStatus(QueueState.Status.OPEN, false) + val queuesState = QueuesState.Queues(listOf(nonMessagingQueue)) + every { queueRepository.queuesState } returns Flowable.just(queuesState) + every { engagementRepository.engagementState } returns Flowable.just(State.TransferredToSecureConversation) + + val testSubscriber = TestSubscriber>() + isMessagingAvailableUseCase().subscribe(testSubscriber) + + testSubscriber.assertValue(Result.success(true)) + } + @Test fun `invoke returns true when queue with messaging exists`() { val messagingQueue = createQueueWithStatus(QueueState.Status.OPEN, true) val queuesState = QueuesState.Queues(listOf(messagingQueue)) every { queueRepository.queuesState } returns Flowable.just(queuesState) + every { engagementRepository.engagementState } returns Flowable.just(State.NoEngagement) val testSubscriber = TestSubscriber>() isMessagingAvailableUseCase().subscribe(testSubscriber) @@ -50,6 +68,7 @@ class IsMessagingAvailableUseCaseTest { val nonMessagingQueue = createQueueWithStatus(QueueState.Status.OPEN, false) val queuesState = QueuesState.Queues(listOf(nonMessagingQueue)) every { queueRepository.queuesState } returns Flowable.just(queuesState) + every { engagementRepository.engagementState } returns Flowable.just(State.NoEngagement) val testSubscriber = TestSubscriber>() isMessagingAvailableUseCase().subscribe(testSubscriber) @@ -62,6 +81,7 @@ class IsMessagingAvailableUseCaseTest { val closedQueue = createQueueWithStatus(QueueState.Status.CLOSED, true) val queuesState = QueuesState.Queues(listOf(closedQueue)) every { queueRepository.queuesState } returns Flowable.just(queuesState) + every { engagementRepository.engagementState } returns Flowable.just(State.NoEngagement) val testSubscriber = TestSubscriber>() isMessagingAvailableUseCase().subscribe(testSubscriber) @@ -74,6 +94,7 @@ class IsMessagingAvailableUseCaseTest { val unknownQueue = createQueueWithStatus(QueueState.Status.UNKNOWN, true) val queuesState = QueuesState.Queues(listOf(unknownQueue)) every { queueRepository.queuesState } returns Flowable.just(queuesState) + every { engagementRepository.engagementState } returns Flowable.just(State.NoEngagement) val testSubscriber = TestSubscriber>() isMessagingAvailableUseCase().subscribe(testSubscriber) @@ -85,6 +106,7 @@ class IsMessagingAvailableUseCaseTest { fun `invoke returns error when queue state is error`() { val errorState = QueuesState.Error(Throwable("Error")) every { queueRepository.queuesState } returns Flowable.just(errorState) + every { engagementRepository.engagementState } returns Flowable.just(State.NoEngagement) val testSubscriber = TestSubscriber>() isMessagingAvailableUseCase().subscribe(testSubscriber) diff --git a/widgetssdk/src/test/java/com/glia/widgets/engagement/EngagementRepositoryTest.kt b/widgetssdk/src/test/java/com/glia/widgets/engagement/EngagementRepositoryTest.kt index d371c8d51..194a5b4c5 100644 --- a/widgetssdk/src/test/java/com/glia/widgets/engagement/EngagementRepositoryTest.kt +++ b/widgetssdk/src/test/java/com/glia/widgets/engagement/EngagementRepositoryTest.kt @@ -177,8 +177,8 @@ class EngagementRepositoryTest { assertNull(currentOperatorValue) assertNull(operatorCurrentMediaState) screenSharingStateTest.assertNotComplete().assertNoValues() - assertFalse(isQueueingOrEngagement) - assertFalse(hasOngoingEngagement) + assertFalse(isQueueingOrLiveEngagement) + assertFalse(hasOngoingLiveEngagement) assertFalse(isQueueing) assertFalse(isQueueingForMedia) assertFalse(isCallVisualizerEngagement) @@ -200,29 +200,43 @@ class EngagementRepositoryTest { screenSharing = mockk(relaxUnitFun = true) cameraDevice = mockk(relaxUnitFun = true) - operator = mockk(relaxUnitFun = true) + operator = mockk(relaxUnitFun = true) { + every { id } returns "initial_id" + every { formattedName } returns "initial_operator_name" + } engagementState = mockk(relaxUnitFun = true) every { engagementState.operator } returns operator every { engagement.state } returns engagementState + every { engagementState.visitorStatus } returns EngagementState.VisitorStatus.ENGAGED every { engagement.media } returns media every { engagement.chat } returns chat every { engagement.screenSharing } returns screenSharing every { media.currentCameraDevice } returns cameraDevice + val stateTestSubscriber = repository.engagementState.test() + if (callVisualizer) { callVisualizerEngagementCallbackSlot.captured.accept(engagement as OmnibrowseEngagement) - repository.engagementState.test().assertValue(State.StartedCallVisualizer).assertValueCount(1).assertNotComplete() + stateTestSubscriber.assertValues( + State.NoEngagement, + State.StartedCallVisualizer, + State.Update(engagementState, EngagementUpdateState.OperatorConnected(operator)) + ).assertValueCount(3).assertNotComplete() verify(inverse = true) { chat.on(Chat.Events.OPERATOR_TYPING_STATUS, capture(operatorTypingCallbackSlot)) } assertTrue(repository.isCallVisualizerEngagement) } else { omniCoreEngagementCallbackSlot.captured.accept(engagement as OmnicoreEngagement) - repository.engagementState.test().assertValue(State.StartedOmniCore).assertValueCount(1).assertNotComplete() + stateTestSubscriber.assertValues( + State.NoEngagement, + State.StartedOmniCore, + State.Update(engagementState, EngagementUpdateState.OperatorConnected(operator)) + ).assertValueCount(3).assertNotComplete() verify { chat.on(Chat.Events.OPERATOR_TYPING_STATUS, capture(operatorTypingCallbackSlot)) } assertFalse(repository.isCallVisualizerEngagement) } - assertTrue(repository.hasOngoingEngagement) - assertTrue(repository.isQueueingOrEngagement) + assertTrue(repository.hasOngoingLiveEngagement) + assertTrue(repository.isQueueingOrLiveEngagement) verify { Logger.i(any(), any()) } verify { operatorRepository.emit(operator) } @@ -240,6 +254,7 @@ class EngagementRepositoryTest { verify { engagement.state } verify { engagementState.operator } + verify { engagementState.visitorStatus } verify { engagement.media } verify { engagement.screenSharing } @@ -381,7 +396,7 @@ class EngagementRepositoryTest { } private fun confirmEngagementVerified() { - confirmVerified(engagement, engagementState, operator, chat, media, screenSharing) + confirmVerified(engagement, chat, media, screenSharing) } private fun requestScreenSharing(testBody: (ScreenSharingRequest) -> Unit) { @@ -524,6 +539,31 @@ class EngagementRepositoryTest { verify { incomingEngagementRequest.off(EngagementRequest.Events.OUTCOME, any()) } } + @Test + fun `TransferredToSecureConversation state is emitted when visitorStatus is transferring and has text capabilities`() { + operator = mockk(relaxUnitFun = true) + engagementState = mockk(relaxUnitFun = true) + media = mockk(relaxUnitFun = true) + chat = mockk(relaxUnitFun = true) + screenSharing = mockk(relaxUnitFun = true) + cameraDevice = mockk(relaxUnitFun = true) + every { engagementState.visitorStatus } returns EngagementState.VisitorStatus.TRANSFERRING + every { engagementState.capabilities.isText } returns true + every { engagementState.operator } returns operator + + every { media.currentCameraDevice } returns cameraDevice + + engagement = mockk(relaxUnitFun = true) + every { engagement.state } returns engagementState + every { engagement.media } returns media + every { engagement.chat } returns chat + every { engagement.screenSharing } returns screenSharing + + omniCoreEngagementCallbackSlot.captured.accept(engagement as OmnicoreEngagement) + repository.engagementState.test().assertValue(State.TransferredToSecureConversation).assertValueCount(1).assertNotComplete() + verify { operatorRepository.emit(any()) } + } + @Test fun `endEngagement() will do nothing when no ongoing engagement`() { repository.endEngagement(false) @@ -626,35 +666,46 @@ class EngagementRepositoryTest { val engagementStateTestObserver = repository.engagementState.test() val operatorTypingStatusTestObserver = repository.operatorTypingStatus.test() - val operator1: Operator = mockk(relaxed = true) { + val operator1: Operator = mockk(relaxUnitFun = true) { every { id } returns "1" } - val operator2: Operator = mockk(relaxed = true) { + val operator2: Operator = mockk(relaxUnitFun = true) { every { id } returns "2" } - val state1: EngagementState = mockk(relaxed = true) { + val state1: EngagementState = mockk(relaxUnitFun = true) { every { operator } returns operator1 every { visitorStatus } returns EngagementState.VisitorStatus.ENGAGED every { id } returns "s_1" + every { capabilities.isText } returns false } - val state2: EngagementState = mockk(relaxed = true) { + val state2: EngagementState = mockk(relaxUnitFun = true) { every { operator } returns operator1 every { visitorStatus } returns EngagementState.VisitorStatus.TRANSFERRING every { id } returns "s_2" + every { capabilities.isText } returns false } - val state3: EngagementState = mockk(relaxed = true) { + val state3: EngagementState = mockk(relaxUnitFun = true) { every { operator } returns operator2 every { visitorStatus } returns EngagementState.VisitorStatus.ENGAGED every { id } returns "s_3" + every { capabilities.isText } returns false } - val state4: EngagementState = mockk(relaxed = true) { + val state4: EngagementState = mockk(relaxUnitFun = true) { every { operator } returns operator2 every { visitorStatus } returns EngagementState.VisitorStatus.ENGAGED every { id } returns "s_4" + every { capabilities.isText } returns false + } + + val state5: EngagementState = mockk(relaxUnitFun = true) { + every { operator } returns operator2 + every { visitorStatus } returns EngagementState.VisitorStatus.TRANSFERRING + every { id } returns "s_5" + every { capabilities.isText } returns true } mockEngagementAndStart() @@ -668,6 +719,8 @@ class EngagementRepositoryTest { assertEquals(operator2, repository.currentOperatorValue) engagementStateCallbackSlot.captured.accept(state4) assertEquals(operator2, repository.currentOperatorValue) + engagementStateCallbackSlot.captured.accept(state5) + assertEquals(operator2, repository.currentOperatorValue) operatorTypingCallbackSlot.captured.apply { accept(OperatorTypingStatus { false }) @@ -676,7 +729,7 @@ class EngagementRepositoryTest { } verify(exactly = 2) { operatorRepository.emit(operator1) } - verify(exactly = 2) { operatorRepository.emit(operator2) } + verify(exactly = 3) { operatorRepository.emit(operator2) } operatorTypingStatusTestObserver .assertNotComplete() @@ -689,26 +742,26 @@ class EngagementRepositoryTest { currentOperatorTestObserver .assertNotComplete() - .assertValueCount(5) + .assertValueCount(4) .assertValuesOnly( Data.Empty, + Data.Value(operator), Data.Value(operator1), - Data.Value(operator1), - Data.Value(operator2), Data.Value(operator2) ) engagementStateTestObserver .assertNotComplete() - .assertValueCount(6) + .assertValueCount(7) .assertValuesOnly( State.NoEngagement, State.StartedOmniCore, - State.Update(state1, EngagementUpdateState.OperatorConnected(operator1)), + State.Update(engagementState, EngagementUpdateState.OperatorConnected(operator)), + State.Update(state1, EngagementUpdateState.OperatorChanged(operator1)), State.Update(state2, EngagementUpdateState.Transferring), State.Update(state3, EngagementUpdateState.OperatorChanged(operator2)), - State.Update(state4, EngagementUpdateState.Ongoing(operator2)) + State.TransferredToSecureConversation ) repository.endEngagement(silently = true) @@ -1213,7 +1266,7 @@ class EngagementRepositoryTest { } engagementStateCallbackSlot.captured.accept(state1) repository.engagementState.test().assertNotComplete().assertValues( - State.Update(state1, EngagementUpdateState.OperatorConnected(operator1)) + State.Update(state1, EngagementUpdateState.OperatorChanged(operator1)) ) verify { operatorRepository.emit(operator1) } //emit a new state end @@ -1228,6 +1281,7 @@ class EngagementRepositoryTest { val newOperator: Operator = mockk(relaxUnitFun = true) val newEngagementState: EngagementState = mockk(relaxUnitFun = true) every { newEngagementState.operator } returns newOperator + every { newEngagementState.visitorStatus } returns EngagementState.VisitorStatus.ENGAGED every { newEngagement.state } returns newEngagementState every { newEngagement.media } returns newMedia every { newEngagement.chat } returns newChat @@ -1235,8 +1289,9 @@ class EngagementRepositoryTest { every { newMedia.currentCameraDevice } returns null omniCoreEngagementCallbackSlot.captured.accept(newEngagement) - repository.engagementState.test().assertNotComplete().assertValue(State.Update(state1, EngagementUpdateState.OperatorConnected(operator1))) - assertTrue(repository.hasOngoingEngagement) + repository.engagementState.test().assertNotComplete() + .assertValue(State.Update(newEngagementState, EngagementUpdateState.OperatorConnected(newOperator))) + assertTrue(repository.hasOngoingLiveEngagement) verify { operatorRepository.emit(newOperator) } @@ -1261,7 +1316,7 @@ class EngagementRepositoryTest { //emit new engagement end verifyUnsubscribedFromEngagement() - confirmVerified(newEngagement, newMedia, newChat, newScreenSharing, newOperator, newEngagementState) + confirmVerified(newEngagement, newMedia, newChat, newScreenSharing) } @@ -1280,7 +1335,7 @@ class EngagementRepositoryTest { } engagementStateCallbackSlot.captured.accept(state1) repository.engagementState.test().assertNotComplete().assertValues( - State.Update(state1, EngagementUpdateState.OperatorConnected(operator1)) + State.Update(state1, EngagementUpdateState.OperatorChanged(operator1)) ) verify { operatorRepository.emit(operator1) } //emit a new state end @@ -1294,6 +1349,7 @@ class EngagementRepositoryTest { val newOperator: Operator = mockk(relaxUnitFun = true) val newEngagementState: EngagementState = mockk(relaxUnitFun = true) + every { newEngagementState.visitorStatus } returns EngagementState.VisitorStatus.ENGAGED every { newEngagementState.operator } returns newOperator every { newEngagement.state } returns newEngagementState every { newEngagement.media } returns newMedia @@ -1302,8 +1358,9 @@ class EngagementRepositoryTest { every { newMedia.currentCameraDevice } returns mockk() callVisualizerEngagementCallbackSlot.captured.accept(newEngagement) - repository.engagementState.test().assertNotComplete().assertValue(State.Update(state1, EngagementUpdateState.OperatorConnected(operator1))) - assertTrue(repository.hasOngoingEngagement) + repository.engagementState.test().assertNotComplete() + .assertValue(State.Update(newEngagementState, EngagementUpdateState.OperatorConnected(newOperator))) + assertTrue(repository.hasOngoingLiveEngagement) verify { operatorRepository.emit(newOperator) } @@ -1328,7 +1385,7 @@ class EngagementRepositoryTest { //emit new engagement end verifyUnsubscribedFromEngagement() - confirmVerified(newEngagement, newMedia, newChat, newScreenSharing, newOperator, newEngagementState) + confirmVerified(newEngagement, newMedia, newChat, newScreenSharing) } @Test @@ -1361,7 +1418,16 @@ class EngagementRepositoryTest { repository.queueForEngagement(MediaType.TEXT) - verify(exactly = 1) { core.queueForEngagement(listOf(queueId), MediaType.TEXT, visitorContextAssetId, any(), any(), capture(queueForEngagementCallbackSlot)) } + verify(exactly = 1) { + core.queueForEngagement( + listOf(queueId), + MediaType.TEXT, + visitorContextAssetId, + any(), + any(), + capture(queueForEngagementCallbackSlot) + ) + } queueForEngagementCallbackSlot.captured.accept(null) assertTrue(repository.isQueueing) @@ -1370,7 +1436,16 @@ class EngagementRepositoryTest { repository.queueForEngagement(MediaType.TEXT) verify { queueRepository.relevantQueueIds } - verify(exactly = 1) { core.queueForEngagement(listOf(queueId), MediaType.TEXT, visitorContextAssetId, any(), any(), capture(queueForEngagementCallbackSlot)) } + verify(exactly = 1) { + core.queueForEngagement( + listOf(queueId), + MediaType.TEXT, + visitorContextAssetId, + any(), + any(), + capture(queueForEngagementCallbackSlot) + ) + } } @Test diff --git a/widgetssdk/src/test/java/com/glia/widgets/engagement/domain/EngagementDomainTest.kt b/widgetssdk/src/test/java/com/glia/widgets/engagement/domain/EngagementDomainTest.kt index a2b1a4f49..dedce5011 100644 --- a/widgetssdk/src/test/java/com/glia/widgets/engagement/domain/EngagementDomainTest.kt +++ b/widgetssdk/src/test/java/com/glia/widgets/engagement/domain/EngagementDomainTest.kt @@ -215,7 +215,7 @@ class EngagementDomainTest { @Test fun `EngagementTypeUseCase isCallVisualizerScreenSharing returns true when current engagement is call visualizer and has no media`() { - val isQueueingOrEngagementUseCase: IsQueueingOrEngagementUseCase = mockk(relaxUnitFun = true) + val isQueueingOrLiveEngagementUseCase: IsQueueingOrLiveEngagementUseCase = mockk(relaxUnitFun = true) val isCurrentEngagementCallVisualizerUseCase: IsCurrentEngagementCallVisualizerUseCase = mockk(relaxUnitFun = true) val operatorMediaUseCase: OperatorMediaUseCase = mockk(relaxUnitFun = true) val visitorMediaUseCase: VisitorMediaUseCase = mockk(relaxUnitFun = true) @@ -226,7 +226,7 @@ class EngagementDomainTest { every { operatorMediaUseCase.hasMedia } returns false val useCase: EngagementTypeUseCase = EngagementTypeUseCaseImpl( - isQueueingOrEngagementUseCase = isQueueingOrEngagementUseCase, + isQueueingOrLiveEngagementUseCase = isQueueingOrLiveEngagementUseCase, isCurrentEngagementCallVisualizerUseCase = isCurrentEngagementCallVisualizerUseCase, operatorMediaUseCase = operatorMediaUseCase, visitorMediaUseCase = visitorMediaUseCase, @@ -238,7 +238,7 @@ class EngagementDomainTest { @Test fun `EngagementTypeUseCase isCallVisualizerScreenSharing returns false when engagement has media`() { - val isQueueingOrEngagementUseCase: IsQueueingOrEngagementUseCase = mockk(relaxUnitFun = true) + val isQueueingOrLiveEngagementUseCase: IsQueueingOrLiveEngagementUseCase = mockk(relaxUnitFun = true) val isCurrentEngagementCallVisualizerUseCase: IsCurrentEngagementCallVisualizerUseCase = mockk(relaxUnitFun = true) val operatorMediaUseCase: OperatorMediaUseCase = mockk(relaxUnitFun = true) val visitorMediaUseCase: VisitorMediaUseCase = mockk(relaxUnitFun = true) @@ -249,7 +249,7 @@ class EngagementDomainTest { every { operatorMediaUseCase.hasMedia } returns false val useCase: EngagementTypeUseCase = EngagementTypeUseCaseImpl( - isQueueingOrEngagementUseCase = isQueueingOrEngagementUseCase, + isQueueingOrLiveEngagementUseCase = isQueueingOrLiveEngagementUseCase, isCurrentEngagementCallVisualizerUseCase = isCurrentEngagementCallVisualizerUseCase, operatorMediaUseCase = operatorMediaUseCase, visitorMediaUseCase = visitorMediaUseCase, @@ -261,7 +261,7 @@ class EngagementDomainTest { @Test fun `EngagementTypeUseCase isChatEngagement returns true when engagement has no media, is not a cv and operator is present`() { - val isQueueingOrEngagementUseCase: IsQueueingOrEngagementUseCase = mockk(relaxUnitFun = true) + val isQueueingOrLiveEngagementUseCase: IsQueueingOrLiveEngagementUseCase = mockk(relaxUnitFun = true) val isCurrentEngagementCallVisualizerUseCase: IsCurrentEngagementCallVisualizerUseCase = mockk(relaxUnitFun = true) val operatorMediaUseCase: OperatorMediaUseCase = mockk(relaxUnitFun = true) val visitorMediaUseCase: VisitorMediaUseCase = mockk(relaxUnitFun = true) @@ -270,11 +270,11 @@ class EngagementDomainTest { every { isCurrentEngagementCallVisualizerUseCase() } returns false every { visitorMediaUseCase.hasMedia } returns false every { operatorMediaUseCase.hasMedia } returns false - every { isQueueingOrEngagementUseCase.hasOngoingEngagement } returns true + every { isQueueingOrLiveEngagementUseCase.hasOngoingLiveEngagement } returns true every { isOperatorPresentUseCase() } returns true val useCase: EngagementTypeUseCase = EngagementTypeUseCaseImpl( - isQueueingOrEngagementUseCase = isQueueingOrEngagementUseCase, + isQueueingOrLiveEngagementUseCase = isQueueingOrLiveEngagementUseCase, isCurrentEngagementCallVisualizerUseCase = isCurrentEngagementCallVisualizerUseCase, operatorMediaUseCase = operatorMediaUseCase, visitorMediaUseCase = visitorMediaUseCase, @@ -286,7 +286,7 @@ class EngagementDomainTest { @Test fun `EngagementTypeUseCase isMediaEngagement returns true when engagement has media and operator is present`() { - val isQueueingOrEngagementUseCase: IsQueueingOrEngagementUseCase = mockk(relaxUnitFun = true) + val isQueueingOrLiveEngagementUseCase: IsQueueingOrLiveEngagementUseCase = mockk(relaxUnitFun = true) val isCurrentEngagementCallVisualizerUseCase: IsCurrentEngagementCallVisualizerUseCase = mockk(relaxUnitFun = true) val operatorMediaUseCase: OperatorMediaUseCase = mockk(relaxUnitFun = true) val visitorMediaUseCase: VisitorMediaUseCase = mockk(relaxUnitFun = true) @@ -294,11 +294,11 @@ class EngagementDomainTest { every { visitorMediaUseCase.hasMedia } returns true every { operatorMediaUseCase.hasMedia } returns false - every { isQueueingOrEngagementUseCase.hasOngoingEngagement } returns true + every { isQueueingOrLiveEngagementUseCase.hasOngoingLiveEngagement } returns true every { isOperatorPresentUseCase() } returns true val useCase: EngagementTypeUseCase = EngagementTypeUseCaseImpl( - isQueueingOrEngagementUseCase = isQueueingOrEngagementUseCase, + isQueueingOrLiveEngagementUseCase = isQueueingOrLiveEngagementUseCase, isCurrentEngagementCallVisualizerUseCase = isCurrentEngagementCallVisualizerUseCase, operatorMediaUseCase = operatorMediaUseCase, visitorMediaUseCase = visitorMediaUseCase, @@ -322,18 +322,18 @@ class EngagementDomainTest { @Test fun `IsQueueingOrEngagementUseCase isQueueingForChat returns true when is not queueing for media`() { val repository: EngagementRepository = mockk(relaxUnitFun = true) { - every { hasOngoingEngagement } returns false + every { hasOngoingLiveEngagement } returns false every { isQueueing } returns true every { isQueueingForMedia } returns false - every { isQueueingOrEngagement } returns true + every { isQueueingOrLiveEngagement } returns true } - val useCase: IsQueueingOrEngagementUseCase = IsQueueingOrEngagementUseCaseImpl(engagementRepository = repository) + val useCase: IsQueueingOrLiveEngagementUseCase = IsQueueingOrLiveEngagementUseCaseImpl(engagementRepository = repository) - assertTrue(useCase.isQueueingForChat) + assertTrue(useCase.isQueueingForLiveChat) assertTrue(useCase()) assertFalse(useCase.isQueueingForMedia) - assertFalse(useCase.hasOngoingEngagement) + assertFalse(useCase.hasOngoingLiveEngagement) } @Test diff --git a/widgetssdk/src/test/java/com/glia/widgets/secureconversations/domain/ManageSecureMessagingStatusUseCaseTest.kt b/widgetssdk/src/test/java/com/glia/widgets/secureconversations/domain/ManageSecureMessagingStatusUseCaseTest.kt index ac2759d8a..62406ed6e 100644 --- a/widgetssdk/src/test/java/com/glia/widgets/secureconversations/domain/ManageSecureMessagingStatusUseCaseTest.kt +++ b/widgetssdk/src/test/java/com/glia/widgets/secureconversations/domain/ManageSecureMessagingStatusUseCaseTest.kt @@ -2,7 +2,6 @@ package com.glia.widgets.secureconversations.domain import com.glia.widgets.core.secureconversations.domain.ManageSecureMessagingStatusUseCase import com.glia.widgets.engagement.EngagementRepository -import com.glia.widgets.engagement.domain.IsQueueingOrEngagementUseCase import io.mockk.every import io.mockk.mockk import io.mockk.verify @@ -13,23 +12,22 @@ import org.junit.Test class ManageSecureMessagingStatusUseCaseTest { - private lateinit var isQueueingOrEngagementUseCase: IsQueueingOrEngagementUseCase private lateinit var engagementRepository: EngagementRepository private lateinit var useCase: ManageSecureMessagingStatusUseCase @Before fun setUp() { - isQueueingOrEngagementUseCase = mockk() - engagementRepository = mockk(relaxed = true) - useCase = ManageSecureMessagingStatusUseCase(isQueueingOrEngagementUseCase, engagementRepository) + engagementRepository = mockk(relaxUnitFun = true) + useCase = ManageSecureMessagingStatusUseCase(engagementRepository) } @Test fun `shouldUseSecureMessagingEndpoints returns true when secure messaging is requested and not queueing or engaged`() { every { engagementRepository.isSecureMessagingRequested } returns true - every { isQueueingOrEngagementUseCase() } returns false + every { engagementRepository.isQueueingOrLiveEngagement } returns false + every { engagementRepository.isTransferredSecureConversation } returns false - val result = useCase.shouldUseSecureMessagingEndpoints() + val result = useCase.shouldUseSecureMessagingEndpoints assertTrue(result) } @@ -38,7 +36,7 @@ class ManageSecureMessagingStatusUseCaseTest { fun `shouldUseSecureMessagingEndpoints returns false when secure messaging is not requested`() { every { engagementRepository.isSecureMessagingRequested } returns false - val result = useCase.shouldUseSecureMessagingEndpoints() + val result = useCase.shouldUseSecureMessagingEndpoints assertFalse(result) } @@ -46,9 +44,10 @@ class ManageSecureMessagingStatusUseCaseTest { @Test fun `shouldUseSecureMessagingEndpoints returns false when queueing or engaged`() { every { engagementRepository.isSecureMessagingRequested } returns true - every { isQueueingOrEngagementUseCase() } returns true + every { engagementRepository.isQueueingOrLiveEngagement } returns true + every { engagementRepository.isTransferredSecureConversation } returns false - val result = useCase.shouldUseSecureMessagingEndpoints() + val result = useCase.shouldUseSecureMessagingEndpoints assertFalse(result) } @@ -56,17 +55,29 @@ class ManageSecureMessagingStatusUseCaseTest { @Test fun `shouldBehaveAsSecureMessaging returns true when secure messaging is requested`() { every { engagementRepository.isSecureMessagingRequested } returns true + every { engagementRepository.isTransferredSecureConversation } returns false - val result = useCase.shouldBehaveAsSecureMessaging() + val result = useCase.shouldBehaveAsSecureMessaging assertTrue(result) } @Test - fun `shouldBehaveAsSecureMessaging returns false when secure messaging is not requested`() { + fun `shouldBehaveAsSecureMessaging returns true when transferred SC`() { every { engagementRepository.isSecureMessagingRequested } returns false + every { engagementRepository.isTransferredSecureConversation } returns true - val result = useCase.shouldBehaveAsSecureMessaging() + val result = useCase.shouldBehaveAsSecureMessaging + + assertTrue(result) + } + + @Test + fun `shouldBehaveAsSecureMessaging returns false when secure messaging is not requested and not transferred SC`() { + every { engagementRepository.isSecureMessagingRequested } returns false + every { engagementRepository.isTransferredSecureConversation } returns false + + val result = useCase.shouldBehaveAsSecureMessaging assertFalse(result) }