From 2295b81f93f5777021777d6d775ada225dbb9179 Mon Sep 17 00:00:00 2001 From: guilhermer Date: Wed, 20 Nov 2024 14:25:42 +0100 Subject: [PATCH] adding card ssn tests --- packages/e2e-playwright/fixtures/URL_MAP.ts | 6 +- .../mocks/binLookup/binLookup.data.ts | 18 +++++- packages/e2e-playwright/models/card-ssn.ts | 10 ++- .../card.socialSecurityNumber.spec.ts | 61 +++++++++++++++++++ .../autoMode/autoMode.clientScripts.js | 10 --- .../autoMode/autoMode.spec.ts | 50 --------------- .../showMode/showMode.clientScripts.js | 10 --- .../showMode/showMode.spec.ts | 60 ------------------ .../storybook/stories/cards/Card.stories.tsx | 13 ++++ 9 files changed, 105 insertions(+), 133 deletions(-) create mode 100644 packages/e2e-playwright/tests/e2e/card/socialSecurityNumber/card.socialSecurityNumber.spec.ts delete mode 100644 packages/e2e-playwright/tests/ui/card/socialSecurityNumber/autoMode/autoMode.clientScripts.js delete mode 100644 packages/e2e-playwright/tests/ui/card/socialSecurityNumber/autoMode/autoMode.spec.ts delete mode 100644 packages/e2e-playwright/tests/ui/card/socialSecurityNumber/showMode/showMode.clientScripts.js delete mode 100644 packages/e2e-playwright/tests/ui/card/socialSecurityNumber/showMode/showMode.spec.ts diff --git a/packages/e2e-playwright/fixtures/URL_MAP.ts b/packages/e2e-playwright/fixtures/URL_MAP.ts index 306e7ab0b..081d141ec 100644 --- a/packages/e2e-playwright/fixtures/URL_MAP.ts +++ b/packages/e2e-playwright/fixtures/URL_MAP.ts @@ -6,8 +6,12 @@ export const URL_MAP = { '/iframe.html?globals=&args=amount:0;sessionData.recurringProcessingModel:CardOnFile;sessionData.storePaymentMethodMode:askForConsent&id=dropin-default--auto&viewMode=story', dropinSessions_zeroAuthCard_fail: '/iframe.html?globals=&args=amount:0;sessionData.recurringProcessingModel:CardOnFile;sessionData.storePaymentMethodMode:askForConsent;sessionData.enableOneClick:!true&id=dropin-default--auto&viewMode=story', - /* Card */ + + /** + * Card + */ card: '/iframe.html?args=&id=cards-card--default&viewMode=story', + cardWithSsn: '/iframe.html?globals=&id=cards-card--with-ssn&viewMode=story', cardWithAvs: '/iframe.html?args=&globals=&id=cards-card--with-avs&viewMode=story', cardWithPartialAvs: '/iframe.html?args=&globals=&id=cards-card--with-partial-avs&viewMode=story', cardWithInstallments: '/iframe.html?args=&id=cards-card--with-installments&viewMode=story', diff --git a/packages/e2e-playwright/mocks/binLookup/binLookup.data.ts b/packages/e2e-playwright/mocks/binLookup/binLookup.data.ts index 806bc3d5f..f79b07f5e 100644 --- a/packages/e2e-playwright/mocks/binLookup/binLookup.data.ts +++ b/packages/e2e-playwright/mocks/binLookup/binLookup.data.ts @@ -116,6 +116,21 @@ const kcpMockOptionalDateAndCvcWithPanLengthMock = { issuingCountryCode: 'KR' }; +const socialSecurityNumberRequiredMock = { + brands: [ + { + brand: 'visa', + cvcPolicy: 'required', + enableLuhnCheck: true, + showExpiryDate: true, + supported: true, + showSocialSecurityNumber: true + } + ], + issuingCountryCode: 'BR', + requestId: null +}; + export { optionalDateAndCvcMock, hiddenDateAndCvcMock, @@ -124,5 +139,6 @@ export { optionalDateAndCvcWithPanLengthMock, multiLengthMaestroWithPanLengthMock, amexWithPanLengthMock, - kcpMockOptionalDateAndCvcWithPanLengthMock + kcpMockOptionalDateAndCvcWithPanLengthMock, + socialSecurityNumberRequiredMock }; diff --git a/packages/e2e-playwright/models/card-ssn.ts b/packages/e2e-playwright/models/card-ssn.ts index 6448f5ba1..39e75dbed 100644 --- a/packages/e2e-playwright/models/card-ssn.ts +++ b/packages/e2e-playwright/models/card-ssn.ts @@ -6,12 +6,20 @@ class CardWithSSN extends Card { constructor(page: Page) { super(page); - this.ssnField = this.rootElement.locator('.adyen-checkout__field--socialSecurityNumber'); // Holder + this.ssnField = this.rootElement.locator('.adyen-checkout__field--socialSecurityNumber'); } get ssnInput() { return this.ssnField.getByRole('textbox', { name: /CPF\/CNPJ/i }); } + + get ssnInputErrorElement() { + return this.ssnField.getByText('Enter a valid CPF/CNPJ number'); + } + + async typeSsn(ssn: string) { + await this.ssnInput.fill(ssn); + } } export { CardWithSSN }; diff --git a/packages/e2e-playwright/tests/e2e/card/socialSecurityNumber/card.socialSecurityNumber.spec.ts b/packages/e2e-playwright/tests/e2e/card/socialSecurityNumber/card.socialSecurityNumber.spec.ts new file mode 100644 index 000000000..dd55972f1 --- /dev/null +++ b/packages/e2e-playwright/tests/e2e/card/socialSecurityNumber/card.socialSecurityNumber.spec.ts @@ -0,0 +1,61 @@ +import { expect, test } from '../../../../fixtures/card.fixture'; +import { PAYMENT_RESULT, REGULAR_TEST_CARD, TEST_CPF_VALUE, TEST_CVC_VALUE, TEST_DATE_VALUE } from '../../../utils/constants'; +import { binLookupMock } from '../../../../mocks/binLookup/binLookup.mock'; +import { socialSecurityNumberRequiredMock } from '../../../../mocks/binLookup/binLookup.data'; +import { URL_MAP } from '../../../../fixtures/URL_MAP'; + +test.describe('Card payment with Social Security Number ', () => { + test.describe('with "socialSecurityNumberMode" set to "show"', () => { + test('should make a payment with a valid SSN', async ({ cardWithSSN }) => { + await cardWithSSN.goto(URL_MAP.cardWithSsn); + + await cardWithSSN.typeCardNumber(REGULAR_TEST_CARD); + await cardWithSSN.typeCvc(TEST_CVC_VALUE); + await cardWithSSN.typeExpiryDate(TEST_DATE_VALUE); + await cardWithSSN.typeSsn(TEST_CPF_VALUE); + await cardWithSSN.pay(); + + await expect(cardWithSSN.paymentResult).toContainText(PAYMENT_RESULT.authorised); + }); + + test('should display an error if SSN is not valid', async ({ cardWithSSN }) => { + await cardWithSSN.goto(URL_MAP.cardWithSsn); + + await cardWithSSN.typeCardNumber(REGULAR_TEST_CARD); + await cardWithSSN.typeCvc(TEST_CVC_VALUE); + await cardWithSSN.typeExpiryDate(TEST_DATE_VALUE); + await cardWithSSN.typeSsn('100200300'); + await cardWithSSN.pay(); + + await expect(cardWithSSN.ssnInputErrorElement).toBeVisible(); + }); + }); + + test.describe('with binLookup forcing the field to be shown ("auto" mode)', () => { + test('should display the SSN field once the card is entered', async ({ page, cardWithSSN }) => { + await binLookupMock(page, socialSecurityNumberRequiredMock); + await cardWithSSN.goto(URL_MAP.card); + + await expect(cardWithSSN.ssnInput).not.toBeVisible(); + + await cardWithSSN.typeCardNumber(REGULAR_TEST_CARD); + await cardWithSSN.typeCvc(TEST_CVC_VALUE); + await cardWithSSN.typeExpiryDate(TEST_DATE_VALUE); + + await expect(cardWithSSN.ssnInput).toBeVisible(); + }); + + test('should perform SSN validation if the field is displayed', async ({ page, cardWithSSN }) => { + await binLookupMock(page, socialSecurityNumberRequiredMock); + await cardWithSSN.goto(URL_MAP.card); + + await cardWithSSN.typeCardNumber(REGULAR_TEST_CARD); + await cardWithSSN.typeCvc(TEST_CVC_VALUE); + await cardWithSSN.typeExpiryDate(TEST_DATE_VALUE); + + await cardWithSSN.pay(); + + await expect(cardWithSSN.ssnInputErrorElement).toBeVisible(); + }); + }); +}); diff --git a/packages/e2e-playwright/tests/ui/card/socialSecurityNumber/autoMode/autoMode.clientScripts.js b/packages/e2e-playwright/tests/ui/card/socialSecurityNumber/autoMode/autoMode.clientScripts.js deleted file mode 100644 index 529744af3..000000000 --- a/packages/e2e-playwright/tests/ui/card/socialSecurityNumber/autoMode/autoMode.clientScripts.js +++ /dev/null @@ -1,10 +0,0 @@ -/** - * Set koreanAuthenticationRequired & countryCode so KCP fields show at start - */ -window.cardConfig = { - type: 'scheme', - brands: ['mc', 'visa', 'amex'], - configuration: { - // socialSecurityNumberMode: 'auto' // default value - } -}; diff --git a/packages/e2e-playwright/tests/ui/card/socialSecurityNumber/autoMode/autoMode.spec.ts b/packages/e2e-playwright/tests/ui/card/socialSecurityNumber/autoMode/autoMode.spec.ts deleted file mode 100644 index 89406b7c1..000000000 --- a/packages/e2e-playwright/tests/ui/card/socialSecurityNumber/autoMode/autoMode.spec.ts +++ /dev/null @@ -1,50 +0,0 @@ -import { test } from '@playwright/test'; -import { BIN_LOOKUP_VERSION, TEST_CPF_VALUE } from '../../../../utils/constants'; - -const getCardState = (what, prop) => globalThis.component.state[what][prop]; -const iframeSelector = '.card-field iframe'; - -const fillSSN = async (t, ssnValue = TEST_CPF_VALUE) => { - return t.switchToMainWindow().typeText('.adyen-checkout__field--socialSecurityNumber input', ssnValue, { speed: 0.5 }); -}; - -const requestURL = `https://checkoutshopper-test.adyen.com/checkoutshopper/${BIN_LOOKUP_VERSION}/bin/binLookup?token=${process.env.CLIENT_KEY}`; - -const mockedResponse = { - brands: [ - { - brand: 'visa', - cvcPolicy: 'required', - enableLuhnCheck: true, - showExpiryDate: true, - supported: true, - showSocialSecurityNumber: true - } - ], - issuingCountryCode: 'BR', - requestId: null -}; - -test.describe('Starting with SSN (auto) field', () => { - test.beforeEach(async () => { - // use mock: mockedResponse for requestURL - // await t.navigateTo(cardPage.pageUrl); - //use autoMode.clientScripts.js - }); - - test('Fill in card number with a socialSecurityNumber (CPF) field (socialSecurityMode: auto)', async () => { - // Start, allow time for iframes to load - // await start(t, 2000, TEST_SPEED); - // - // // Fill card field with non-korean card - // await cardUtils.fillCardNumber(t, REGULAR_TEST_CARD); - // - // // Complete form - // await cardUtils.fillDateAndCVC(t); - // - // await fillSSN(t); - // - // // Expect card to now be valid - // await t.expect(getIsValid()).eql(true); - }); -}); diff --git a/packages/e2e-playwright/tests/ui/card/socialSecurityNumber/showMode/showMode.clientScripts.js b/packages/e2e-playwright/tests/ui/card/socialSecurityNumber/showMode/showMode.clientScripts.js deleted file mode 100644 index 57f8509a1..000000000 --- a/packages/e2e-playwright/tests/ui/card/socialSecurityNumber/showMode/showMode.clientScripts.js +++ /dev/null @@ -1,10 +0,0 @@ -/** - * Set koreanAuthenticationRequired & countryCode so KCP fields show at start - */ -window.cardConfig = { - type: 'scheme', - brands: ['mc', 'visa', 'amex'], - configuration: { - socialSecurityNumberMode: 'show' - } -}; diff --git a/packages/e2e-playwright/tests/ui/card/socialSecurityNumber/showMode/showMode.spec.ts b/packages/e2e-playwright/tests/ui/card/socialSecurityNumber/showMode/showMode.spec.ts deleted file mode 100644 index d0ad6999a..000000000 --- a/packages/e2e-playwright/tests/ui/card/socialSecurityNumber/showMode/showMode.spec.ts +++ /dev/null @@ -1,60 +0,0 @@ -import { test } from '@playwright/test'; -import { TEST_CPF_VALUE } from '../../../../utils/constants'; - -const passwordHolder = '.card-field [data-cse="encryptedPassword"]'; - -const getCardState = (what, prop) => { - return globalThis.card.state[what][prop]; -}; - -const iframeSelector = '.card-field iframe'; - -const fillSSN = async (t, ssnValue = TEST_CPF_VALUE) => { - return t.switchToMainWindow().typeText('.adyen-checkout__field--socialSecurityNumber input', ssnValue, { speed: 0.5 }); -}; - -test.describe('Starting with SSN (show) field', () => { - test.beforeEach(async () => { - // use mock: mockedResponse for requestURL - // await t.navigateTo(cardPage.pageUrl); - //use showMode.clientScripts.js - }); - - test('Fill in card number with a socialSecurityNumber (CPF) field (socialSecurityMode: show)', async t => { - // Start, allow time for iframes to load - // await start(t, 2000, TEST_SPEED); - // - // // Fill card field with non-korean card - // await cardUtils.fillCardNumber(t, REGULAR_TEST_CARD); - // - // // Does the password securedField get removed - // await t.expect(passwordHolder.exists).notOk(); - // - // // Complete form - // await cardUtils.fillDateAndCVC(t); - // - // await fillSSN(t); - // - // // Expect card to now be valid - // await t.expect(getIsValid()).eql(true); - }); - - test('Fill in card number with a wrong socialSecurityNumber (CPF) field (socialSecurityMode: show)', async t => { - // Start, allow time for iframes to load - // await start(t, 2000, TEST_SPEED); - // - // // Fill card field with non-korean card - // await cardUtils.fillCardNumber(t, REGULAR_TEST_CARD); - // - // // Does the password securedField get removed - // await t.expect(passwordHolder.exists).notOk(); - // - // // Complete form - // await cardUtils.fillDateAndCVC(t); - // - // await fillSSN(t, '1234'); - // - // // Expect card to now be valid - // await t.expect(getIsValid()).eql(false); - }); -}); diff --git a/packages/lib/storybook/stories/cards/Card.stories.tsx b/packages/lib/storybook/stories/cards/Card.stories.tsx index 660235799..2741afcb5 100644 --- a/packages/lib/storybook/stories/cards/Card.stories.tsx +++ b/packages/lib/storybook/stories/cards/Card.stories.tsx @@ -50,6 +50,19 @@ export const Default: CardStory = { } }; +export const WithSSN: CardStory = { + render: createCardComponent, + args: { + countryCode: 'BR', + componentConfiguration: { + _disableClickToPay: true, + configuration: { + socialSecurityNumberMode: 'show' + } + } + } +}; + export const WithAVS: CardStory = { render: createCardComponent, args: {