Skip to content

Commit

Permalink
Cancel ongoing queue ticket if visitor selects engagement of another …
Browse files Browse the repository at this point in the history
…type or starts a new engagement during queueing

MOB-3886
  • Loading branch information
DavDo authored and andrews-moc committed Dec 27, 2024
1 parent ad83aeb commit 35d6916
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 3 deletions.
8 changes: 7 additions & 1 deletion widgetssdk/src/main/java/com/glia/widgets/di/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,13 @@ internal object Dependencies {

@JvmStatic
val engagementLauncher: EngagementLauncher by lazy {
EngagementLauncherImpl(activityLauncher, useCaseFactory.hasPendingSecureConversationsWithTimeoutUseCase, configurationManager)
EngagementLauncherImpl(
activityLauncher,
useCaseFactory.hasPendingSecureConversationsWithTimeoutUseCase,
useCaseFactory.isQueueingOrEngagementUseCase,
useCaseFactory.endEngagementUseCase,
configurationManager,
controllerFactory)
}

@JvmStatic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ internal interface IsQueueingOrLiveEngagementUseCase {
val hasOngoingLiveEngagement: Boolean
val isQueueingForMedia: Boolean
val isQueueingForLiveChat: Boolean
val isQueueing: 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 val isQueueing: Boolean get() = engagementRepository.isQueueing
override fun invoke(): Boolean = engagementRepository.isQueueingOrLiveEngagement
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import android.content.Context
import com.glia.androidsdk.Engagement
import com.glia.widgets.chat.Intention
import com.glia.widgets.core.secureconversations.domain.HasOngoingSecureConversationUseCase
import com.glia.widgets.di.ControllerFactory
import com.glia.widgets.engagement.domain.EndEngagementUseCase
import com.glia.widgets.engagement.domain.IsQueueingOrLiveEngagementUseCase

/**
* An interface for launching different types of engagements, such as chat,
Expand Down Expand Up @@ -46,10 +49,18 @@ interface EngagementLauncher {
internal class EngagementLauncherImpl(
private val activityLauncher: ActivityLauncher,
private val hasOngoingSecureConversationUseCase: HasOngoingSecureConversationUseCase,
private val configurationManager: ConfigurationManager
private val isQueueingOrLiveEngagementUseCase: IsQueueingOrLiveEngagementUseCase,
private val endEngagementUseCase: EndEngagementUseCase,
private val configurationManager: ConfigurationManager,
private val controllerFactory: ControllerFactory
) : EngagementLauncher {

override fun startChat(context: Context, visitorContextAssetId: String?) {
if (isQueueingOrLiveEngagementUseCase.isQueueing) {
endEngagementUseCase()
controllerFactory.destroyChatController()
}

visitorContextAssetId?.let { configurationManager.setVisitorContextAssetId(it) }
hasOngoingSecureConversationUseCase {
if (it) {
Expand All @@ -61,6 +72,11 @@ internal class EngagementLauncherImpl(
}

override fun startAudioCall(context: Context, visitorContextAssetId: String?) {
if (isQueueingOrLiveEngagementUseCase.isQueueing) {
endEngagementUseCase()
controllerFactory.destroyCallController()
}

visitorContextAssetId?.let { configurationManager.setVisitorContextAssetId(it) }
hasOngoingSecureConversationUseCase {
if (it) {
Expand All @@ -72,6 +88,11 @@ internal class EngagementLauncherImpl(
}

override fun startVideoCall(context: Context, visitorContextAssetId: String?) {
if (isQueueingOrLiveEngagementUseCase.isQueueing) {
endEngagementUseCase()
controllerFactory.destroyCallController()
}

visitorContextAssetId?.let { configurationManager.setVisitorContextAssetId(it) }
hasOngoingSecureConversationUseCase {
if (it) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import android.app.Activity
import com.glia.androidsdk.Engagement
import com.glia.widgets.chat.Intention
import com.glia.widgets.core.secureconversations.domain.HasOngoingSecureConversationUseCase
import com.glia.widgets.di.ControllerFactory
import com.glia.widgets.engagement.domain.EndEngagementUseCase
import com.glia.widgets.engagement.domain.IsQueueingOrLiveEngagementUseCase
import io.mockk.MockKAnnotations
import io.mockk.every
import io.mockk.impl.annotations.MockK
Expand All @@ -19,6 +22,15 @@ class EngagementLauncherImplTest {
@MockK
private lateinit var hasOngoingSecureConversationUseCase: HasOngoingSecureConversationUseCase

@MockK
private lateinit var isQueueingOrLiveEngagementUseCase: IsQueueingOrLiveEngagementUseCase

@MockK(relaxUnitFun = true)
private lateinit var endEngagementUseCase: EndEngagementUseCase

@MockK(relaxUnitFun = true)
private lateinit var controllerFactory: ControllerFactory

@MockK
private lateinit var activity: Activity

Expand All @@ -33,12 +45,20 @@ class EngagementLauncherImplTest {
@Before
fun setUp() {
MockKAnnotations.init(this)
engagementLauncher = EngagementLauncherImpl(activityLauncher, hasOngoingSecureConversationUseCase, configurationManager)
engagementLauncher = EngagementLauncherImpl(
activityLauncher,
hasOngoingSecureConversationUseCase,
isQueueingOrLiveEngagementUseCase,
endEngagementUseCase,
configurationManager,
controllerFactory
)
}

@Test
fun `startChat launches live chat when no pending secure conversations`() {
mockOngoingInteractionCallback(false)
every { isQueueingOrLiveEngagementUseCase.isQueueing } returns false

engagementLauncher.startChat(activity)

Expand All @@ -49,6 +69,7 @@ class EngagementLauncherImplTest {
@Test
fun `startChat launches secure conversation dialog when there are pending secure conversations`() {
mockOngoingInteractionCallback(true)
every { isQueueingOrLiveEngagementUseCase.isQueueing } returns false

engagementLauncher.startChat(activity, visitorContextAssetId)

Expand All @@ -59,6 +80,7 @@ class EngagementLauncherImplTest {
@Test
fun `startAudioCall launches audio call when no pending secure conversations`() {
mockOngoingInteractionCallback(false)
every { isQueueingOrLiveEngagementUseCase.isQueueing } returns false

engagementLauncher.startAudioCall(activity)

Expand All @@ -69,6 +91,7 @@ class EngagementLauncherImplTest {
@Test
fun `startAudioCall launches secure conversation audio dialog when there are pending secure conversations`() {
mockOngoingInteractionCallback(true)
every { isQueueingOrLiveEngagementUseCase.isQueueing } returns false

engagementLauncher.startAudioCall(activity, visitorContextAssetId)

Expand All @@ -79,6 +102,7 @@ class EngagementLauncherImplTest {
@Test
fun `startVideoCall launches video call when no pending secure conversations`() {
mockOngoingInteractionCallback(false)
every { isQueueingOrLiveEngagementUseCase.isQueueing } returns false

engagementLauncher.startVideoCall(activity)

Expand All @@ -89,6 +113,7 @@ class EngagementLauncherImplTest {
@Test
fun `startVideoCall launches secure conversation video dialog when there are pending secure conversations`() {
mockOngoingInteractionCallback(true)
every { isQueueingOrLiveEngagementUseCase.isQueueing } returns false

engagementLauncher.startVideoCall(activity, visitorContextAssetId)

Expand All @@ -99,6 +124,7 @@ class EngagementLauncherImplTest {
@Test
fun `startSecureMessaging launches secure messaging welcome screen when no pending secure conversations`() {
mockOngoingInteractionCallback(false)
every { isQueueingOrLiveEngagementUseCase.isQueueing } returns false

engagementLauncher.startSecureMessaging(activity)

Expand All @@ -109,6 +135,7 @@ class EngagementLauncherImplTest {
@Test
fun `startSecureMessaging launches secure chat when there are pending secure conversations`() {
mockOngoingInteractionCallback(true)
every { isQueueingOrLiveEngagementUseCase.isQueueing } returns false

engagementLauncher.startSecureMessaging(activity, visitorContextAssetId)

Expand All @@ -121,4 +148,40 @@ class EngagementLauncherImplTest {
firstArg<(Boolean) -> Unit>().invoke(hasOngoingInteraction)
}
}

@Test
fun `startChat ends engagement and destroys chat controller when queueing`() {
mockOngoingInteractionCallback(false)
every { isQueueingOrLiveEngagementUseCase.isQueueing } returns true

engagementLauncher.startChat(activity)

verify { endEngagementUseCase() }
verify { controllerFactory.destroyChatController() }
verify { activityLauncher.launchChat(activity, Intention.LIVE_CHAT) }
}

@Test
fun `startAudioCall ends engagement and destroys call controller when queueing`() {
mockOngoingInteractionCallback(false)
every { isQueueingOrLiveEngagementUseCase.isQueueing } returns true

engagementLauncher.startAudioCall(activity)

verify { endEngagementUseCase() }
verify { controllerFactory.destroyCallController() }
verify { activityLauncher.launchCall(activity, Engagement.MediaType.AUDIO, false) }
}

@Test
fun `startVideoCall ends engagement and destroys call controller when queueing`() {
mockOngoingInteractionCallback(false)
every { isQueueingOrLiveEngagementUseCase.isQueueing } returns true

engagementLauncher.startVideoCall(activity)

verify { endEngagementUseCase() }
verify { controllerFactory.destroyCallController() }
verify { activityLauncher.launchCall(activity, Engagement.MediaType.VIDEO, false) }
}
}

0 comments on commit 35d6916

Please sign in to comment.