From 37358d050fc3f8803e2f58852c1d325e7ebd9ccf Mon Sep 17 00:00:00 2001 From: Liz Martinez <40329316+elizabethmv@users.noreply.github.com> Date: Thu, 12 Oct 2023 14:32:27 -0500 Subject: [PATCH] Include branded in HCF eligibility check --- src/zoid/card-fields/component.jsx | 5 +- .../tests/card-fields/eligibility.js | 55 +++++++++++++++++++ test/integration/tests/card-fields/index.js | 3 + test/integration/tests/index.js | 1 + test/paypal.js | 5 ++ 5 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 test/integration/tests/card-fields/eligibility.js create mode 100644 test/integration/tests/card-fields/index.js diff --git a/src/zoid/card-fields/component.jsx b/src/zoid/card-fields/component.jsx index 54c7062edd..1793a8c541 100644 --- a/src/zoid/card-fields/component.jsx +++ b/src/zoid/card-fields/component.jsx @@ -475,7 +475,10 @@ export const getCardFieldsComponent: () => CardFieldsComponent = memoize( eligible: () => { const fundingEligibility = getRefinedFundingEligibility(); - if (fundingEligibility?.card?.eligible) { + if ( + fundingEligibility?.card?.eligible && + !fundingEligibility.card.branded + ) { return { eligible: true, }; diff --git a/test/integration/tests/card-fields/eligibility.js b/test/integration/tests/card-fields/eligibility.js new file mode 100644 index 0000000000..c1fef92d8c --- /dev/null +++ b/test/integration/tests/card-fields/eligibility.js @@ -0,0 +1,55 @@ +/* @flow */ + +import { FUNDING } from "@paypal/sdk-constants/src"; + +import { + createTestContainer, + destroyTestContainer, + mockProp, + assert, +} from "../common"; + +describe.only(`paypal card fields component`, () => { + beforeEach(() => { + createTestContainer(); + }); + + afterEach(() => { + destroyTestContainer(); + }); + + it(`should not be eligible or render when branded is true`, (done) => { + const fundingSource = FUNDING.CARD; + mockProp(window.__TEST_FUNDING_ELIGIBILITY__, fundingSource, { + eligible: true, + branded: true, + }); + + const cardButton = window.paypal.Buttons({ + fundingSource, + }); + + const cardFields = window.paypal.CardFields({}); + + assert.equal(cardFields.isEligible(), false); + done(); + }); + + it(`should be eligible when branded is false`, (done) => { + const fundingSource = FUNDING.CARD; + mockProp(window.__TEST_FUNDING_ELIGIBILITY__, fundingSource, { + eligible: true, + branded: false, + }); + window.__COMPONENTS__ = ["buttons", "card-fields"]; + + const cardButton = window.paypal.Buttons({ + fundingSource, + }); + + const cardFields = window.paypal.CardFields({}); + + assert.equal(cardFields.isEligible(), true); + done(); + }); +}); diff --git a/test/integration/tests/card-fields/index.js b/test/integration/tests/card-fields/index.js new file mode 100644 index 0000000000..5a69e0fb53 --- /dev/null +++ b/test/integration/tests/card-fields/index.js @@ -0,0 +1,3 @@ +/* @flow */ + +import "./eligibility"; diff --git a/test/integration/tests/index.js b/test/integration/tests/index.js index 84dbe0bf47..2c1414d660 100644 --- a/test/integration/tests/index.js +++ b/test/integration/tests/index.js @@ -10,3 +10,4 @@ import "./security"; import "./funding/paylater"; import "./funding/applepay"; import "./funding/venmo"; +import "./card-fields"; diff --git a/test/paypal.js b/test/paypal.js index 35ec0c9118..5ce98dd47e 100644 --- a/test/paypal.js +++ b/test/paypal.js @@ -7,6 +7,7 @@ import * as paypalWallet from "../src/interface/wallet"; // eslint-disable-line import * as paypalMarks from "../src/interface/marks"; // eslint-disable-line import/no-namespace import * as paypalFields from "../src/interface/fields"; // eslint-disable-line import/no-namespace import * as paypalPaymentFields from "../src/interface/payment-fields"; // eslint-disable-line import/no-namespace +import * as paypalCardFields from "../src/interface/card-fields"; // eslint-disable-line import/no-namespace // the enable-funding=venmo flag is temporarily needed for the venmo experiment // the enable-funding=applepay flag is needed for applepay vertical stack and standalone buttons to render @@ -34,4 +35,8 @@ setupSDK([ name: "paypal-fields", requirer: () => ({ ...paypalFields, ...paypalPaymentFields }), }, + { + name: "paypal-card-fields", + requirer: () => paypalCardFields, + }, ]);