Skip to content

Commit

Permalink
Paywalls: improve error display (#1558)
Browse files Browse the repository at this point in the history
  • Loading branch information
NachoSoto authored Jan 17, 2024
1 parent abbbfd4 commit aeb374a
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,9 @@ internal class PaywallViewModelImpl(
}

if (currentOffering == null) {
_state.value = PaywallState.Error("No offering or current offering")
_state.value = PaywallState.Error(
"The RevenueCat dashboard does not have a current offering configured.",
)
} else {
_state.value = calculateState(
currentOffering,
Expand All @@ -236,7 +238,9 @@ internal class PaywallViewModelImpl(
)
}
} catch (e: PurchasesException) {
_state.value = PaywallState.Error(e.toString())
_state.value = PaywallState.Error(
"Error ${e.code.code}: ${e.code.description}",
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,51 @@ class PaywallViewModelTest {
.isTrue
}

@Test
fun `Error loading offerings`() {
coEvery { purchases.awaitOfferings() } throws PurchasesException(
PurchasesError(PurchasesErrorCode.NetworkError
))

val model = create(
activeSubscriptions = setOf(TestData.Packages.monthly.product.id),
nonSubscriptionTransactionProductIdentifiers = setOf(TestData.Packages.lifetime.product.id)
)

coVerify { purchases.awaitOfferings() }

val state = model.state.value
if (state !is PaywallState.Error) {
fail("Invalid state")
return
}

assertThat(state.errorMessage).isEqualTo("Error 10: Error performing request.")
}

@Test
fun `Error loading empty offerings`() {
coEvery { purchases.awaitOfferings() } returns Offerings(
null,
mapOf()
)

val model = create(
activeSubscriptions = setOf(TestData.Packages.monthly.product.id),
nonSubscriptionTransactionProductIdentifiers = setOf(TestData.Packages.lifetime.product.id)
)

coVerify { purchases.awaitOfferings() }

val state = model.state.value
if (state !is PaywallState.Error) {
fail("Invalid state")
return
}

assertThat(state.errorMessage).isEqualTo("The RevenueCat dashboard does not have a current offering configured.")
}

@Test
fun `Should load selected offering`() {
val offering = TestData.template1Offering
Expand Down

0 comments on commit aeb374a

Please sign in to comment.