-
Notifications
You must be signed in to change notification settings - Fork 292
/
PackageVariablesTests.swift
275 lines (234 loc) · 13.8 KB
/
PackageVariablesTests.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
//
// Copyright RevenueCat Inc. All Rights Reserved.
//
// Licensed under the MIT License (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://opensource.org/licenses/MIT
//
// PackageVariablesTests.swift
//
// Created by Nacho Soto on 8/4/23.
import Nimble
import RevenueCat
@testable import RevenueCatUI
import XCTest
@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
class PackageVariablesTests: TestCase {
func testAppplicationName() {
expect(TestData.monthlyPackage.applicationName) == "xctest"
}
func testLocalizedPrice() {
expect(TestData.weeklyPackage.localizedPriceString) == "$1.99"
expect(TestData.monthlyPackage.localizedPriceString) == "$6.99"
expect(TestData.annualPackage.localizedPriceString) == "$53.99"
expect(TestData.lifetimePackage.localizedPriceString) == "$119.49"
}
func testLocalizedPricePerWeek() {
expect(TestData.weeklyPackage.localizedPricePerWeek) == "$1.99"
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) == "$8.64"
expect(TestData.monthlyPackage.localizedPricePerMonth) == "$6.99"
expect(TestData.threeMonthPackage.localizedPricePerMonth) == "$1.66"
expect(TestData.sixMonthPackage.localizedPricePerMonth) == "$1.33"
expect(TestData.annualPackage.localizedPricePerMonth) == "$4.49"
expect(TestData.lifetimePackage.localizedPricePerMonth) == "$119.49"
}
func testEnglishLocalizedPricePerPeriod() {
expect(TestData.weeklyPackage.localizedPricePerPeriod(Self.english)) == "$1.99/wk"
expect(TestData.monthlyPackage.localizedPricePerPeriod(Self.english)) == "$6.99/mo"
expect(TestData.threeMonthPackage.localizedPricePerPeriod(Self.english)) == "$4.99/3mo"
expect(TestData.sixMonthPackage.localizedPricePerPeriod(Self.english)) == "$7.99/6mo"
expect(TestData.annualPackage.localizedPricePerPeriod(Self.english)) == "$53.99/yr"
expect(TestData.lifetimePackage.localizedPricePerPeriod(Self.english)) == "$119.49"
}
func testSpanishLocalizedPricePerPeriod() {
expect(TestData.weeklyPackage.localizedPricePerPeriod(Self.spanish)) == "$1.99/sem"
expect(TestData.monthlyPackage.localizedPricePerPeriod(Self.spanish)) == "$6.99/m."
expect(TestData.threeMonthPackage.localizedPricePerPeriod(Self.spanish)) == "$4.99/3m"
expect(TestData.sixMonthPackage.localizedPricePerPeriod(Self.spanish)) == "$7.99/6m"
expect(TestData.annualPackage.localizedPricePerPeriod(Self.spanish)) == "$53.99/año"
expect(TestData.lifetimePackage.localizedPricePerPeriod(Self.spanish)) == "$119.49"
}
func testArabicLocalizedPricePerPeriod() {
let arabicPrice = "٣.٩٩ درهم"
expect(TestData.weeklyPackage.with(arabicPrice, Self.arabic).localizedPricePerPeriod(Self.arabic))
== "٣.٩٩ درهم/أسبوع"
expect(TestData.monthlyPackage.with(arabicPrice, Self.arabic).localizedPricePerPeriod(Self.arabic))
== "٣.٩٩ درهم/شهر"
expect(TestData.threeMonthPackage.with(arabicPrice, Self.arabic).localizedPricePerPeriod(Self.arabic))
== "٣.٩٩ درهم/3شهر"
expect(TestData.sixMonthPackage.with(arabicPrice, Self.arabic).localizedPricePerPeriod(Self.arabic))
== "٣.٩٩ درهم/6شهر"
expect(TestData.annualPackage.with(arabicPrice, Self.arabic).localizedPricePerPeriod(Self.arabic))
== "٣.٩٩ درهم/سنة"
expect(TestData.lifetimePackage.with(arabicPrice, Self.arabic).localizedPricePerPeriod(Self.arabic))
== "٣.٩٩ درهم"
}
func testEnglishLocalizedPriceAndPerMonth() {
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)"
expect(TestData.annualPackage.localizedPriceAndPerMonth(Self.english)) == "$53.99/yr ($4.49/mo)"
expect(TestData.lifetimePackage.localizedPriceAndPerMonth(Self.english)) == "$119.49"
}
func testSpanishLocalizedPriceAndPerMonth() {
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.)"
expect(TestData.annualPackage.localizedPriceAndPerMonth(Self.spanish)) == "$53.99/año ($4.49/m.)"
expect(TestData.lifetimePackage.localizedPriceAndPerMonth(Self.spanish)) == "$119.49"
}
func testArabicLocalizedPriceAndPerMonth() {
let arabicPrice = "٣.٩٩ درهم"
expect(TestData.weeklyPackage.with(arabicPrice, Self.arabic).localizedPriceAndPerMonth(Self.arabic))
.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))
.to(equalIgnoringRTL("٣.٩٩ درهم/3شهر (1.66 د.إ./شهر)"))
expect(TestData.sixMonthPackage.with(arabicPrice, Self.arabic).localizedPriceAndPerMonth(Self.arabic))
.to(equalIgnoringRTL("٣.٩٩ درهم/6شهر (1.33 د.إ./شهر)"))
expect(TestData.annualPackage.with(arabicPrice, Self.arabic).localizedPriceAndPerMonth(Self.arabic))
.to(equalIgnoringRTL("٣.٩٩ درهم/سنة (4.49 د.إ./شهر)"))
expect(TestData.lifetimePackage.with(arabicPrice, Self.arabic).localizedPriceAndPerMonth(Self.arabic))
== arabicPrice
}
func testProductName() {
expect(TestData.weeklyPackage.productName) == "Weekly"
expect(TestData.monthlyPackage.productName) == "Monthly"
expect(TestData.threeMonthPackage.productName) == "3 months"
expect(TestData.sixMonthPackage.productName) == "6 months"
expect(TestData.annualPackage.productName) == "Annual"
expect(TestData.lifetimePackage.productName) == "Lifetime"
}
func testEnglishPeriodName() {
expect(TestData.weeklyPackage.periodName(Self.english)) == "Weekly"
expect(TestData.monthlyPackage.periodName(Self.english)) == "Monthly"
expect(TestData.threeMonthPackage.periodName(Self.english)) == "3 Month"
expect(TestData.sixMonthPackage.periodName(Self.english)) == "6 Month"
expect(TestData.annualPackage.periodName(Self.english)) == "Annual"
expect(TestData.lifetimePackage.periodName(Self.english)) == "Lifetime"
}
func testSpanishPeriodName() {
expect(TestData.weeklyPackage.periodName(Self.spanish)) == "Semanalmente"
expect(TestData.monthlyPackage.periodName(Self.spanish)) == "Mensual"
expect(TestData.threeMonthPackage.periodName(Self.spanish)) == "3 meses"
expect(TestData.sixMonthPackage.periodName(Self.spanish)) == "6 meses"
expect(TestData.annualPackage.periodName(Self.spanish)) == "Anual"
expect(TestData.lifetimePackage.periodName(Self.spanish)) == "Toda la vida"
}
func testEnglishIntroductoryOfferDuration() {
expect(TestData.weeklyPackage.introductoryOfferDuration(Self.english)).to(beNil())
expect(TestData.monthlyPackage.introductoryOfferDuration(Self.english)) == "7 days"
expect(TestData.annualPackage.introductoryOfferDuration(Self.english)) == "14 days"
expect(TestData.lifetimePackage.introductoryOfferDuration(Self.english)).to(beNil())
}
func testSpanishIntroductoryOfferDuration() {
expect(TestData.weeklyPackage.introductoryOfferDuration(Self.spanish)).to(beNil())
expect(TestData.monthlyPackage.introductoryOfferDuration(Self.spanish)) == "7 días"
expect(TestData.annualPackage.introductoryOfferDuration(Self.spanish)) == "14 días"
expect(TestData.lifetimePackage.introductoryOfferDuration(Self.spanish)).to(beNil())
}
func testIntroductoryOfferPrice() {
expect(TestData.weeklyPackage.localizedIntroductoryOfferPrice).to(beNil())
expect(TestData.monthlyPackage.localizedIntroductoryOfferPrice) == "$0.00"
expect(TestData.annualPackage.localizedIntroductoryOfferPrice) == "$1.99"
expect(TestData.lifetimePackage.localizedIntroductoryOfferPrice).to(beNil())
}
func testEnglishRelativeDiscount() {
expect(TestData.weeklyPackage.localizedRelativeDiscount(nil, Self.english)).to(beNil())
expect(TestData.weeklyPackage.localizedRelativeDiscount(0.372, Self.english)) == "37% off"
}
func testSpanishRelativeDiscount() {
expect(TestData.weeklyPackage.localizedRelativeDiscount(nil, Self.spanish)).to(beNil())
expect(TestData.weeklyPackage.localizedRelativeDiscount(0.372, Self.spanish)) == "37% de descuento"
}
func testEnglishSubscriptionDuration() {
expect(TestData.weeklyPackage.subscriptionDuration(Self.english)) == "1 week"
expect(TestData.monthlyPackage.subscriptionDuration(Self.english)) == "1 month"
expect(TestData.threeMonthPackage.subscriptionDuration(Self.english)) == "3 months"
expect(TestData.sixMonthPackage.subscriptionDuration(Self.english)) == "6 months"
expect(TestData.annualPackage.subscriptionDuration(Self.english)) == "1 year"
expect(TestData.lifetimePackage.subscriptionDuration(Self.english)) == "Lifetime"
}
func testSpanishSubscriptionDuration() {
expect(TestData.weeklyPackage.subscriptionDuration(Self.spanish)) == "1 semana"
expect(TestData.monthlyPackage.subscriptionDuration(Self.spanish)) == "1 mes"
expect(TestData.threeMonthPackage.subscriptionDuration(Self.spanish)) == "3 meses"
expect(TestData.sixMonthPackage.subscriptionDuration(Self.spanish)) == "6 meses"
expect(TestData.annualPackage.subscriptionDuration(Self.spanish)) == "1 año"
expect(TestData.lifetimePackage.subscriptionDuration(Self.spanish)) == "Toda la vida"
}
func testEnglishNormalizedSubscriptionDuration() {
expect(TestData.weeklyPackage.normalizedSubscriptionDuration(Self.english)) == "1 week"
expect(TestData.monthlyPackage.normalizedSubscriptionDuration(Self.english)) == "1 month"
expect(TestData.threeMonthPackage.normalizedSubscriptionDuration(Self.english)) == "3 months"
expect(TestData.sixMonthPackage.normalizedSubscriptionDuration(Self.english)) == "6 months"
expect(TestData.annualPackage.normalizedSubscriptionDuration(Self.english)) == "12 months"
expect(TestData.lifetimePackage.normalizedSubscriptionDuration(Self.english)) == "Lifetime"
}
func testSpanishNormalizedSubscriptionDuration() {
expect(TestData.weeklyPackage.normalizedSubscriptionDuration(Self.spanish)) == "1 semana"
expect(TestData.monthlyPackage.normalizedSubscriptionDuration(Self.spanish)) == "1 mes"
expect(TestData.threeMonthPackage.normalizedSubscriptionDuration(Self.spanish)) == "3 meses"
expect(TestData.sixMonthPackage.normalizedSubscriptionDuration(Self.spanish)) == "6 meses"
expect(TestData.annualPackage.normalizedSubscriptionDuration(Self.spanish)) == "12 meses"
expect(TestData.lifetimePackage.normalizedSubscriptionDuration(Self.spanish)) == "Toda la vida"
}
}
@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
private extension PackageVariablesTests {
static let english: Locale = .init(identifier: "en_US")
static let spanish: Locale = .init(identifier: "es_ES")
static let arabic: Locale = .init(identifier: "ar_AE")
}
// MARK: -
@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
private extension Package {
func with(_ newLocalizedPrice: String, _ locale: Locale) -> Package {
return .init(
identifier: self.identifier,
packageType: self.packageType,
storeProduct: self.storeProduct
.toTestProduct()
.with(newLocalizedPrice, locale)
.toStoreProduct(),
offeringIdentifier: self.offeringIdentifier
)
}
}
@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
private extension TestStoreProduct {
func with(_ newLocalizedPrice: String, _ locale: Locale) -> Self {
var copy = self
copy.localizedPriceString = newLocalizedPrice
copy.locale = locale
return copy
}
}
@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
private extension StoreProduct {
func toTestProduct() -> TestStoreProduct {
return .init(
localizedTitle: self.localizedTitle,
price: self.price,
localizedPriceString: self.localizedPriceString,
productIdentifier: self.productIdentifier,
productType: self.productType,
localizedDescription: self.localizedDescription,
subscriptionGroupIdentifier: self.subscriptionGroupIdentifier,
subscriptionPeriod: self.subscriptionPeriod,
isFamilyShareable: self.isFamilyShareable
)
}
}