Skip to content

Commit

Permalink
Track error events when token is missing fails
Browse files Browse the repository at this point in the history
COAND-1010
  • Loading branch information
araratthehero committed Dec 10, 2024
1 parent 47647c4 commit a92a28e
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ internal class DefaultAdyen3DS2Delegate(
activity: Activity,
) {
if (action.token.isNullOrEmpty()) {
trackFingerprintTokenMissingErrorEvent()
emitError(ComponentException("Fingerprint token not found."))
return
}
Expand All @@ -166,6 +167,7 @@ internal class DefaultAdyen3DS2Delegate(
activity: Activity,
) {
if (action.token.isNullOrEmpty()) {
trackChallengeTokenMissingErrorEvent()
emitError(ComponentException("Challenge token not found."))
return
}
Expand All @@ -179,10 +181,6 @@ internal class DefaultAdyen3DS2Delegate(
action: Threeds2Action,
activity: Activity,
) {
if (action.token.isNullOrEmpty()) {
emitError(ComponentException("3DS2 token not found."))
return
}
if (action.subtype == null) {
emitError(ComponentException("3DS2 Action subtype not found."))
return
Expand All @@ -196,7 +194,17 @@ internal class DefaultAdyen3DS2Delegate(
activity: Activity,
subtype: Threeds2Action.SubType,
) {
val token = action.token.orEmpty()
val token = action.token
if (token.isNullOrEmpty()) {
when (subtype) {
Threeds2Action.SubType.FINGERPRINT -> trackFingerprintTokenMissingErrorEvent()
Threeds2Action.SubType.CHALLENGE -> trackChallengeTokenMissingErrorEvent()
}

emitError(ComponentException("3DS2 token not found."))
return
}

when (subtype) {
Threeds2Action.SubType.FINGERPRINT -> {
trackFingerprintActionEvent(action)
Expand Down Expand Up @@ -590,6 +598,9 @@ internal class DefaultAdyen3DS2Delegate(
analyticsManager?.trackEvent(event)
}

private fun trackFingerprintTokenMissingErrorEvent() =
trackFingerprintErrorEvent(ErrorEvent.THREEDS2_TOKEN_MISSING)

private fun trackFingerprintCreationErrorEvent() =
trackFingerprintErrorEvent(ErrorEvent.THREEDS2_FINGERPRINT_CREATION)

Expand All @@ -607,6 +618,9 @@ internal class DefaultAdyen3DS2Delegate(
analyticsManager?.trackEvent(event)
}

private fun trackChallengeTokenMissingErrorEvent() =
trackChallengeErrorEvent(ErrorEvent.THREEDS2_TOKEN_MISSING)

private fun trackChallengeTransactionMissingErrorEvent() =
trackChallengeErrorEvent(ErrorEvent.THREEDS2_TRANSACTION_MISSING)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,53 @@ internal class DefaultAdyen3DS2DelegateTest(
analyticsManager.assertLastEventEquals(expectedEvent)
}

@Test
fun `when action is Threeds2FingerprintAction and token is null, then error event is tracked`() = runTest {
delegate.initialize(this)

delegate.handleAction(Threeds2FingerprintAction(token = null), Activity())

val expectedEvent = ThreeDS2Events.threeDS2FingerprintError(
event = ErrorEvent.THREEDS2_TOKEN_MISSING,
)
analyticsManager.assertLastEventEquals(expectedEvent)
}

@Test
fun `when action is Threeds2ChallengeAction and token is null, then error event is tracked`() = runTest {
delegate.initialize(this)

delegate.handleAction(Threeds2ChallengeAction(token = null), Activity())

val expectedEvent = ThreeDS2Events.threeDS2ChallengeError(
event = ErrorEvent.THREEDS2_TOKEN_MISSING,
)
analyticsManager.assertLastEventEquals(expectedEvent)
}

@Test
fun `when action is Threeds2Action and token is null, then error event is tracked`() = runTest {
delegate.initialize(CoroutineScope(UnconfinedTestDispatcher(testScheduler)))

delegate.handleAction(
Threeds2Action(token = null, subtype = Threeds2Action.SubType.FINGERPRINT.value),
Activity(),
)
val expectedFingerprintEvent = ThreeDS2Events.threeDS2FingerprintError(
event = ErrorEvent.THREEDS2_TOKEN_MISSING,
)
analyticsManager.assertLastEventEquals(expectedFingerprintEvent)

delegate.handleAction(
Threeds2Action(token = null, subtype = Threeds2Action.SubType.CHALLENGE.value),
Activity(),
)
val expectedChallengeEvent = ThreeDS2Events.threeDS2ChallengeError(
event = ErrorEvent.THREEDS2_TOKEN_MISSING,
)
analyticsManager.assertLastEventEquals(expectedChallengeEvent)
}

@Test
fun `when fingerprintToken is partial, then error event is tracked`() = runTest {
val partialFingerprintToken =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ enum class ErrorEvent(val errorType: Type, val errorCode: String) {
API_NATIVE_REDIRECT(Type.API_ERROR, "625"),

// 3DS2
THREEDS2_TOKEN_MISSING(Type.THREEDS2, "701"),
THREEDS2_TOKEN_DECODING(Type.THREEDS2, "704"),
THREEDS2_FINGERPRINT_CREATION(Type.THREEDS2, "705"),
THREEDS2_TRANSACTION_CREATION(Type.THREEDS2, "706"),
Expand Down

0 comments on commit a92a28e

Please sign in to comment.