@@ -125,18 +125,57 @@ test('Shows a loading spinner when uninitialized credit count', async () => {
125
125
await expect ( queryByTestId ( 'spinner' ) ) . toBeVisible ( )
126
126
} )
127
127
128
- test ( 'Shows the total credits for Unknown subscription' , async ( ) => {
129
- const data = {
130
- balance : {
131
- monthlyApiCreditsRemaining : 10 ,
132
- stableApiCreditsRemaining : 25 ,
133
- } ,
134
- subscriptions : {
135
- monthlyPayAsYouGoApiCreditsTotal : 20 ,
136
- name : "unknown" ,
137
- }
128
+ const unKnownTierData = {
129
+ balance : {
130
+ monthlyApiCreditsRemaining : 10 ,
131
+ stableApiCreditsRemaining : 25 ,
132
+ } ,
133
+ subscriptions : {
134
+ monthlyPayAsYouGoApiCreditsTotal : 20 ,
135
+ name : "unknown" ,
136
+ }
137
+ }
138
+
139
+ const freeTierData = {
140
+ balance : {
141
+ monthlyApiCreditsRemaining : 10 ,
142
+ stableApiCreditsRemaining : 0 ,
143
+ } ,
144
+ subscriptions : {
145
+ monthlyPayAsYouGoApiCreditsTotal : 20 ,
146
+ name : "free" ,
147
+ }
148
+ }
149
+
150
+ const proTierData = {
151
+ // These are all ignored
152
+ balance : {
153
+ monthlyApiCreditsRemaining : 10 ,
154
+ stableApiCreditsRemaining : 0 ,
155
+ } ,
156
+ subscriptions : {
157
+ // This should be ignored because it's Pro tier.
158
+ monthlyPayAsYouGoApiCreditsTotal : 20 ,
159
+ name : "pro" ,
138
160
}
161
+ }
139
162
163
+ const enterpriseTierData = {
164
+ // These are all ignored, user is part of an org.
165
+ balance : {
166
+ monthlyApiCreditsRemaining : 10 ,
167
+ stableApiCreditsRemaining : 0 ,
168
+ } ,
169
+ subscriptions : {
170
+ // This should be ignored because it's Pro tier.
171
+ monthlyPayAsYouGoApiCreditsTotal : 20 ,
172
+ // This should be ignored because the user is part of an Org.
173
+ name : "free" ,
174
+ }
175
+ }
176
+
177
+ test ( 'Shows the total credits for Unknown subscription' , async ( ) => {
178
+ const data = unKnownTierData
140
179
server . use (
141
180
http . get ( '*/user/payment/balance' , ( req , res , ctx ) => {
142
181
return HttpResponse . json ( createUserPaymentBalanceResponse ( data . balance ) )
@@ -166,17 +205,7 @@ test('Shows the total credits for Unknown subscription', async () => {
166
205
} )
167
206
168
207
test ( 'Progress bar reflects ratio left of Free subscription' , async ( ) => {
169
- const data = {
170
- balance : {
171
- monthlyApiCreditsRemaining : 10 ,
172
- stableApiCreditsRemaining : 0 ,
173
- } ,
174
- subscriptions : {
175
- monthlyPayAsYouGoApiCreditsTotal : 20 ,
176
- name : "free" ,
177
- }
178
- }
179
-
208
+ const data = freeTierData
180
209
server . use (
181
210
http . get ( '*/user/payment/balance' , ( req , res , ctx ) => {
182
211
return HttpResponse . json ( createUserPaymentBalanceResponse ( data . balance ) )
@@ -212,19 +241,7 @@ test('Progress bar reflects ratio left of Free subscription', async () => {
212
241
} )
213
242
} )
214
243
test ( 'Shows infinite credits for Pro subscription' , async ( ) => {
215
- const data = {
216
- // These are all ignored
217
- balance : {
218
- monthlyApiCreditsRemaining : 10 ,
219
- stableApiCreditsRemaining : 0 ,
220
- } ,
221
- subscriptions : {
222
- // This should be ignored because it's Pro tier.
223
- monthlyPayAsYouGoApiCreditsTotal : 20 ,
224
- name : "pro" ,
225
- }
226
- }
227
-
244
+ const data = proTierData
228
245
server . use (
229
246
http . get ( '*/user/payment/balance' , ( req , res , ctx ) => {
230
247
return HttpResponse . json ( createUserPaymentBalanceResponse ( data . balance ) )
@@ -255,19 +272,7 @@ test('Shows infinite credits for Pro subscription', async () => {
255
272
await expect ( queryByTestId ( 'billing-remaining-progress-bar-inline' ) ) . toBe ( null )
256
273
} )
257
274
test ( 'Shows infinite credits for Enterprise subscription' , async ( ) => {
258
- const data = {
259
- // These are all ignored, user is part of an org.
260
- balance : {
261
- monthlyApiCreditsRemaining : 10 ,
262
- stableApiCreditsRemaining : 0 ,
263
- } ,
264
- subscriptions : {
265
- // This should be ignored because it's Pro tier.
266
- monthlyPayAsYouGoApiCreditsTotal : 20 ,
267
- // This should be ignored because the user is part of an Org.
268
- name : "free" ,
269
- }
270
- }
275
+ const data = enterpriseTierData
271
276
272
277
server . use (
273
278
http . get ( '*/user/payment/balance' , ( req , res , ctx ) => {
@@ -297,3 +302,58 @@ test('Shows infinite credits for Enterprise subscription', async () => {
297
302
await expect ( queryByTestId ( 'infinity' ) ) . toBeVisible ( )
298
303
await expect ( queryByTestId ( 'billing-remaining-progress-bar-inline' ) ) . toBe ( null )
299
304
} )
305
+
306
+ test ( 'Show upgrade button if credits are not infinite' , async ( ) => {
307
+ const data = freeTierData
308
+ server . use (
309
+ http . get ( '*/user/payment/balance' , ( req , res , ctx ) => {
310
+ return HttpResponse . json ( createUserPaymentBalanceResponse ( data . balance ) )
311
+ } ) ,
312
+ http . get ( '*/user/payment/subscriptions' , ( req , res , ctx ) => {
313
+ return HttpResponse . json ( createUserPaymentSubscriptionsResponse ( data . subscriptions ) )
314
+ } ) ,
315
+ http . get ( '*/org' , ( req , res , ctx ) => {
316
+ return new HttpResponse ( 403 )
317
+ } ) ,
318
+ )
319
+
320
+ const billingActor = createActor ( billingMachine , { input : BILLING_CONTEXT_DEFAULTS } ) . start ( )
321
+
322
+ const { queryByTestId } = render ( < BillingDialog
323
+ billingActor = { billingActor }
324
+ /> )
325
+
326
+ await act ( ( ) => {
327
+ billingActor . send ( { type : BillingTransition . Update , apiToken : "it doesn't matter wtf this is :)" } )
328
+ } )
329
+
330
+ await expect ( queryByTestId ( 'billing-upgrade-button' ) ) . toBeVisible ( )
331
+ } )
332
+
333
+ test ( 'Hide upgrade button if credits are infinite' , async ( ) => {
334
+ const data = enterpriseTierData
335
+ server . use (
336
+ http . get ( '*/user/payment/balance' , ( req , res , ctx ) => {
337
+ return HttpResponse . json ( createUserPaymentBalanceResponse ( data . balance ) )
338
+ } ) ,
339
+ http . get ( '*/user/payment/subscriptions' , ( req , res , ctx ) => {
340
+ return HttpResponse . json ( createUserPaymentSubscriptionsResponse ( data . subscriptions ) )
341
+ } ) ,
342
+ // Ok finally the first use of an org lol
343
+ http . get ( '*/org' , ( req , res , ctx ) => {
344
+ return HttpResponse . json ( createOrgResponse ( ) )
345
+ } ) ,
346
+ )
347
+
348
+ const billingActor = createActor ( billingMachine , { input : BILLING_CONTEXT_DEFAULTS } ) . start ( )
349
+
350
+ const { queryByTestId } = render ( < BillingDialog
351
+ billingActor = { billingActor }
352
+ /> )
353
+
354
+ await act ( ( ) => {
355
+ billingActor . send ( { type : BillingTransition . Update , apiToken : "it doesn't matter wtf this is :)" } )
356
+ } )
357
+
358
+ await expect ( queryByTestId ( 'billing-upgrade-button' ) ) . toBe ( null )
359
+ } )
0 commit comments