Repository: Automattic/pocket-casts-android
File: modules/services/payment/src/test/kotlin/au/com/shiftyjelly/pocketcasts/payment/billing/BillingPaymentMapperTest.kt (Kotlin)

Code before:
                ),
            )
        }

        val products = googleProducts.map(mapper::toProduct)

        assertTrue(products.all { it == null })
        listener.assertMessages(
            "Missing billing period duration designator in {basePlanId=Base plan ID, productId=Product ID, rawDuration=1M}",
            "Missing billing period duration designator in {basePlanId=Base plan ID, productId=Product ID, rawDuration=D1M}",
            "Invalid billing period interval count '' in {basePlanId=Base plan ID, productId=Product ID, rawDuration=PM}",
            "Invalid billing period interval count '' in {basePlanId=Base plan ID, productId=Product ID, rawDuration=P-1M}",
            "Unrecognized billing interval period designator 'U' in {basePlanId=Base plan ID, productId=Product ID, rawDuration=P1U}",
            "Unrecognized billing interval period designator 'MY' in {basePlanId=Base plan ID, productId=Product ID, rawDuration=P1MY}",
            "Unrecognized billing interval period designator '' in {basePlanId=Base plan ID, productId=Product ID, rawDuration=P1}",
        )
    }

    @Test
    fun `map product with installment plan details`() {
        val googleProduct = createGoogleProductDetails(
            subscriptionOfferDetails = listOf(
                createGoogleOfferDetails(
                    offerId = null,
                    installmentPlanCommitmentPaymentsCount = 12,
                    subsequentInstallmentPlanCommitmentPaymentsCount = 0,
                ),
            ),
        )

        val basePlan = mapper.toProduct(googleProduct)!!.pricingPlans.basePlan

        assertNotNull(basePlan.installmentPlanDetails)
        assertEquals(12, basePlan.installmentPlanDetails?.commitmentPaymentsCount)
        assertEquals(0, basePlan.installmentPlanDetails?.subsequentCommitmentPaymentsCount)
    }

    @Test
    fun `map product without installment plan details`() {
        val googleProduct = createGoogleProductDetails(
            subscriptionOfferDetails = listOf(
                createGoogleOfferDetails(offerId = null),
            ),
        )

        val basePlan = mapper.toProduct(googleProduct)!!.pricingPlans.basePlan

        assertNull(basePlan.installmentPlanDetails)
    }

    @Test

Review comment (suggestion):
ℹ️ Often it is good to use a value different from `0` when testing. `0` is sometimes used as a default value in different APIs so having something else in a test guards against that.

Code after:
                ),
            )
        }

        val products = googleProducts.map(mapper::toProduct)

        assertTrue(products.all { it == null })
        listener.assertMessages(
            "Missing billing period duration designator in {basePlanId=Base plan ID, productId=Product ID, rawDuration=1M}",
            "Missing billing period duration designator in {basePlanId=Base plan ID, productId=Product ID, rawDuration=D1M}",
            "Invalid billing period interval count '' in {basePlanId=Base plan ID, productId=Product ID, rawDuration=PM}",
            "Invalid billing period interval count '' in {basePlanId=Base plan ID, productId=Product ID, rawDuration=P-1M}",
            "Unrecognized billing interval period designator 'U' in {basePlanId=Base plan ID, productId=Product ID, rawDuration=P1U}",
            "Unrecognized billing interval period designator 'MY' in {basePlanId=Base plan ID, productId=Product ID, rawDuration=P1MY}",
            "Unrecognized billing interval period designator '' in {basePlanId=Base plan ID, productId=Product ID, rawDuration=P1}",
        )
    }

    @Test
    fun `map product with installment plan details`() {
        val googleProduct = createGoogleProductDetails(
            subscriptionOfferDetails = listOf(
                createGoogleOfferDetails(
                    offerId = null,
                    installmentPlanCommitmentPaymentsCount = 12,
                    subsequentInstallmentPlanCommitmentPaymentsCount = 1,
                ),
            ),
        )

        val basePlan = mapper.toProduct(googleProduct)!!.pricingPlans.basePlan

        assertNotNull(basePlan.installmentPlanDetails)
        assertEquals(12, basePlan.installmentPlanDetails?.commitmentPaymentsCount)
        assertEquals(1, basePlan.installmentPlanDetails?.subsequentCommitmentPaymentsCount)
    }

    @Test
    fun `map product without installment plan details`() {
        val googleProduct = createGoogleProductDetails(
            subscriptionOfferDetails = listOf(
                createGoogleOfferDetails(offerId = null),
            ),
        )

        val basePlan = mapper.toProduct(googleProduct)!!.pricingPlans.basePlan

        assertNull(basePlan.installmentPlanDetails)
    }

    @Test