|
| 1 | +/* |
| 2 | + * Copyright (c) 2025 DuckDuckGo |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package com.duckduckgo.subscriptions.impl.billing |
| 18 | + |
| 19 | +import com.duckduckgo.subscriptions.impl.PricingPhase |
| 20 | +import junit.framework.TestCase.assertEquals |
| 21 | +import junit.framework.TestCase.assertNull |
| 22 | +import org.junit.Test |
| 23 | + |
| 24 | +class PricingPhaseTest { |
| 25 | + @Test |
| 26 | + fun billingPeriodParsesDaysCorrectly() { |
| 27 | + val phase = PricingPhase(formattedPrice = "Free", billingPeriod = "P10D") |
| 28 | + assertEquals(10, phase.getBillingPeriodInDays()) |
| 29 | + } |
| 30 | + |
| 31 | + @Test |
| 32 | + fun billingPeriodParsesWeeksCorrectly() { |
| 33 | + val phase = PricingPhase(formattedPrice = "Free", billingPeriod = "P2W") |
| 34 | + assertEquals(14, phase.getBillingPeriodInDays()) |
| 35 | + } |
| 36 | + |
| 37 | + @Test |
| 38 | + fun billingPeriodParsesMonthsCorrectly() { |
| 39 | + val phase = PricingPhase(formattedPrice = "Free", billingPeriod = "P2M") |
| 40 | + assertEquals(60, phase.getBillingPeriodInDays()) |
| 41 | + } |
| 42 | + |
| 43 | + @Test |
| 44 | + fun billingPeriodParsesYearsCorrectly() { |
| 45 | + val phase = PricingPhase(formattedPrice = "Free", billingPeriod = "P1Y") |
| 46 | + assertEquals(365, phase.getBillingPeriodInDays()) |
| 47 | + } |
| 48 | + |
| 49 | + @Test |
| 50 | + fun billingPeriodParsesMixedPeriodCorrectly() { |
| 51 | + val phase = PricingPhase(formattedPrice = "Free", billingPeriod = "P1Y2M10D") |
| 52 | + val expectedDays = 1 * 365 + 2 * 30 + 10 // 365 + 60 + 10 = 435 |
| 53 | + assertEquals(expectedDays, phase.getBillingPeriodInDays()) |
| 54 | + } |
| 55 | + |
| 56 | + @Test |
| 57 | + fun billingPeriodEmptyReturnsNull() { |
| 58 | + val phase = PricingPhase(formattedPrice = "$0", billingPeriod = "") |
| 59 | + assertNull(phase.getBillingPeriodInDays()) |
| 60 | + } |
| 61 | + |
| 62 | + @Test |
| 63 | + fun billingPeriodReturnsNullForInvalidFormat() { |
| 64 | + val phase = PricingPhase(formattedPrice = "Free", billingPeriod = "INVALID") |
| 65 | + assertNull(phase.getBillingPeriodInDays()) |
| 66 | + } |
| 67 | +} |
0 commit comments