Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve price per month accuracy for weekly subscriptions #3480

Merged
merged 2 commits into from Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -167,7 +167,7 @@ private extension SubscriptionPeriod {
static let daysPerWeek: Decimal = 7
static let daysPerMonth: Decimal = 30
static let daysPerYear: Decimal = 365
static let weeksPerMonth: Decimal = 4
static let weeksPerMonth: Decimal = daysPerYear / monthsPerYear / daysPerWeek
static let weeksPerYear: Decimal = 52.14
static let monthsPerYear: Decimal = 12
}
Expand Down
14 changes: 7 additions & 7 deletions Tests/RevenueCatUITests/Data/PackageVariablesTests.swift
Expand Up @@ -32,15 +32,15 @@ class PackageVariablesTests: TestCase {

func testLocalizedPricePerWeek() {
expect(TestData.weeklyPackage.localizedPricePerWeek) == "$1.99"
expect(TestData.monthlyPackage.localizedPricePerWeek) == "$1.74"
expect(TestData.threeMonthPackage.localizedPricePerWeek) == "$0.41"
expect(TestData.sixMonthPackage.localizedPricePerWeek) == "$0.33"
expect(TestData.monthlyPackage.localizedPricePerWeek) == "$1.60"
expect(TestData.threeMonthPackage.localizedPricePerWeek) == "$0.38"
expect(TestData.sixMonthPackage.localizedPricePerWeek) == "$0.30"
expect(TestData.annualPackage.localizedPricePerWeek) == "$1.03"
expect(TestData.lifetimePackage.localizedPricePerWeek) == "$119.49"
}

func testLocalizedPricePerMonth() {
expect(TestData.weeklyPackage.localizedPricePerMonth) == "$7.96"
expect(TestData.weeklyPackage.localizedPricePerMonth) == "$8.64"
expect(TestData.monthlyPackage.localizedPricePerMonth) == "$6.99"
expect(TestData.threeMonthPackage.localizedPricePerMonth) == "$1.66"
expect(TestData.sixMonthPackage.localizedPricePerMonth) == "$1.33"
Expand Down Expand Up @@ -84,7 +84,7 @@ class PackageVariablesTests: TestCase {
}

func testEnglishLocalizedPriceAndPerMonth() {
expect(TestData.weeklyPackage.localizedPriceAndPerMonth(Self.english)) == "$1.99/wk ($7.96/mo)"
expect(TestData.weeklyPackage.localizedPriceAndPerMonth(Self.english)) == "$1.99/wk ($8.64/mo)"
expect(TestData.monthlyPackage.localizedPriceAndPerMonth(Self.english)) == "$6.99/mo"
expect(TestData.threeMonthPackage.localizedPriceAndPerMonth(Self.english)) == "$4.99/3mo ($1.66/mo)"
expect(TestData.sixMonthPackage.localizedPriceAndPerMonth(Self.english)) == "$7.99/6mo ($1.33/mo)"
Expand All @@ -93,7 +93,7 @@ class PackageVariablesTests: TestCase {
}

func testSpanishLocalizedPriceAndPerMonth() {
expect(TestData.weeklyPackage.localizedPriceAndPerMonth(Self.spanish)) == "$1.99/sem ($7.96/m.)"
expect(TestData.weeklyPackage.localizedPriceAndPerMonth(Self.spanish)) == "$1.99/sem ($8.64/m.)"
expect(TestData.monthlyPackage.localizedPriceAndPerMonth(Self.spanish)) == "$6.99/m."
expect(TestData.threeMonthPackage.localizedPriceAndPerMonth(Self.spanish)) == "$4.99/3m ($1.66/m.)"
expect(TestData.sixMonthPackage.localizedPriceAndPerMonth(Self.spanish)) == "$7.99/6m ($1.33/m.)"
Expand All @@ -105,7 +105,7 @@ class PackageVariablesTests: TestCase {
let arabicPrice = "٣.٩٩ درهم"

expect(TestData.weeklyPackage.with(arabicPrice, Self.arabic).localizedPriceAndPerMonth(Self.arabic))
.to(equalIgnoringRTL("٣.٩٩ درهم/أسبوع (‏7.96 ‏د.إ.‏/شهر)"))
.to(equalIgnoringRTL("٣.٩٩ درهم/أسبوع (‏8.64 ‏د.إ.‏/شهر)"))
expect(TestData.monthlyPackage.with(arabicPrice, Self.arabic).localizedPriceAndPerMonth(Self.arabic))
.to(equalIgnoringRTL("٣.٩٩ درهم/شهر"))
expect(TestData.threeMonthPackage.with(arabicPrice, Self.arabic).localizedPriceAndPerMonth(Self.arabic))
Expand Down
Expand Up @@ -51,9 +51,9 @@ class SubscriptionPeriodTests: TestCase {
.init(p(14, .day), 2, 1),
.init(p(1, .week), 10, 10),
.init(p(2, .week), 10, 5),
.init(p(1, .month), 14.99, 3.74),
.init(p(2, .month), 30, 3.75),
.init(p(3, .month), 40, 3.33),
.init(p(1, .month), 14.99, 3.44),
.init(p(2, .month), 30, 3.45),
.init(p(3, .month), 40, 3.06),
.init(p(1, .year), 120, 2.3),
.init(p(1, .year), 50, 0.95),
.init(p(1, .year), 29.99, 0.57),
Expand All @@ -77,8 +77,8 @@ class SubscriptionPeriodTests: TestCase {
let tests: [Test] = [
.init(p(1, .day), 2, 60),
.init(p(15, .day), 5, 10),
.init(p(1, .week), 10, 40),
.init(p(2, .week), 10, 20),
.init(p(1, .week), 10, 43.45),
.init(p(2, .week), 10, 21.72),
.init(p(1, .month), 14.99, 14.99),
.init(p(2, .month), 30, 15),
.init(p(3, .month), 40, 13.33),
Expand Down