Skip to content

Commit 0d33704

Browse files
fix tests
1 parent ea0b00d commit 0d33704

File tree

3 files changed

+38
-10
lines changed

3 files changed

+38
-10
lines changed

src/pages/PlanPage/subRoutes/CurrentOrgPlan/BillingDetails/PaymentCard/PaymentCard.test.jsx

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ vi.mock('services/account/useCreateStripeSetupIntent', async () => {
3535
})
3636

3737
afterEach(() => {
38+
queryClient.clear()
3839
vi.clearAllMocks()
3940
})
4041

@@ -54,6 +55,20 @@ const subscriptionDetail = {
5455
cancelAtPeriodEnd: false,
5556
}
5657

58+
const usBankSubscriptionDetail = {
59+
defaultPaymentMethod: {
60+
usBankAccount: {
61+
bankName: 'STRIPE TEST BANK',
62+
last4: '6789',
63+
},
64+
},
65+
plan: {
66+
value: Plans.USERS_PR_INAPPY,
67+
},
68+
currentPeriodEnd: 1606851492,
69+
cancelAtPeriodEnd: false,
70+
}
71+
5772
const wrapper = ({ children }) => (
5873
<QueryClientProvider client={queryClient}>
5974
<ThemeContextProvider>{children}</ThemeContextProvider>
@@ -200,6 +215,22 @@ describe('PaymentCard', () => {
200215
})
201216
})
202217

218+
describe('when the user has a US bank account', () => {
219+
it('renders the bank account details', () => {
220+
render(
221+
<PaymentCard
222+
subscriptionDetail={usBankSubscriptionDetail}
223+
provider="gh"
224+
owner="codecov"
225+
/>,
226+
{ wrapper }
227+
)
228+
229+
expect(screen.getByText(/STRIPE TEST BANK/)).toBeInTheDocument()
230+
expect(screen.getByText(/ 6789/)).toBeInTheDocument()
231+
})
232+
})
233+
203234
describe('when the subscription is set to expire', () => {
204235
it(`doesn't render the next billing`, () => {
205236
render(

src/pages/PlanPage/subRoutes/CurrentOrgPlan/BillingDetails/PaymentCard/PaymentMethodForm.test.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ describe('PaymentMethodForm', () => {
9797
/>,
9898
{ wrapper }
9999
)
100-
await user.click(screen.getByTestId('update-payment-method'))
100+
await user.click(screen.getByTestId('save-payment-method'))
101101

102102
expect(screen.queryByText(/Visa/)).not.toBeInTheDocument()
103103
})
@@ -118,7 +118,7 @@ describe('PaymentMethodForm', () => {
118118
/>,
119119
{ wrapper }
120120
)
121-
await user.click(screen.getByTestId('update-payment-method'))
121+
await user.click(screen.getByTestId('save-payment-method'))
122122

123123
expect(screen.getByRole('button', { name: /Save/i })).toBeInTheDocument()
124124
})
@@ -140,7 +140,7 @@ describe('PaymentMethodForm', () => {
140140
/>,
141141
{ wrapper }
142142
)
143-
await user.click(screen.getByTestId('update-payment-method'))
143+
await user.click(screen.getByTestId('save-payment-method'))
144144
expect(updatePaymentMethod).toHaveBeenCalled()
145145
})
146146
})
@@ -163,7 +163,7 @@ describe('PaymentMethodForm', () => {
163163
{ wrapper }
164164
)
165165

166-
await user.click(screen.getByTestId('update-payment-method'))
166+
await user.click(screen.getByTestId('save-payment-method'))
167167
await user.click(screen.getByRole('button', { name: /Cancel/ }))
168168

169169
expect(closeForm).toHaveBeenCalled()
@@ -189,7 +189,7 @@ describe('PaymentMethodForm', () => {
189189
{ wrapper }
190190
)
191191

192-
await user.click(screen.getByTestId('update-payment-method'))
192+
await user.click(screen.getByTestId('save-payment-method'))
193193

194194
expect(screen.getByText(randomError)).toBeInTheDocument()
195195
})

src/pages/PlanPage/subRoutes/CurrentOrgPlan/BillingDetails/PaymentCard/PaymentMethodForm.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { PaymentElement, useElements } from '@stripe/react-stripe-js'
22
import { StripePaymentElement } from '@stripe/stripe-js'
33
import cs from 'classnames'
4-
import { useState } from 'react'
54
import { z } from 'zod'
65

76
import { stripeAddress, SubscriptionDetailSchema } from 'services/account'
@@ -22,7 +21,6 @@ const PaymentMethodForm = ({
2221
owner,
2322
subscriptionDetail,
2423
}: PaymentMethodFormProps) => {
25-
const [errorState, setErrorState] = useState('')
2624
const elements = useElements()
2725

2826
const {
@@ -64,14 +62,13 @@ const PaymentMethodForm = ({
6462
})
6563
}
6664

67-
const showError = (error && !reset) || errorState
65+
const showError = error && !reset
6866

6967
return (
7068
<form onSubmit={submit} aria-label="form">
7169
<div className={cs('flex flex-col gap-3')}>
7270
<div className="mt-2 flex flex-col gap-2">
7371
<PaymentElement
74-
onChange={(e) => setErrorState(e?.value?.type || '')}
7572
options={{
7673
layout: 'tabs',
7774
fields: {
@@ -83,7 +80,7 @@ const PaymentMethodForm = ({
8380
}}
8481
/>
8582
<p className="mt-1 text-ds-primary-red">
86-
{showError && (error?.message || errorState)}
83+
{showError && error?.message}
8784
</p>
8885
<div className="mb-8 mt-4 flex gap-1">
8986
<Button

0 commit comments

Comments
 (0)