|
| 1 | +import { expect, test } from '../../../../fixtures/card.fixture'; |
| 2 | +import { URL_MAP } from '../../../../fixtures/URL_MAP'; |
| 3 | +import { |
| 4 | + KOREAN_TEST_CARD, |
| 5 | + PAYMENT_RESULT, |
| 6 | + REGULAR_TEST_CARD, |
| 7 | + TEST_CVC_VALUE, |
| 8 | + TEST_DATE_VALUE, |
| 9 | + TEST_PWD_VALUE, |
| 10 | + TEST_TAX_NUMBER_VALUE |
| 11 | +} from '../../../utils/constants'; |
| 12 | +import { getStoryUrl } from '../../../utils/getStoryUrl'; |
| 13 | +import { paymentSuccessfulMock } from '../../../../mocks/payments/payments.mock'; |
| 14 | + |
| 15 | +test.describe('Card with KCP fields', () => { |
| 16 | + test.describe('Displaying KCP fields by default', () => { |
| 17 | + test('should hide KCP fields if Card is not korean and make the payment', async ({ cardWithKCP }) => { |
| 18 | + await cardWithKCP.goto(URL_MAP.cardWithKcp); |
| 19 | + await cardWithKCP.typeCardNumber(REGULAR_TEST_CARD); |
| 20 | + |
| 21 | + await expect(cardWithKCP.passwordInput).not.toBeVisible(); |
| 22 | + await expect(cardWithKCP.taxNumberInput).not.toBeVisible(); |
| 23 | + |
| 24 | + await cardWithKCP.typeCvc(TEST_CVC_VALUE); |
| 25 | + await cardWithKCP.typeExpiryDate(TEST_DATE_VALUE); |
| 26 | + await cardWithKCP.pay(); |
| 27 | + |
| 28 | + await expect(cardWithKCP.paymentResult).toContainText(PAYMENT_RESULT.authorised); |
| 29 | + }); |
| 30 | + |
| 31 | + test('should hide KCP fields if Card is not korean, then show them again once the Card is replaced by korean card and make the payment', async ({ |
| 32 | + cardWithKCP, |
| 33 | + page |
| 34 | + }) => { |
| 35 | + await paymentSuccessfulMock(page); |
| 36 | + const paymentsRequestPromise = page.waitForRequest(request => request.url().includes('/payments') && request.method() === 'POST'); |
| 37 | + |
| 38 | + await cardWithKCP.goto(URL_MAP.cardWithKcp); |
| 39 | + await cardWithKCP.typeCardNumber(REGULAR_TEST_CARD); |
| 40 | + |
| 41 | + await expect(cardWithKCP.passwordInput).not.toBeVisible(); |
| 42 | + await expect(cardWithKCP.taxNumberInput).not.toBeVisible(); |
| 43 | + |
| 44 | + await cardWithKCP.deleteCardNumber(); |
| 45 | + |
| 46 | + await cardWithKCP.typeCardNumber(KOREAN_TEST_CARD); |
| 47 | + await cardWithKCP.typeCvc(TEST_CVC_VALUE); |
| 48 | + await cardWithKCP.typeExpiryDate(TEST_DATE_VALUE); |
| 49 | + await cardWithKCP.typeTaxNumber(TEST_TAX_NUMBER_VALUE); |
| 50 | + await cardWithKCP.typePassword(TEST_PWD_VALUE); |
| 51 | + await cardWithKCP.pay(); |
| 52 | + |
| 53 | + // Check that KCP fields are passed in |
| 54 | + const request = await paymentsRequestPromise; |
| 55 | + const paymentMethod = await request.postDataJSON().paymentMethod; |
| 56 | + expect(paymentMethod.encryptedPassword).not.toBeNull(); |
| 57 | + expect(paymentMethod.taxNumber).not.toBeNull(); |
| 58 | + |
| 59 | + await expect(cardWithKCP.paymentResult).toContainText(PAYMENT_RESULT.authorised); |
| 60 | + }); |
| 61 | + test('should fill in KCP fields, then replace with non-korean Card and make a payment', async ({ cardWithKCP }) => { |
| 62 | + await cardWithKCP.goto(URL_MAP.cardWithKcp); |
| 63 | + |
| 64 | + await cardWithKCP.typeCardNumber(KOREAN_TEST_CARD); |
| 65 | + await cardWithKCP.typeCvc(TEST_CVC_VALUE); |
| 66 | + await cardWithKCP.typeExpiryDate(TEST_DATE_VALUE); |
| 67 | + await cardWithKCP.typeTaxNumber(TEST_TAX_NUMBER_VALUE); |
| 68 | + await cardWithKCP.typePassword(TEST_PWD_VALUE); |
| 69 | + |
| 70 | + await cardWithKCP.deleteCardNumber(); |
| 71 | + await cardWithKCP.typeCardNumber(REGULAR_TEST_CARD); |
| 72 | + |
| 73 | + await expect(cardWithKCP.passwordInput).not.toBeVisible(); |
| 74 | + await expect(cardWithKCP.taxNumberInput).not.toBeVisible(); |
| 75 | + |
| 76 | + await cardWithKCP.pay(); |
| 77 | + |
| 78 | + await expect(cardWithKCP.paymentResult).toContainText(PAYMENT_RESULT.authorised); |
| 79 | + }); |
| 80 | + }); |
| 81 | + |
| 82 | + test.describe('Displaying KCP fields once Korean card is detected', () => { |
| 83 | + const url = getStoryUrl({ |
| 84 | + baseUrl: URL_MAP.card, |
| 85 | + componentConfig: { |
| 86 | + brands: ['mc', 'visa', 'amex', 'korean_local_card'], |
| 87 | + configuration: { |
| 88 | + koreanAuthenticationRequired: true |
| 89 | + } |
| 90 | + } |
| 91 | + }); |
| 92 | + |
| 93 | + test('should display KCP fields once korean card is entered and make the payment', async ({ cardWithKCP, page }) => { |
| 94 | + await paymentSuccessfulMock(page); |
| 95 | + |
| 96 | + await cardWithKCP.goto(url); |
| 97 | + |
| 98 | + await expect(cardWithKCP.passwordInput).not.toBeVisible(); |
| 99 | + await expect(cardWithKCP.taxNumberInput).not.toBeVisible(); |
| 100 | + |
| 101 | + await cardWithKCP.typeCardNumber(KOREAN_TEST_CARD); |
| 102 | + |
| 103 | + await expect(cardWithKCP.passwordInput).toBeVisible(); |
| 104 | + await expect(cardWithKCP.taxNumberInput).toBeVisible(); |
| 105 | + |
| 106 | + await cardWithKCP.typeCvc(TEST_CVC_VALUE); |
| 107 | + await cardWithKCP.typeExpiryDate(TEST_DATE_VALUE); |
| 108 | + await cardWithKCP.typeTaxNumber(TEST_TAX_NUMBER_VALUE); |
| 109 | + await cardWithKCP.typePassword(TEST_PWD_VALUE); |
| 110 | + await cardWithKCP.pay(); |
| 111 | + |
| 112 | + await expect(cardWithKCP.paymentResult).toContainText(PAYMENT_RESULT.authorised); |
| 113 | + }); |
| 114 | + |
| 115 | + test('should display KCP fields once korean card is entered, then replace by regular Card and make the payment', async ({ cardWithKCP }) => { |
| 116 | + await cardWithKCP.goto(url); |
| 117 | + |
| 118 | + await cardWithKCP.typeCardNumber(KOREAN_TEST_CARD); |
| 119 | + |
| 120 | + await expect(cardWithKCP.passwordInput).toBeVisible(); |
| 121 | + await expect(cardWithKCP.taxNumberInput).toBeVisible(); |
| 122 | + |
| 123 | + await cardWithKCP.deleteCardNumber(); |
| 124 | + |
| 125 | + await cardWithKCP.typeCardNumber(REGULAR_TEST_CARD); |
| 126 | + await cardWithKCP.typeCvc(TEST_CVC_VALUE); |
| 127 | + await cardWithKCP.typeExpiryDate(TEST_DATE_VALUE); |
| 128 | + |
| 129 | + await expect(cardWithKCP.passwordInput).not.toBeVisible(); |
| 130 | + await expect(cardWithKCP.taxNumberInput).not.toBeVisible(); |
| 131 | + |
| 132 | + await cardWithKCP.pay(); |
| 133 | + |
| 134 | + await expect(cardWithKCP.paymentResult).toContainText(PAYMENT_RESULT.authorised); |
| 135 | + }); |
| 136 | + |
| 137 | + test('should apply validation to KCP fields', async ({ cardWithKCP }) => { |
| 138 | + await cardWithKCP.goto(url); |
| 139 | + |
| 140 | + await cardWithKCP.typeCardNumber(KOREAN_TEST_CARD); |
| 141 | + await cardWithKCP.typeCvc(TEST_CVC_VALUE); |
| 142 | + await cardWithKCP.typeExpiryDate(TEST_DATE_VALUE); |
| 143 | + await cardWithKCP.pay(); |
| 144 | + |
| 145 | + await expect(cardWithKCP.taxNumberErrorLocator).toHaveText('Invalid Cardholder birthdate or Corporate registration number'); |
| 146 | + await expect(cardWithKCP.passwordErrorLocator).toHaveText('Enter the password'); |
| 147 | + }); |
| 148 | + }); |
| 149 | +}); |
0 commit comments