Skip to content

Commit

Permalink
Android: retrieve free trial period from the free phase (#446)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkVillacampa authored Jun 27, 2023
1 parent b202cd8 commit 2e3b416
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ val StoreProduct.priceString: String
val StoreProduct.priceCurrencyCode: String
get() = this.price.currencyCode
val StoreProduct.freeTrialPeriod: Period?
get() = this.subscriptionOptions?.freeTrial?.billingPeriod
get() = this.subscriptionOptions?.freeTrial?.freePhase?.billingPeriod
val StoreProduct.freeTrialCycles: Int?
get() = this.subscriptionOptions?.freeTrial?.freePhase?.billingCycleCount

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.revenuecat.purchases.hybridcommon.mappers

import com.revenuecat.purchases.models.Period
import com.revenuecat.purchases.models.Price
import com.revenuecat.purchases.models.PricingPhase
import com.revenuecat.purchases.models.RecurrenceMode
import com.revenuecat.purchases.models.StoreProduct
import io.mockk.every
import io.mockk.mockk
Expand All @@ -25,8 +28,12 @@ internal class StoreProductIntroPriceMapperTests {
inner class MappingFreeTrial {
@Test
fun `of 7 days, the map has the correct intro price values`() {
every { mockStoreProduct.freeTrialPeriod } returns Period(7, Period.Unit.DAY, "P7D")
every { mockStoreProduct.freeTrialCycles } returns 1
every { mockStoreProduct.subscriptionOptions?.freeTrial?.freePhase } returns PricingPhase(
price = Price("$0.00", 0, "USD"),
billingCycleCount = 1,
billingPeriod = Period(7, Period.Unit.DAY, "P7D"),
recurrenceMode = RecurrenceMode.NON_RECURRING,
)
received = mockStoreProduct.mapIntroPrice()
val expected = mapOf(
"price" to 0,
Expand All @@ -41,8 +48,12 @@ internal class StoreProductIntroPriceMapperTests {

@Test
fun `of 1 month, the map has the correct intro price values`() {
every { mockStoreProduct.freeTrialPeriod } returns Period(1, Period.Unit.MONTH, "P1M")
every { mockStoreProduct.freeTrialCycles } returns 1
every { mockStoreProduct.subscriptionOptions?.freeTrial?.freePhase } returns PricingPhase(
price = Price("$0.00", 0, "USD"),
billingCycleCount = 1,
billingPeriod = Period(1, Period.Unit.MONTH, "P1M"),
recurrenceMode = RecurrenceMode.NON_RECURRING,
)
received = mockStoreProduct.mapIntroPrice()
val expected = mapOf(
"price" to 0,
Expand All @@ -57,8 +68,12 @@ internal class StoreProductIntroPriceMapperTests {

@Test
fun `of 0 days, the map has the correct intro price values`() {
every { mockStoreProduct.freeTrialPeriod } returns Period(0, Period.Unit.DAY, "P0D")
every { mockStoreProduct.freeTrialCycles } returns 1
every { mockStoreProduct.subscriptionOptions?.freeTrial?.freePhase } returns PricingPhase(
price = Price("$0.00", 0, "USD"),
billingCycleCount = 1,
billingPeriod = Period(0, Period.Unit.DAY, "P0D"),
recurrenceMode = RecurrenceMode.NON_RECURRING,
)
received = mockStoreProduct.mapIntroPrice()

val expected = mapOf(
Expand Down

0 comments on commit 2e3b416

Please sign in to comment.