Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Infer name if not in billing details #3676

Merged
merged 5 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function BillingDetails() {
<EmailAddress />
<PaymentCard
// @ts-expect-error - TODO fix this once we update PaymentCard to TS
subscriptionDetail={subscriptionDetail}
accountDetails={accountDetails}
provider={provider}
owner={owner}
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import PropTypes from 'prop-types'
import { useState } from 'react'

import { subscriptionDetailType } from 'services/account'
import { accountDetailsPropType } from 'services/account'
import { formatTimestampToCalendarDate } from 'shared/utils/billing'
import A from 'ui/A'
import Button from 'ui/Button'
Expand All @@ -10,8 +10,9 @@ import Icon from 'ui/Icon'
import BankInformation from './BankInformation'
import CardInformation from './CardInformation'
import PaymentMethodForm from './PaymentMethodForm'
function PaymentCard({ subscriptionDetail, provider, owner }) {
function PaymentCard({ accountDetails, provider, owner }) {
const [isFormOpen, setIsFormOpen] = useState(false)
const subscriptionDetail = accountDetails?.subscriptionDetail
const card = subscriptionDetail?.defaultPaymentMethod?.card
const usBankAccount = subscriptionDetail?.defaultPaymentMethod?.usBankAccount

Expand Down Expand Up @@ -41,7 +42,7 @@ function PaymentCard({ subscriptionDetail, provider, owner }) {
provider={provider}
owner={owner}
closeForm={() => setIsFormOpen(false)}
subscriptionDetail={subscriptionDetail}
accountDetails={accountDetails}
/>
) : card ? (
<CardInformation card={card} subscriptionDetail={subscriptionDetail} />
Expand Down Expand Up @@ -72,7 +73,7 @@ function PaymentCard({ subscriptionDetail, provider, owner }) {
}

PaymentCard.propTypes = {
subscriptionDetail: subscriptionDetailType,
accountDetails: accountDetailsPropType,
provider: PropTypes.string.isRequired,
owner: PropTypes.string.isRequired,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ const subscriptionDetail = {
cancelAtPeriodEnd: false,
}

const accountDetails = {
subscriptionDetail,
}

const usBankSubscriptionDetail = {
defaultPaymentMethod: {
usBankAccount: {
Expand Down Expand Up @@ -100,12 +104,12 @@ describe('PaymentCard', () => {
return { user }
}

describe(`when the user doesn't have any subscriptionDetail`, () => {
describe(`when the user doesn't have any accountDetails`, () => {
// NOTE: This test is misleading because we hide this component from a higher level in
suejung-sentry marked this conversation as resolved.
Show resolved Hide resolved
// BillingDetails.tsx if there is no subscriptionDetail
// BillingDetails.tsx if there is no accountDetails
it('renders the set payment method message', () => {
render(
<PaymentCard subscriptionDetail={null} provider="gh" owner="codecov" />
<PaymentCard accountDetails={null} provider="gh" owner="codecov" />
)

expect(
Expand All @@ -120,9 +124,12 @@ describe('PaymentCard', () => {
it('renders an error message', () => {
render(
<PaymentCard
subscriptionDetail={{
...subscriptionDetail,
defaultPaymentMethod: null,
accountDetails={{
...accountDetails,
subscriptionDetail: {
...accountDetails.subscriptionDetail,
defaultPaymentMethod: null,
},
}}
provider="gh"
owner="codecov"
Expand All @@ -142,9 +149,12 @@ describe('PaymentCard', () => {
const { user } = setup()
render(
<PaymentCard
subscriptionDetail={{
...subscriptionDetail,
defaultPaymentMethod: null,
accountDetails={{
...accountDetails,
subscriptionDetail: {
...accountDetails.subscriptionDetail,
defaultPaymentMethod: null,
},
}}
provider="gh"
owner="codecov"
Expand All @@ -165,9 +175,12 @@ describe('PaymentCard', () => {
const { user } = setup()
render(
<PaymentCard
subscriptionDetail={{
...subscriptionDetail,
defaultPaymentMethod: null,
accountDetails={{
...accountDetails,
subscriptionDetail: {
...accountDetails.subscriptionDetail,
defaultPaymentMethod: null,
},
}}
provider="gh"
owner="codecov"
Expand All @@ -190,7 +203,7 @@ describe('PaymentCard', () => {
it('renders the card', () => {
render(
<PaymentCard
subscriptionDetail={subscriptionDetail}
accountDetails={accountDetails}
provider="gh"
owner="codecov"
/>,
Expand All @@ -204,7 +217,7 @@ describe('PaymentCard', () => {
it('renders the next billing', () => {
render(
<PaymentCard
subscriptionDetail={subscriptionDetail}
accountDetails={accountDetails}
provider="gh"
owner="codecov"
/>,
Expand All @@ -217,9 +230,15 @@ describe('PaymentCard', () => {

describe('when the user has a US bank account', () => {
it('renders the bank account details', () => {
const testAccountDetails = {
...accountDetails,
subscriptionDetail: {
...usBankSubscriptionDetail,
},
}
render(
<PaymentCard
subscriptionDetail={usBankSubscriptionDetail}
accountDetails={testAccountDetails}
provider="gh"
owner="codecov"
/>,
Expand All @@ -235,9 +254,12 @@ describe('PaymentCard', () => {
it(`doesn't render the next billing`, () => {
render(
<PaymentCard
subscriptionDetail={{
...subscriptionDetail,
cancelAtPeriodEnd: true,
accountDetails={{
...accountDetails,
subscriptionDetail: {
...accountDetails.subscriptionDetail,
cancelAtPeriodEnd: true,
},
}}
provider="gh"
owner="codecov"
Expand All @@ -260,7 +282,7 @@ describe('PaymentCard', () => {

render(
<PaymentCard
subscriptionDetail={subscriptionDetail}
accountDetails={accountDetails}
provider="gh"
owner="codecov"
/>,
Expand All @@ -280,7 +302,7 @@ describe('PaymentCard', () => {
})
render(
<PaymentCard
subscriptionDetail={subscriptionDetail}
accountDetails={accountDetails}
provider="gh"
owner="codecov"
/>,
Expand All @@ -305,7 +327,7 @@ describe('PaymentCard', () => {

render(
<PaymentCard
subscriptionDetail={subscriptionDetail}
accountDetails={accountDetails}
provider="gh"
owner="codecov"
/>,
Expand All @@ -327,7 +349,7 @@ describe('PaymentCard', () => {
})
render(
<PaymentCard
subscriptionDetail={subscriptionDetail}
accountDetails={accountDetails}
provider="gh"
owner="codecov"
/>,
Expand All @@ -354,7 +376,7 @@ describe('PaymentCard', () => {
})
render(
<PaymentCard
subscriptionDetail={subscriptionDetail}
accountDetails={accountDetails}
provider="gh"
owner="codecov"
/>,
Expand All @@ -376,7 +398,7 @@ describe('PaymentCard', () => {
})
render(
<PaymentCard
subscriptionDetail={subscriptionDetail}
accountDetails={accountDetails}
provider="gh"
owner="codecov"
/>,
Expand Down
Loading
Loading