File tree 3 files changed +49
-1
lines changed
commonMain/kotlin/org/hyperskill/app/paywall
commonTest/kotlin/org/hyperskill/paywall
3 files changed +49
-1
lines changed Original file line number Diff line number Diff line change
1
+ package org.hyperskill.app.paywall.domain.analytic
2
+
3
+ import org.hyperskill.app.analytic.domain.model.apps_flyer.AppsFlyerAnalyticEvent
4
+
5
+ /* *
6
+ * Represents an analytic event when user purchases a subscription.
7
+ */
8
+ object PaywallSubscriptionPurchasedAppsFlyerAnalyticEvent : AppsFlyerAnalyticEvent(name = " af_subscribe" )
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ import org.hyperskill.app.paywall.domain.analytic.PaywallClickedBuySubscriptionH
6
6
import org.hyperskill.app.paywall.domain.analytic.PaywallClickedContinueWithLimitsHyperskillAnalyticEvent
7
7
import org.hyperskill.app.paywall.domain.analytic.PaywallClickedRetryContentLoadingHyperskillAnalyticEvent
8
8
import org.hyperskill.app.paywall.domain.analytic.PaywallClickedTermsOfServiceAndPrivacyPolicyHyperskillAnalyticEvent
9
+ import org.hyperskill.app.paywall.domain.analytic.PaywallSubscriptionPurchasedAppsFlyerAnalyticEvent
9
10
import org.hyperskill.app.paywall.domain.analytic.PaywallViewedHyperskillAnalyticEvent
10
11
import org.hyperskill.app.paywall.domain.model.PaywallTransitionSource
11
12
import org.hyperskill.app.paywall.presentation.PaywallFeature.Action
@@ -98,7 +99,12 @@ internal class PaywallReducer(
98
99
): ReducerResult =
99
100
if (state is State .Content ) {
100
101
when (message.purchaseResult) {
101
- is PurchaseResult .Succeed ,
102
+ is PurchaseResult .Succeed -> {
103
+ state.copy(isPurchaseSyncLoadingShowed = true ) to setOf (
104
+ InternalAction .SyncSubscription ,
105
+ InternalAction .LogAnalyticEvent (PaywallSubscriptionPurchasedAppsFlyerAnalyticEvent )
106
+ )
107
+ }
102
108
is PurchaseResult .Error .ProductAlreadyPurchasedError -> {
103
109
state.copy(isPurchaseSyncLoadingShowed = true ) to
104
110
setOf (InternalAction .SyncSubscription )
Original file line number Diff line number Diff line change
1
+ package org.hyperskill.paywall
2
+
3
+ import kotlin.test.Test
4
+ import kotlin.test.assertTrue
5
+ import org.hyperskill.ResourceProviderStub
6
+ import org.hyperskill.app.paywall.domain.analytic.PaywallSubscriptionPurchasedAppsFlyerAnalyticEvent
7
+ import org.hyperskill.app.paywall.domain.model.PaywallTransitionSource
8
+ import org.hyperskill.app.paywall.presentation.PaywallFeature
9
+ import org.hyperskill.app.paywall.presentation.PaywallFeature.InternalAction
10
+ import org.hyperskill.app.paywall.presentation.PaywallFeature.InternalMessage
11
+ import org.hyperskill.app.paywall.presentation.PaywallReducer
12
+ import org.hyperskill.app.purchases.domain.model.PurchaseResult
13
+
14
+ class PaywallTest {
15
+ private val reducer = PaywallReducer (
16
+ paywallTransitionSource = PaywallTransitionSource .LOGIN ,
17
+ resourceProvider = ResourceProviderStub ()
18
+ )
19
+
20
+ @Test
21
+ fun `Success subscription purchase should log analytic event` () {
22
+ val (_, actions) = reducer.reduce(
23
+ PaywallFeature .State .Content (formattedPrice = " " , isPurchaseSyncLoadingShowed = false ),
24
+ InternalMessage .MobileOnlySubscriptionPurchaseSuccess (
25
+ PurchaseResult .Succeed (orderId = null , productIds = emptyList())
26
+ )
27
+ )
28
+ assertTrue {
29
+ actions.any {
30
+ it == InternalAction .LogAnalyticEvent (PaywallSubscriptionPurchasedAppsFlyerAnalyticEvent )
31
+ }
32
+ }
33
+ }
34
+ }
You can’t perform that action at this time.
0 commit comments