forked from freeCodeCamp/freeCodeCamp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(client): avoid calling the api for signed out users (freeCodeCamp…
…#42383) * feat(client): call api for singed in paypal subs * feat(client): update tests * feat(client): add kebab case * fix: clarify tests
- Loading branch information
Showing
3 changed files
with
69 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { render } from '@testing-library/react'; | ||
import React from 'react'; | ||
|
||
import { PaypalButton } from './PaypalButton'; | ||
|
||
const commonProps = { | ||
donationAmount: 500, | ||
donationDuration: 'month', | ||
handleProcessing: () => null, | ||
isDonating: false, | ||
onDonationStateChange: () => null, | ||
isPaypalLoading: true, | ||
t: jest.fn(), | ||
theme: 'night', | ||
handlePaymentButtonLoad: jest.fn() | ||
}; | ||
|
||
const donationData = { | ||
redirecting: false, | ||
processing: false, | ||
success: false, | ||
error: null | ||
}; | ||
|
||
jest.mock('../../analytics'); | ||
|
||
describe('<Paypal Button/>', () => { | ||
it('does not call addDonate api on payment approval when user is not signed ', () => { | ||
const ref = React.createRef<PaypalButton>(); | ||
const isSubscription = true; | ||
const addDonation = jest.fn(); | ||
render( | ||
<PaypalButton | ||
{...commonProps} | ||
addDonation={addDonation} | ||
isSignedIn={false} | ||
ref={ref} | ||
/> | ||
); | ||
|
||
ref.current?.handleApproval(donationData, isSubscription); | ||
expect(addDonation).toBeCalledTimes(0); | ||
}); | ||
it('calls addDonate api on payment approval when user is signed in', () => { | ||
const ref = React.createRef<PaypalButton>(); | ||
const isSubscription = true; | ||
const addDonation = jest.fn(); | ||
render( | ||
<PaypalButton | ||
{...commonProps} | ||
addDonation={addDonation} | ||
isSignedIn={true} | ||
ref={ref} | ||
/> | ||
); | ||
|
||
ref.current?.handleApproval(donationData, isSubscription); | ||
expect(addDonation).toBeCalledTimes(1); | ||
}); | ||
}); |