package com.suno.android.common_data.mappers.cms import com.suno.android.common_core_utils.model.Url import com.suno.android.common_networking.remote.entities.BadgeSchema import com.suno.android.common_networking.remote.entities.BillingPeriodToggleSchema import com.suno.android.common_networking.remote.entities.ContentSchema import com.suno.android.common_networking.remote.entities.FeatureComparisonSchema import com.suno.android.common_networking.remote.entities.FeatureSchema import com.suno.android.common_networking.remote.entities.FeatureValueSchema import com.suno.android.common_networking.remote.entities.PlanSchema import com.suno.android.common_networking.remote.entities.PlanStickerSchema import com.suno.android.common_networking.remote.entities.PlansSchema import com.suno.android.common_networking.remote.entities.SubscriptionPageCmsSchema import com.suno.android.common_networking.remote.entities.TextSchema import org.junit.Assert.assertEquals import org.junit.Assert.assertNull import org.junit.Test class SubscriptionPageCmsMapperTest { @Test fun `given PlanSchema with stickerUrl when toPlanContent then stickerUrl is mapped`() { val stickerUrl = "https://example.com/sticker.png" val schema = createPlanSchema(stickerUrl = stickerUrl) val result = schema.toPlanContent() assertEquals(Url(stickerUrl), result.stickers?.monthly) } @Test fun `given PlanSchema with null stickerUrl when toPlanContent then stickerUrl is null`() { val schema = createPlanSchema(stickerUrl = null) val result = schema.toPlanContent() assertNull(result.stickers?.monthly) } @Test fun `given PlansSchema with pro plan containing stickerUrl when toPlansContent then pro plan has stickerUrl`() { val stickerUrl = "https://example.com/pro-sticker.png" val proPlan = createPlanSchema(stickerUrl = stickerUrl) val schema = PlansSchema( pro = proPlan, free = null, premier = null, ) val result = schema.toPlansContent() assertEquals(Url(stickerUrl), result.pro?.stickers?.monthly) } @Test fun `given PlansSchema with premier plan containing stickerUrl when toPlansContent then plan has stickerUrl`() { val stickerUrl = "https://example.com/premier-sticker.png" val premierPlan = createPlanSchema(stickerUrl = stickerUrl) val schema = PlansSchema( pro = null, free = null, premier = premierPlan, ) val result = schema.toPlansContent() assertEquals(Url(stickerUrl), result.premier?.stickers?.monthly) } @Test fun `given SubscriptionPageCmsSchema with plans containing stickerUrls then stickerUrls are mapped`() { val proStickerUrl = "https://example.com/pro-sticker.png" val premierStickerUrl = "https://example.com/premier-sticker.png" val schema = SubscriptionPageCmsSchema( content = ContentSchema( salesBadge = null, countdown = null, billingPeriodToggle = null, plans = PlansSchema( pro = createPlanSchema(stickerUrl = proStickerUrl), free = createPlanSchema(stickerUrl = null), premier = createPlanSchema(stickerUrl = premierStickerUrl), ), featureComparison = null, ), language = "en", ) val result = schema.toSubscriptionPageCmsContent() assertEquals(Url(proStickerUrl), result.plans?.pro?.stickers?.monthly) assertNull(result.plans?.free?.stickers?.monthly) assertEquals(Url(premierStickerUrl), result.plans?.premier?.stickers?.monthly) } @Test fun `given PlanSchema with all fields when toPlanContent then all fields are mapped correctly`() { val displayName = TextSchema("Pro Plan") val tagline = TextSchema("Best for professionals") val highlightFeatures = listOf("Feature 1", "Feature 2") val ctaPrimary = TextSchema("Subscribe Now") val badge = BadgeSchema("Popular", "#FF0000", "#FFFFFF") val stickerUrl = "https://example.com/sticker.png" val stickers = PlanStickerSchema( monthly = stickerUrl, annual = stickerUrl, ) val schema = PlanSchema( displayName = displayName, tagline = tagline, highlightFeatures = highlightFeatures, ctaPrimary = ctaPrimary, badge = badge, stickers = stickers, ) val result = schema.toPlanContent() assertEquals("Pro Plan", result.displayName?.text) assertEquals("Best for professionals", result.tagline?.text) assertEquals(highlightFeatures, result.highlightFeatures) assertEquals("Subscribe Now", result.ctaPrimary?.text) assertEquals("Popular", result.badge?.text) assertEquals(Url(stickerUrl), result.stickers?.monthly) } @Test fun `given PlansContent with pro key when getPlan then returns pro plan with stickerUrl`() { val stickerUrl = "https://example.com/pro-sticker.png" val content = PlansContent( pro = PlanContent( displayName = TextContent("Pro"), tagline = null, highlightFeatures = null, ctaPrimary = null, badge = null, stickers = PlanStickerContent( monthly = Url(stickerUrl), annual = Url(stickerUrl), ), ), free = null, premier = null, ) val result = content.getPlan("pro") assertEquals(Url(stickerUrl), result?.stickers?.monthly) } @Test fun `given PlansContent with premier key when getPlan then returns premier plan with stickerUrl`() { val stickerUrl = "https://example.com/premier-sticker.png" val content = PlansContent( pro = null, free = null, premier = PlanContent( displayName = TextContent("Premier"), tagline = null, highlightFeatures = null, ctaPrimary = null, badge = null, stickers = PlanStickerContent( monthly = Url(stickerUrl), annual = Url(stickerUrl), ), ), ) val result = content.getPlan("premier") assertEquals(Url(stickerUrl), result?.stickers?.monthly) } @Test fun `given PlansContent with free key when getPlan then returns free plan with stickerUrl`() { val stickerUrl = "https://example.com/free-sticker.png" val content = PlansContent( pro = null, free = PlanContent( displayName = TextContent("Free"), tagline = null, highlightFeatures = null, ctaPrimary = null, badge = null, stickers = PlanStickerContent( monthly = Url(stickerUrl), annual = Url(stickerUrl), ), ), premier = null, ) val result = content.getPlan("free") assertEquals(Url(stickerUrl), result?.stickers?.monthly) } @Test fun `given BadgeSchema when toBadgeContent then badge is mapped correctly`() { val schema = BadgeSchema( text = "Limited Offer", backgroundColor = "#FF0000", textColor = "#FFFFFF", ) val result = schema.toBadgeContent() assertEquals("Limited Offer", result.text) assertEquals("#FF0000", result.backgroundColor) assertEquals("#FFFFFF", result.textColor) } @Test fun `given TextSchema when toTextContent then text is mapped correctly`() { val schema = TextSchema("Sample Text") val result = schema.toTextContent() assertEquals("Sample Text", result.text) } @Test fun `given BillingPeriodToggleSchema when toBillingPeriodToggleContent then all fields are mapped`() { val schema = BillingPeriodToggleSchema( monthlyLabel = TextSchema("Monthly"), annualLabel = TextSchema("Annual"), discountBadge = BadgeSchema("Save 20%", "#00FF00", "#000000"), ) val result = schema.toBillingPeriodToggleContent() assertEquals("Monthly", result.monthlyLabel?.text) assertEquals("Annual", result.annualLabel?.text) assertEquals("Save 20%", result.discountBadge?.text) } @Test fun `given FeatureValueSchema when toFeatureValueContent then fields are mapped`() { val schema = FeatureValueSchema( text = "Unlimited", icon = "check", ) val result = schema.toFeatureValueContent() assertEquals("Unlimited", result.text) assertEquals("check", result.icon) } @Test fun `given FeatureSchema when toFeatureContent then fields are mapped`() { val schema = FeatureSchema( featureName = TextSchema("Credits"), values = listOf( FeatureValueSchema("100", "check"), FeatureValueSchema("Unlimited", "check"), ), ) val result = schema.toFeatureContent() assertEquals("Credits", result.featureName?.text) assertEquals(2, result.values?.size) assertEquals("100", result.values?.get(0)?.text) assertEquals("Unlimited", result.values?.get(1)?.text) } @Test fun `given FeatureComparisonSchema when toFeatureComparisonContent then fields are mapped`() { val schema = FeatureComparisonSchema( sectionHeader = TextSchema("Compare Plans"), features = listOf( FeatureSchema( featureName = TextSchema("Credits"), values = listOf(FeatureValueSchema("100", "check")), ), ), ) val result = schema.toFeatureComparisonContent() assertEquals("Compare Plans", result.sectionHeader?.text) assertEquals(1, result.features?.size) assertEquals("Credits", result.features?.get(0)?.featureName?.text) } @Test fun `given complete SubscriptionPageCmsSchema when toSubscriptionPageCmsContent then all fields are mapped`() { val schema = SubscriptionPageCmsSchema( content = ContentSchema( salesBadge = BadgeSchema("Limited Time", "#FF0000", "#FFFFFF"), countdown = null, billingPeriodToggle = BillingPeriodToggleSchema( monthlyLabel = TextSchema("Monthly"), annualLabel = TextSchema("Annual"), discountBadge = BadgeSchema("Save 20%", "#00FF00", "#000000"), ), plans = PlansSchema( pro = createPlanSchema(stickerUrl = "https://example.com/pro.png"), free = createPlanSchema(stickerUrl = null), premier = createPlanSchema(stickerUrl = "https://example.com/premier.png"), ), featureComparison = FeatureComparisonSchema( sectionHeader = TextSchema("Compare Plans"), features = listOf(), ), ), language = "en", ) val result = schema.toSubscriptionPageCmsContent() assertEquals("Limited Time", result.salesBadge?.text) assertEquals("Monthly", result.billingPeriodToggle?.monthlyLabel?.text) assertEquals(Url("https://example.com/pro.png"), result.plans?.pro?.stickers?.monthly) assertNull(result.plans?.free?.stickers?.monthly) assertEquals(Url("https://example.com/premier.png"), result.plans?.premier?.stickers?.monthly) assertEquals("Compare Plans", result.featureComparison?.sectionHeader?.text) assertEquals("en", result.language) } private fun createPlanSchema( stickerUrl: String?, ) = PlanSchema( displayName = TextSchema("Test Plan"), tagline = TextSchema("Test Tagline"), highlightFeatures = listOf(), ctaPrimary = TextSchema("Subscribe"), badge = null, stickers = PlanStickerSchema( monthly = stickerUrl, annual = stickerUrl, ), ) }