forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplan_pricing_test.dart
More file actions
213 lines (193 loc) · 6.82 KB
/
Copy pathplan_pricing_test.dart
File metadata and controls
213 lines (193 loc) · 6.82 KB
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
import 'package:flutter_test/flutter_test.dart';
import 'package:omi/utils/plan_pricing.dart';
List<Map<String, dynamic>> _tier({num? monthly, num? yearly}) {
return [
if (monthly != null) {'interval': 'month', 'unit_amount': monthly},
if (yearly != null) {'interval': 'year', 'unit_amount': yearly},
];
}
void main() {
// Returns a count rather than a label: the English 'N Months Free' string it
// used to build could not be translated. The rendered badge is covered in
// test/unit/plans_sheet_l10n_test.dart.
group('annualMonthsFree', () {
test('Plus and Unlimited save 3 months, not the hardcoded 2', () {
// Regression: the badge was hardcoded to '2 Months Free', which was only
// ever right for legacy Neo. Plus ($17.99/mo, $161.91/yr) and Unlimited
// ($29.99/mo, $269.91/yr) both bill 9 months for a year.
expect(annualMonthsFree(_tier(monthly: 1799, yearly: 16191)), 3);
expect(annualMonthsFree(_tier(monthly: 2999, yearly: 26991)), 3);
});
test('legacy Neo still shows 2 months', () {
expect(annualMonthsFree(_tier(monthly: 1999, yearly: 19999)), 2);
});
test('a single free month is still reported', () {
expect(annualMonthsFree(_tier(monthly: 1000, yearly: 11000)), 1);
});
test('returns null when the annual plan is not cheaper', () {
expect(annualMonthsFree(_tier(monthly: 1000, yearly: 12000)), isNull);
expect(annualMonthsFree(_tier(monthly: 1000, yearly: 13000)), isNull);
});
test('returns null when a price is missing or unusable', () {
expect(annualMonthsFree(_tier(monthly: 1799)), isNull);
expect(annualMonthsFree(_tier(yearly: 16191)), isNull);
expect(annualMonthsFree(const []), isNull);
expect(annualMonthsFree(_tier(monthly: 0, yearly: 16191)), isNull);
});
});
group('annualDiscountPercent', () {
test('Plus and Unlimited discount 25%, not the hardcoded 17%', () {
// Regression: the yearly-toggle badge was a hardcoded "Save ~17%" string
// in all 49 locales. 17% is the legacy Neo discount; 3 months free is 25%.
expect(annualDiscountPercent(_tier(monthly: 1799, yearly: 16191)), 25);
expect(annualDiscountPercent(_tier(monthly: 2999, yearly: 26991)), 25);
});
test('legacy Neo still discounts ~17%', () {
expect(annualDiscountPercent(_tier(monthly: 1999, yearly: 19999)), 17);
});
test('returns null when annual is not cheaper or prices are unusable', () {
expect(annualDiscountPercent(_tier(monthly: 1000, yearly: 12000)), isNull);
expect(annualDiscountPercent(_tier(monthly: 1000, yearly: 13000)), isNull);
expect(annualDiscountPercent(_tier(monthly: 1799)), isNull);
expect(annualDiscountPercent(const []), isNull);
});
});
group('bestAnnualDiscountPercent', () {
test('advertises the best discount across the shown tiers', () {
final neo = _tier(monthly: 1999, yearly: 19999); // 17%
final plus = _tier(monthly: 1799, yearly: 16191); // 25%
expect(bestAnnualDiscountPercent([neo, plus]), 25);
expect(bestAnnualDiscountPercent([neo]), 17);
});
test('ignores tiers with unusable prices', () {
final broken = _tier(monthly: 1799);
final plus = _tier(monthly: 1799, yearly: 16191);
expect(bestAnnualDiscountPercent([broken, plus]), 25);
});
test('returns null when no tier has a usable discount', () {
expect(bestAnnualDiscountPercent([_tier(monthly: 1799), const []]), isNull);
expect(bestAnnualDiscountPercent(const []), isNull);
});
});
group('shouldShowPlanContinueButton', () {
test('hides when plans are loading, cancelled, or a change is already scheduled', () {
expect(
shouldShowPlanContinueButton(
isOnAnnualPlan: false,
hasScheduledUpgrade: false,
isCancelled: false,
plansLoaded: false,
),
isFalse,
);
expect(
shouldShowPlanContinueButton(
isOnAnnualPlan: false,
hasScheduledUpgrade: false,
isCancelled: true,
plansLoaded: true,
),
isFalse,
);
expect(
shouldShowPlanContinueButton(
isOnAnnualPlan: false,
hasScheduledUpgrade: true,
isCancelled: false,
plansLoaded: true,
),
isFalse,
);
});
test('shows for monthly users, including same-tier monthly→annual', () {
expect(
shouldShowPlanContinueButton(
isOnAnnualPlan: false,
hasScheduledUpgrade: false,
isCancelled: false,
plansLoaded: true,
selectedTierId: 'plus',
currentTierId: 'plus',
),
isTrue,
);
});
test('hides for annual users already on the selected tier', () {
expect(
shouldShowPlanContinueButton(
isOnAnnualPlan: true,
hasScheduledUpgrade: false,
isCancelled: false,
plansLoaded: true,
selectedTierId: 'plus',
currentTierId: 'plus',
),
isFalse,
);
expect(
shouldShowPlanContinueButton(
isOnAnnualPlan: true,
hasScheduledUpgrade: false,
isCancelled: false,
plansLoaded: true,
),
isFalse,
);
});
test('shows for annual Plus selecting Unlimited — do not restore !isOnAnnualPlan', () {
expect(
shouldShowPlanContinueButton(
isOnAnnualPlan: true,
hasScheduledUpgrade: false,
isCancelled: false,
plansLoaded: true,
selectedTierId: 'unlimited_v2',
currentTierId: 'plus',
),
isTrue,
);
});
test('hides desktop-plan Continue onto a mobile tier (manage-only)', () {
expect(
shouldShowPlanContinueButton(
isOnAnnualPlan: false,
hasScheduledUpgrade: false,
isCancelled: false,
plansLoaded: true,
selectedTierId: 'plus',
currentTierId: 'architect',
currentGrantsDesktop: true,
),
isFalse,
);
});
test('still shows monthly→annual Continue on a desktop plan', () {
expect(
shouldShowPlanContinueButton(
isOnAnnualPlan: false,
hasScheduledUpgrade: false,
isCancelled: false,
plansLoaded: true,
selectedTierId: 'architect',
currentTierId: 'architect',
currentGrantsDesktop: true,
),
isTrue,
);
});
test('hides same-tier annual Continue on a desktop plan', () {
expect(
shouldShowPlanContinueButton(
isOnAnnualPlan: true,
hasScheduledUpgrade: false,
isCancelled: false,
plansLoaded: true,
selectedTierId: 'architect',
currentTierId: 'architect',
currentGrantsDesktop: true,
),
isFalse,
);
});
});
}