Skip to content

Commit 128f966

Browse files
committed
add billing e2e tests
1 parent c08b5e8 commit 128f966

File tree

9 files changed

+304
-3
lines changed

9 files changed

+304
-3
lines changed
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/// <reference types='cypress' />
2+
3+
describe('Billing', () => {
4+
function stubBillingCalls() {
5+
cy.intercept('GET', 'http://talo.api/billing/organisation-plan', {
6+
statusCode: 200,
7+
fixture: 'responses/billing/free-plan'
8+
})
9+
10+
cy.intercept('GET', 'http://talo.api/billing/plans', {
11+
statusCode: 200,
12+
fixture: 'responses/billing/plans'
13+
})
14+
15+
cy.intercept('GET', 'http://talo.api/billing/usage', {
16+
statusCode: 200,
17+
fixture: 'responses/billing/usage'
18+
})
19+
}
20+
21+
it('should show the correct usages', () => {
22+
stubBillingCalls()
23+
24+
cy.login('owner', '/billing')
25+
cy.findByTestId('User seats-usage').should('contain.text', '0/2')
26+
cy.findByTestId('Data exports-usage').should('contain.text', '1/3')
27+
})
28+
29+
it('should open the billing portal', () => {
30+
stubBillingCalls()
31+
32+
cy.intercept('POST', 'http://talo.api/billing/portal-session', {
33+
statusCode: 200,
34+
body: {
35+
redirect: 'https://trytalo.com'
36+
}
37+
}).as('portalSession')
38+
39+
cy.login('owner', '/billing')
40+
cy.findByText('Billing Portal').click()
41+
42+
cy.wait('@portalSession').then(() => {
43+
cy.on('url:changed', (newUrl) => {
44+
expect(newUrl).to.eq('https://trytalo.com')
45+
})
46+
})
47+
})
48+
49+
it('should open the checkout portal', () => {
50+
stubBillingCalls()
51+
52+
cy.intercept('POST', 'http://talo.api/billing/checkout-session', {
53+
statusCode: 200,
54+
body: {
55+
redirect: 'https://trytalo.com'
56+
}
57+
}).as('checkoutSession')
58+
59+
cy.login('owner', '/billing')
60+
cy.findAllByText('Upgrade').spread((button) => button.click())
61+
62+
cy.wait('@checkoutSession').then(() => {
63+
cy.on('url:changed', (newUrl) => {
64+
expect(newUrl).to.eq('https://trytalo.com')
65+
})
66+
})
67+
})
68+
69+
it('should show the confirm plan change modal', () => {
70+
stubBillingCalls()
71+
72+
cy.intercept('POST', 'http://talo.api/billing/checkout-session', {
73+
statusCode: 200,
74+
fixture: 'responses/billing/invoice'
75+
})
76+
77+
cy.intercept('POST', 'http://talo.api/billing/confirm-plan', {
78+
statusCode: 204
79+
})
80+
81+
cy.login('owner', '/billing')
82+
cy.findAllByText('Upgrade').spread((button) => button.click())
83+
84+
cy.findByText('This is a preview of the invoice that will be billed on 12 Aug 2022:').should('exist')
85+
cy.findByText('12 Jun 2022 - 12 Jul 2022').should('exist')
86+
cy.findByText('Team plan usage').should('exist')
87+
cy.findByText('Team plan proration').should('exist')
88+
cy.findByText('13 Jul 2022 - 12 Aug 2022').should('exist')
89+
cy.findByText('Business plan usage').should('exist')
90+
91+
cy.findByTestId('confirm-plan-change').click()
92+
cy.findByText('Confirm plan change').should('not.exist')
93+
cy.findByText('Current plan').should('exist')
94+
})
95+
})
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"accessToken": "ey...",
3+
"user": {
4+
"id": 1,
5+
"type": 0,
6+
"username": "Owner",
7+
"organisation": {
8+
"games": [
9+
{
10+
"id": 1,
11+
"name": "Superstatic",
12+
"props": [],
13+
"playerCount": 0,
14+
"createdAt": "2023-01-01 00:00:00"
15+
}
16+
],
17+
"pricingPlan": {
18+
"status": "active"
19+
}
20+
}
21+
}
22+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"pricingPlan": {
3+
"pricingPlan": {
4+
"id": 1,
5+
"hidden": false,
6+
"default": true,
7+
"actions": []
8+
},
9+
"status": "active",
10+
"endDate": null,
11+
"canViewBillingPortal": true
12+
}
13+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"invoice": {
3+
"lines": [
4+
{
5+
"id": 1,
6+
"period": {
7+
"start": 1655024400,
8+
"end": 1657616400
9+
},
10+
"description": "Team plan usage",
11+
"amount": 5000
12+
},
13+
{
14+
"id": 2,
15+
"period": {
16+
"start": 1655024400,
17+
"end": 1657666799
18+
},
19+
"description": "Team plan proration",
20+
"amount": -300
21+
},
22+
{
23+
"id": 3,
24+
"period": {
25+
"start": 1657670400,
26+
"end": 1660345199
27+
},
28+
"description": "Business plan usage",
29+
"amount": 8000
30+
}
31+
],
32+
"total": 13300,
33+
"prorationDate": 1655024400,
34+
"collectionDate": 1660345199
35+
}
36+
}
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
{
2+
"pricingPlans": [
3+
{
4+
"id": 1,
5+
"stripeId": "prod_LsNS1zRKy9PNkn",
6+
"hidden": false,
7+
"default": true,
8+
"createdAt": "2022-06-14T17:13:12.000Z",
9+
"updatedAt": "2022-06-14T17:13:12.000Z",
10+
"actions": [
11+
{
12+
"id": 1,
13+
"type": 0,
14+
"limit": 2,
15+
"trackedMonthly": false
16+
},
17+
{
18+
"id": 2,
19+
"type": 1,
20+
"limit": 2,
21+
"trackedMonthly": true
22+
}
23+
],
24+
"name": "Indie Plan",
25+
"prices": [
26+
{
27+
"amount": 0,
28+
"currency": "usd",
29+
"interval": "month",
30+
"current": true
31+
},
32+
{
33+
"amount": 0,
34+
"currency": "usd",
35+
"interval": "year",
36+
"current": false
37+
}
38+
]
39+
},
40+
{
41+
"id": 2,
42+
"stripeId": "prod_LsNTl1tTzZa1LI",
43+
"hidden": false,
44+
"default": false,
45+
"createdAt": "2022-06-14T17:13:34.000Z",
46+
"updatedAt": "2022-06-14T17:13:34.000Z",
47+
"actions": [
48+
{
49+
"id": 3,
50+
"type": 0,
51+
"limit": 10,
52+
"trackedMonthly": false
53+
},
54+
{
55+
"id": 4,
56+
"type": 1,
57+
"limit": 4,
58+
"trackedMonthly": true
59+
}
60+
],
61+
"name": "Team Plan",
62+
"prices": [
63+
{
64+
"amount": 599,
65+
"currency": "usd",
66+
"interval": "month",
67+
"current": false
68+
},
69+
{
70+
"amount": 6399,
71+
"currency": "usd",
72+
"interval": "year",
73+
"current": false
74+
}
75+
]
76+
},
77+
{
78+
"id": 3,
79+
"stripeId": "prod_LsNTee1kaFQNSU",
80+
"hidden": false,
81+
"default": false,
82+
"createdAt": "2022-06-14T17:13:55.000Z",
83+
"updatedAt": "2022-06-14T17:13:55.000Z",
84+
"actions": [
85+
{
86+
"id": 5,
87+
"type": 0,
88+
"limit": 50,
89+
"trackedMonthly": false
90+
},
91+
{
92+
"id": 6,
93+
"type": 1,
94+
"limit": 10,
95+
"trackedMonthly": true
96+
}
97+
],
98+
"name": "Business Plan",
99+
"prices": [
100+
{
101+
"amount": 1999,
102+
"currency": "usd",
103+
"interval": "month",
104+
"current": false
105+
},
106+
{
107+
"amount": 21499,
108+
"currency": "usd",
109+
"interval": "year",
110+
"current": false
111+
}
112+
]
113+
}
114+
]
115+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"usage": {
3+
"0": {
4+
"limit": 2,
5+
"used": 0
6+
},
7+
"1": {
8+
"limit": 3,
9+
"used": 1
10+
}
11+
}
12+
}

cypress/support/commands.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ Cypress.Commands.add('visitAsGuest', (url = '/') => {
2424
cy.visit(url)
2525
})
2626

27-
Cypress.Commands.add('login', (userType = 'dev') => {
27+
Cypress.Commands.add('login', (userType = 'dev', url = '/') => {
2828
cy.intercept('GET', 'http://talo.api/public/users/refresh', {
2929
statusCode: 200,
3030
fixture: `responses/auth/${userType}`
3131
})
3232

3333
cy.stubDashboardCalls()
3434

35-
cy.visit('/')
35+
cy.visit(url)
3636
})

src/components/billing/BillingUsageTile.jsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@ export default function BillingUsageTile({ usage, usageError }) {
2020
return (
2121
<li key={idx} className='flex items-center'>
2222
<p className='w-40'>{name}</p>
23-
<p className={classNames('w-20 font-semibold font-mono text-right', { 'text-orange-400': used >= limit })}>{used}/{limit}</p>
23+
<p
24+
data-testid={name + '-usage'}
25+
className={classNames('w-20 font-semibold font-mono text-right', { 'text-orange-400': used >= limit })}
26+
>
27+
{used}/{limit}
28+
</p>
2429

2530
<div className='h-3 w-full bg-gray-900 rounded-sm relative ml-4'>
2631
<div

src/modals/ConfirmPlanChange.jsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ export default function ConfirmPlanChange({ modalState, plan, pricingInterval, i
107107
variant='green'
108108
isLoading={isLoading}
109109
onClick={onConfirmClick}
110+
extra={{
111+
'data-testId': 'confirm-plan-change'
112+
}}
110113
>
111114
Confirm
112115
</Button>

0 commit comments

Comments
 (0)