-
Notifications
You must be signed in to change notification settings - Fork 571
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support New displayOnly Confg Option (#2252)
* add new vaultable logic to eligible funding * add displayOnly to button props * remove unneeded prop * fix lint * refactor. thanks shane * add some basic unit tests for funding eligibility * clean up mock funding options * change const name & update constants * fix lint * make flow types, lint, and logic work together * add new test * update sdk-constants version --------- Co-authored-by: Spencer Sablan <[email protected]>
- Loading branch information
1 parent
3a76edc
commit bcd4e50
Showing
6 changed files
with
211 additions
and
3 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,140 @@ | ||
/* @flow */ | ||
import { COMPONENTS, FUNDING } from "@paypal/sdk-constants/src"; | ||
import { describe, expect } from "vitest"; | ||
|
||
import { BUTTON_FLOW } from "../constants"; | ||
|
||
import { isFundingEligible } from "./funding"; | ||
|
||
const defaultMockFundingOptions = { | ||
platform: "desktop", | ||
components: [COMPONENTS.BUTTONS], | ||
flow: BUTTON_FLOW.PURCHASE, | ||
fundingSource: FUNDING.SEPA, | ||
fundingEligibility: { | ||
paylater: { | ||
eligible: true, | ||
vaultable: false, | ||
}, | ||
venmo: { | ||
eligible: true, | ||
vaultable: true, | ||
branded: false, | ||
}, | ||
sepa: { | ||
eligible: false, | ||
branded: false, | ||
}, | ||
oxxo: { | ||
eligible: false, | ||
vaultable: true, | ||
branded: false, | ||
}, | ||
card: { | ||
eligible: true, | ||
branded: false, | ||
vendors: { | ||
visa: { | ||
eligible: true, | ||
vaultable: false, | ||
}, | ||
mastercard: { | ||
eligible: true, | ||
vaultable: false, | ||
}, | ||
amex: { | ||
eligible: true, | ||
vaultable: false, | ||
}, | ||
}, | ||
}, | ||
}, | ||
applePaySupport: false, | ||
supportsPopups: true, | ||
supportedNativeBrowser: true, | ||
onShippingChange: null, | ||
onShippingAddressChange: null, | ||
onShippingOptionsChange: null, | ||
}; | ||
|
||
describe("Funding eligibility", () => { | ||
test("should not be eligible if funding source is missing from fundingEligibility", () => { | ||
const fundingEligible = isFundingEligible( | ||
FUNDING.WECHATPAY, | ||
defaultMockFundingOptions | ||
); | ||
|
||
expect(fundingEligible).toBe(false); | ||
}); | ||
|
||
test("should not be eligible if displayOnly includes 'vaultable' and vaultable is false", () => { | ||
const options = { | ||
...defaultMockFundingOptions, | ||
displayOnly: ["vaultable"], | ||
fundingSource: FUNDING.PAYLATER, | ||
}; | ||
const fundingEligible = isFundingEligible(FUNDING.PAYLATER, options); | ||
|
||
expect(fundingEligible).toBe(false); | ||
}); | ||
|
||
test("card should not be eligible if displayOnly includes 'vaultable' and no vendors are vaultable", () => { | ||
const options = { | ||
...defaultMockFundingOptions, | ||
displayOnly: ["vaultable"], | ||
components: [COMPONENTS.BUTTONS], | ||
fundingSource: FUNDING.CARD, | ||
}; | ||
const fundingEligible = isFundingEligible(FUNDING.CARD, options); | ||
|
||
expect(fundingEligible).toBe(false); | ||
}); | ||
|
||
test("card should be eligible if displayOnly includes 'vaultable' and any vendor is vaultable", () => { | ||
const options = { | ||
...defaultMockFundingOptions, | ||
displayOnly: ["vaultable"], | ||
fundingSource: FUNDING.CARD, | ||
components: [COMPONENTS.BUTTONS], | ||
platform: "desktop", | ||
fundingEligibility: { | ||
card: { | ||
eligible: true, | ||
branded: false, | ||
vendors: { | ||
visa: { | ||
eligible: true, | ||
vaultable: true, | ||
}, | ||
mastercard: { | ||
eligible: true, | ||
vaultable: false, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
const fundingEligible = isFundingEligible(FUNDING.CARD, options); | ||
|
||
expect(fundingEligible).toBe(true); | ||
}); | ||
|
||
test("should not be eligible if fundingSource.eligible is false", () => { | ||
const fundingEligible = isFundingEligible( | ||
FUNDING.SEPA, | ||
defaultMockFundingOptions | ||
); | ||
|
||
expect(fundingEligible).toBe(false); | ||
}); | ||
|
||
test("should not be eligible if fundingSource.eligible is false and fundingSource.vaultable is true", () => { | ||
const fundingEligible = isFundingEligible( | ||
FUNDING.OXXO, | ||
defaultMockFundingOptions | ||
); | ||
|
||
expect(fundingEligible).toBe(false); | ||
}); | ||
}); |
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