package com.suno.android.common_data.mappers.cms 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.CountdownSchema 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.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.assertNotNull import org.junit.Assert.assertNull import org.junit.Test import java.time.Instant class SubscriptionPageCmsTest { // CountdownSchema to CountdownContent mapping tests @Test fun `given CountdownSchema with valid data when mapping then returns CountdownContent with parsed timestamp`() { // Given val timestamp = "2025-12-31T23:59:59Z" val countdownSchema = CountdownSchema( text = "Sale ends in:", timestamp = timestamp, ) // When val result = countdownSchema.toCountdownContent() // Then assertEquals("Sale ends in:", result?.text) assertEquals(Instant.parse(timestamp), result?.timestamp) } @Test fun `given CountdownSchema with null text when mapping then returns null`() { // Given val timestamp = "2025-12-31T23:59:59Z" val countdownSchema = CountdownSchema( text = null, timestamp = timestamp, ) // When val result = countdownSchema.toCountdownContent() // Then assertNull(result?.text) assertNull(result?.timestamp) } // ContentSchema to SubscriptionPageCmsContent mapping tests with countdown @Test fun `given ContentSchema with countdown when mapping then includes countdown in result`() { // Given val timestamp = "2025-12-31T23:59:59Z" val countdownSchema = CountdownSchema( text = "Limited time offer!", timestamp = timestamp, ) val contentSchema = ContentSchema( salesBadge = null, countdown = countdownSchema, billingPeriodToggle = null, plans = null, featureComparison = null, ) val schema = SubscriptionPageCmsSchema( content = contentSchema, language = "en", ) // When val result = schema.toSubscriptionPageCmsContent() // Then assertNotNull(result.countdown) assertEquals("Limited time offer!", result.countdown?.text) assertEquals(Instant.parse(timestamp), result.countdown?.timestamp) } @Test fun `given ContentSchema with null countdown when mapping then countdown is null in result`() { // Given val contentSchema = ContentSchema( salesBadge = null, countdown = null, billingPeriodToggle = null, plans = null, featureComparison = null, ) val schema = SubscriptionPageCmsSchema( content = contentSchema, language = "en", ) // When val result = schema.toSubscriptionPageCmsContent() // Then assertNull(result.countdown) } @Test fun `given SubscriptionPageCmsSchema with null content when mapping then countdown is null`() { // Given val schema = SubscriptionPageCmsSchema( content = null, language = "en", ) // When val result = schema.toSubscriptionPageCmsContent() // Then assertNull(result.countdown) } @Test fun `given ContentSchema with all properties when mapping then all are mapped correctly`() { // Given val timestamp = "2025-12-31T23:59:59Z" val countdownSchema = CountdownSchema( text = "Sale ends in:", timestamp = timestamp, ) val salesBadge = BadgeSchema( text = "50% OFF", backgroundColor = "#FF0000", textColor = "#FFFFFF", ) val billingPeriodToggle = BillingPeriodToggleSchema( monthlyLabel = TextSchema(text = "Monthly"), annualLabel = TextSchema(text = "Annual"), discountBadge = BadgeSchema( text = "SAVE 20%", backgroundColor = "#00FF00", textColor = "#000000", ), ) val plans = PlansSchema( pro = PlanSchema( displayName = TextSchema(text = "Pro"), tagline = TextSchema(text = "For professionals"), highlightFeatures = listOf("Feature 1", "Feature 2"), ctaPrimary = TextSchema(text = "Subscribe"), badge = null, stickers = null, ), free = null, premier = null, ) val featureComparison = FeatureComparisonSchema( sectionHeader = TextSchema(text = "Compare Plans"), features = listOf( FeatureSchema( featureName = TextSchema(text = "Storage"), values = listOf( FeatureValueSchema(text = "Unlimited", icon = "check"), ), ), ), ) val contentSchema = ContentSchema( salesBadge = salesBadge, countdown = countdownSchema, billingPeriodToggle = billingPeriodToggle, plans = plans, featureComparison = featureComparison, ) val schema = SubscriptionPageCmsSchema( content = contentSchema, language = "en", ) // When val result = schema.toSubscriptionPageCmsContent() // Then // Verify countdown assertNotNull(result.countdown) assertEquals("Sale ends in:", result.countdown?.text) assertEquals(Instant.parse(timestamp), result.countdown?.timestamp) // Verify sales badge assertNotNull(result.salesBadge) assertEquals("50% OFF", result.salesBadge?.text) assertEquals("#FF0000", result.salesBadge?.backgroundColor) assertEquals("#FFFFFF", result.salesBadge?.textColor) // Verify billing period toggle assertNotNull(result.billingPeriodToggle) assertEquals("Monthly", result.billingPeriodToggle?.monthlyLabel?.text) assertEquals("Annual", result.billingPeriodToggle?.annualLabel?.text) assertEquals("SAVE 20%", result.billingPeriodToggle?.discountBadge?.text) // Verify plans assertNotNull(result.plans) assertNotNull(result.plans?.pro) assertEquals("Pro", result.plans?.pro?.displayName?.text) assertEquals("For professionals", result.plans?.pro?.tagline?.text) assertEquals(2, result.plans?.pro?.highlightFeatures?.size) assertEquals("Subscribe", result.plans?.pro?.ctaPrimary?.text) // Verify feature comparison assertNotNull(result.featureComparison) assertEquals("Compare Plans", result.featureComparison?.sectionHeader?.text) assertEquals(1, result.featureComparison?.features?.size) // Verify language assertEquals("en", result.language) } // BadgeSchema mapping tests @Test fun `given BadgeSchema with all properties when mapping then returns BadgeContent with all properties`() { // Given val badgeSchema = BadgeSchema( text = "SALE", backgroundColor = "#FF0000", textColor = "#FFFFFF", ) // When val result = badgeSchema.toBadgeContent() // Then assertEquals("SALE", result.text) assertEquals("#FF0000", result.backgroundColor) assertEquals("#FFFFFF", result.textColor) } @Test fun `given BadgeSchema with null properties when mapping then returns BadgeContent with null properties`() { // Given val badgeSchema = BadgeSchema( text = null, backgroundColor = null, textColor = null, ) // When val result = badgeSchema.toBadgeContent() // Then assertNull(result.text) assertNull(result.backgroundColor) assertNull(result.textColor) } // TextSchema mapping tests @Test fun `given TextSchema with text when mapping then returns TextContent with text`() { // Given val textSchema = TextSchema(text = "Test text") // When val result = textSchema.toTextContent() // Then assertEquals("Test text", result.text) } @Test fun `given TextSchema with null text when mapping then returns TextContent with null text`() { // Given val textSchema = TextSchema(text = null) // When val result = textSchema.toTextContent() // Then assertNull(result.text) } // PlansContent.getPlan tests @Test fun `given pro plan key when getting plan then returns pro plan`() { // Given val proContent = createPlanContent("Pro") val plansContent = PlansContent(pro = proContent, free = null, premier = null) // When val result = plansContent.getPlan("pro") // Then assertEquals(proContent, result) } @Test fun `given free plan key when getting plan then returns free plan`() { // Given val freeContent = createPlanContent("Free") val plansContent = PlansContent(pro = null, free = freeContent, premier = null) // When val result = plansContent.getPlan("free") // Then assertEquals(freeContent, result) } @Test fun `given premier plan key when getting plan then returns premier plan`() { // Given val premierContent = createPlanContent("Premier") val plansContent = PlansContent(pro = null, free = null, premier = premierContent) // When val result = plansContent.getPlan("premier") // Then assertEquals(premierContent, result) } @Test fun `given uppercase plan key when getting plan then returns plan case-insensitively`() { // Given val proContent = createPlanContent("Pro") val plansContent = PlansContent(pro = proContent, free = null, premier = null) // When val result = plansContent.getPlan("PRO") // Then assertEquals(proContent, result) } @Test fun `given unknown plan key when getting plan then returns null`() { // Given val plansContent = PlansContent(pro = null, free = null, premier = null) // When val result = plansContent.getPlan("unknown") // Then assertNull(result) } // PlanSchema mapping tests @Test fun `given PlanSchema with all properties when mapping then returns PlanContent with all properties`() { // Given val planSchema = PlanSchema( displayName = TextSchema(text = "Pro Plan"), tagline = TextSchema(text = "Best for professionals"), highlightFeatures = listOf("Unlimited storage", "Priority support"), ctaPrimary = TextSchema(text = "Get Started"), badge = BadgeSchema(text = "POPULAR", backgroundColor = "#FFD700", textColor = "#000000"), stickers = null, ) // When val result = planSchema.toPlanContent() // Then assertEquals("Pro Plan", result.displayName?.text) assertEquals("Best for professionals", result.tagline?.text) assertEquals(2, result.highlightFeatures?.size) assertEquals("Unlimited storage", result.highlightFeatures?.get(0)) assertEquals("Priority support", result.highlightFeatures?.get(1)) assertEquals("Get Started", result.ctaPrimary?.text) assertNotNull(result.badge) assertEquals("POPULAR", result.badge?.text) } // FeatureComparisonSchema mapping tests @Test fun `given FeatureComparisonSchema with features when mapping then maps features correctly`() { // Given val featureSchema = FeatureComparisonSchema( sectionHeader = TextSchema(text = "Features"), features = listOf( FeatureSchema( featureName = TextSchema(text = "Storage"), values = listOf( FeatureValueSchema(text = "100GB", icon = "storage"), ), ), ), ) // When val result = featureSchema.toFeatureComparisonContent() // Then assertEquals("Features", result.sectionHeader?.text) assertEquals(1, result.features?.size) assertEquals("Storage", result.features?.get(0)?.featureName?.text) assertEquals(1, result.features?.get(0)?.values?.size) assertEquals("100GB", result.features?.get(0)?.values?.get(0)?.text) assertEquals("storage", result.features?.get(0)?.values?.get(0)?.icon) } @Test fun `given FeatureComparisonSchema with null features when mapping then features are null`() { // Given val featureSchema = FeatureComparisonSchema( sectionHeader = TextSchema(text = "Features"), features = null, ) // When val result = featureSchema.toFeatureComparisonContent() // Then assertEquals("Features", result.sectionHeader?.text) assertNull(result.features) } // Helper function to create PlanContent for testing private fun createPlanContent( name: String, ): PlanContent = PlanContent( displayName = TextContent(text = name), tagline = TextContent(text = "$name tagline"), highlightFeatures = listOf("Feature 1", "Feature 2"), ctaPrimary = TextContent(text = "Subscribe"), badge = null, stickers = null, ) }