From ddfd139b8a81d251157158e18c1bf5af2f6f61ab Mon Sep 17 00:00:00 2001 From: "aritro.ghosh" Date: Thu, 14 Nov 2024 14:56:31 +0530 Subject: [PATCH 1/4] chore: add automated Cypress test for card number input validation --- .../e2e/card-number-validation-test.cy.ts | 107 ++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 cypress-tests/cypress/e2e/card-number-validation-test.cy.ts diff --git a/cypress-tests/cypress/e2e/card-number-validation-test.cy.ts b/cypress-tests/cypress/e2e/card-number-validation-test.cy.ts new file mode 100644 index 000000000..dc8544e53 --- /dev/null +++ b/cypress-tests/cypress/e2e/card-number-validation-test.cy.ts @@ -0,0 +1,107 @@ +import * as testIds from "../../../src/Utilities/TestUtils.bs"; +import { getClientURL } from "../support/utils"; +import { createPaymentBody } from "../support/utils"; +import { changeObjectKeyValue } from "../support/utils"; +import { stripeCards } from "cypress/support/cards"; + +describe("Card number validation test", () => { + + const publishableKey = Cypress.env('HYPERSWITCH_PUBLISHABLE_KEY') + const secretKey = Cypress.env('HYPERSWITCH_SECRET_KEY') + let getIframeBody: () => Cypress.Chainable>; + let iframeSelector = + "#orca-payment-element-iframeRef-orca-elements-payment-element-payment-element"; + + // changeObjectKeyValue(createPaymentBody,"profile_id","YOUR_PROFILE_ID") + changeObjectKeyValue(createPaymentBody,"customer_id","new_user") + + + beforeEach(() => { + getIframeBody = () => cy.iframe(iframeSelector); + cy.createPaymentIntent(secretKey, createPaymentBody).then(() => { + cy.getGlobalState("clientSecret").then((clientSecret) => { + + cy.visit(getClientURL(clientSecret, publishableKey)); + }); + + }) + }); + + it("should complete the card payment successfully", () => { + const { cardNo, card_exp_month, card_exp_year, cvc } = stripeCards.successCard; + + getIframeBody().find('[data-testid=cardNoInput]').type(cardNo); + getIframeBody().find('[data-testid=expiryInput]').type(card_exp_month); + getIframeBody().find('[data-testid=expiryInput]').type(card_exp_year); + getIframeBody().find('[data-testid=cvvInput]').type(cvc); + + getIframeBody().get("#submit").click(); + + cy.wait(3000); + cy.contains("Thanks for your order!").should("be.visible"); + }); + + it("should fail with an undetectable card brand", () => { + const { card_exp_month, card_exp_year, cvc } = stripeCards.successCard; + + getIframeBody().find('[data-testid=cardNoInput]').type("111111"); + getIframeBody().find('[data-testid=expiryInput]').type(card_exp_month); + getIframeBody().find('[data-testid=expiryInput]').type(card_exp_year); + getIframeBody().find('[data-testid=cvvInput]').type(cvc); + + getIframeBody().get("#submit").click(); + + cy.wait(3000); + + getIframeBody().find('.Error.pt-1').should('be.visible') + .and('contain.text', "Please enter a valid card number."); + }); + + it("should fail with a detectable but invalid card number", () => { + const { card_exp_month, card_exp_year, cvc } = stripeCards.successCard; + + getIframeBody().find('[data-testid=cardNoInput]').type("424242"); + getIframeBody().find('[data-testid=expiryInput]').type(card_exp_month); + getIframeBody().find('[data-testid=expiryInput]').type(card_exp_year); + getIframeBody().find('[data-testid=cvvInput]').type(cvc); + + getIframeBody().get("#submit").click(); + + cy.wait(3000); + + getIframeBody().find('.Error.pt-1').should('be.visible') + .and('contain.text', "Card number is invalid."); + }); + + it("should fail with an unsupported card brand (RuPay)", () => { + const { card_exp_month, card_exp_year, cvc } = stripeCards.successCard; + + getIframeBody().find('[data-testid=cardNoInput]').type("6082015309577308"); + getIframeBody().find('[data-testid=expiryInput]').type(card_exp_month); + getIframeBody().find('[data-testid=expiryInput]').type(card_exp_year); + getIframeBody().find('[data-testid=cvvInput]').type(cvc); + + getIframeBody().get("#submit").click(); + + cy.wait(3000); + + getIframeBody().find('.Error.pt-1').should('be.visible') + .and('contain.text', "RuPay is not supported at the moment."); + }); + + it("should fail with an empty card number", () => { + const { card_exp_month, card_exp_year, cvc } = stripeCards.successCard; + + getIframeBody().find('[data-testid=expiryInput]').type(card_exp_month); + getIframeBody().find('[data-testid=expiryInput]').type(card_exp_year); + getIframeBody().find('[data-testid=cvvInput]').type(cvc); + + getIframeBody().get("#submit").click(); + + cy.wait(3000); + + getIframeBody().find('.Error.pt-1').should('be.visible') + .and('contain.text', "Card Number cannot be empty"); + }); + +}); From 0f47cd04c40350d6e6b658d20aff351d10b106a4 Mon Sep 17 00:00:00 2001 From: "aritro.ghosh" Date: Mon, 18 Nov 2024 16:41:35 +0530 Subject: [PATCH 2/4] refactor: incorporate Suggested Changes --- .../e2e/card-number-validation-test.cy.ts | 39 +++++++------------ 1 file changed, 13 insertions(+), 26 deletions(-) diff --git a/cypress-tests/cypress/e2e/card-number-validation-test.cy.ts b/cypress-tests/cypress/e2e/card-number-validation-test.cy.ts index dc8544e53..d8a2ebd27 100644 --- a/cypress-tests/cypress/e2e/card-number-validation-test.cy.ts +++ b/cypress-tests/cypress/e2e/card-number-validation-test.cy.ts @@ -27,20 +27,6 @@ describe("Card number validation test", () => { }) }); - it("should complete the card payment successfully", () => { - const { cardNo, card_exp_month, card_exp_year, cvc } = stripeCards.successCard; - - getIframeBody().find('[data-testid=cardNoInput]').type(cardNo); - getIframeBody().find('[data-testid=expiryInput]').type(card_exp_month); - getIframeBody().find('[data-testid=expiryInput]').type(card_exp_year); - getIframeBody().find('[data-testid=cvvInput]').type(cvc); - - getIframeBody().get("#submit").click(); - - cy.wait(3000); - cy.contains("Thanks for your order!").should("be.visible"); - }); - it("should fail with an undetectable card brand", () => { const { card_exp_month, card_exp_year, cvc } = stripeCards.successCard; @@ -51,10 +37,11 @@ describe("Card number validation test", () => { getIframeBody().get("#submit").click(); - cy.wait(3000); - getIframeBody().find('.Error.pt-1').should('be.visible') - .and('contain.text', "Please enter a valid card number."); + .and('contain.text', "Please enter a valid card number."); + getIframeBody().find('[data-testid=cardNoInput]').click(); + getIframeBody().find('.Error.pt-1').should('not.exist'); + }); it("should fail with a detectable but invalid card number", () => { @@ -66,11 +53,11 @@ describe("Card number validation test", () => { getIframeBody().find('[data-testid=cvvInput]').type(cvc); getIframeBody().get("#submit").click(); - - cy.wait(3000); - + getIframeBody().find('.Error.pt-1').should('be.visible') .and('contain.text', "Card number is invalid."); + getIframeBody().find('[data-testid=cardNoInput]').click(); + getIframeBody().find('.Error.pt-1').should('not.exist'); }); it("should fail with an unsupported card brand (RuPay)", () => { @@ -82,11 +69,11 @@ describe("Card number validation test", () => { getIframeBody().find('[data-testid=cvvInput]').type(cvc); getIframeBody().get("#submit").click(); - - cy.wait(3000); - + getIframeBody().find('.Error.pt-1').should('be.visible') .and('contain.text', "RuPay is not supported at the moment."); + getIframeBody().find('[data-testid=cardNoInput]').click(); + getIframeBody().find('.Error.pt-1').should('not.exist'); }); it("should fail with an empty card number", () => { @@ -97,11 +84,11 @@ describe("Card number validation test", () => { getIframeBody().find('[data-testid=cvvInput]').type(cvc); getIframeBody().get("#submit").click(); - - cy.wait(3000); - + getIframeBody().find('.Error.pt-1').should('be.visible') .and('contain.text', "Card Number cannot be empty"); + getIframeBody().find('[data-testid=cardNoInput]').click(); + getIframeBody().find('.Error.pt-1').should('not.exist'); }); }); From b4f6af00bdc31e90251e29d7bccebabd86975cee Mon Sep 17 00:00:00 2001 From: "aritro.ghosh" Date: Thu, 5 Dec 2024 14:07:20 +0530 Subject: [PATCH 3/4] test: update card number validation test cases --- .../e2e/card-number-validation-test.cy.ts | 38 +++++++++---------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/cypress-tests/cypress/e2e/card-number-validation-test.cy.ts b/cypress-tests/cypress/e2e/card-number-validation-test.cy.ts index d8a2ebd27..e4f9473d0 100644 --- a/cypress-tests/cypress/e2e/card-number-validation-test.cy.ts +++ b/cypress-tests/cypress/e2e/card-number-validation-test.cy.ts @@ -30,16 +30,16 @@ describe("Card number validation test", () => { it("should fail with an undetectable card brand", () => { const { card_exp_month, card_exp_year, cvc } = stripeCards.successCard; - getIframeBody().find('[data-testid=cardNoInput]').type("111111"); - getIframeBody().find('[data-testid=expiryInput]').type(card_exp_month); - getIframeBody().find('[data-testid=expiryInput]').type(card_exp_year); - getIframeBody().find('[data-testid=cvvInput]').type(cvc); + getIframeBody().find(`[data-testid=${testIds.cardNoInputTestId}]`).type("111111"); + getIframeBody().find(`[data-testid=${testIds.expiryInputTestId}]`).type(card_exp_month); + getIframeBody().find(`[data-testid=${testIds.expiryInputTestId}]`).type(card_exp_year); + getIframeBody().find(`[data-testid=${testIds.cardCVVInputTestId}]`).type(cvc); getIframeBody().get("#submit").click(); getIframeBody().find('.Error.pt-1').should('be.visible') .and('contain.text', "Please enter a valid card number."); - getIframeBody().find('[data-testid=cardNoInput]').click(); + getIframeBody().find(`[data-testid=${testIds.cardNoInputTestId}]`).click(); getIframeBody().find('.Error.pt-1').should('not.exist'); }); @@ -47,48 +47,46 @@ describe("Card number validation test", () => { it("should fail with a detectable but invalid card number", () => { const { card_exp_month, card_exp_year, cvc } = stripeCards.successCard; - getIframeBody().find('[data-testid=cardNoInput]').type("424242"); - getIframeBody().find('[data-testid=expiryInput]').type(card_exp_month); - getIframeBody().find('[data-testid=expiryInput]').type(card_exp_year); - getIframeBody().find('[data-testid=cvvInput]').type(cvc); + getIframeBody().find(`[data-testid=${testIds.cardNoInputTestId}]`).type("424242"); + getIframeBody().find(`[data-testid=${testIds.expiryInputTestId}]`).type(card_exp_month); + getIframeBody().find(`[data-testid=${testIds.expiryInputTestId}]`).type(card_exp_year); + getIframeBody().find(`[data-testid=${testIds.cardCVVInputTestId}]`).type(cvc); getIframeBody().get("#submit").click(); getIframeBody().find('.Error.pt-1').should('be.visible') .and('contain.text', "Card number is invalid."); - getIframeBody().find('[data-testid=cardNoInput]').click(); + getIframeBody().find(`[data-testid=${testIds.cardNoInputTestId}]`).click(); getIframeBody().find('.Error.pt-1').should('not.exist'); }); it("should fail with an unsupported card brand (RuPay)", () => { const { card_exp_month, card_exp_year, cvc } = stripeCards.successCard; - getIframeBody().find('[data-testid=cardNoInput]').type("6082015309577308"); - getIframeBody().find('[data-testid=expiryInput]').type(card_exp_month); - getIframeBody().find('[data-testid=expiryInput]').type(card_exp_year); - getIframeBody().find('[data-testid=cvvInput]').type(cvc); + getIframeBody().find(`[data-testid=${testIds.cardNoInputTestId}]`).type("6082015309577308"); + getIframeBody().find(`[data-testid=${testIds.expiryInputTestId}]`).type(card_exp_month); + getIframeBody().find(`[data-testid=${testIds.expiryInputTestId}]`).type(card_exp_year); + getIframeBody().find(`[data-testid=${testIds.cardCVVInputTestId}]`).type(cvc); getIframeBody().get("#submit").click(); getIframeBody().find('.Error.pt-1').should('be.visible') .and('contain.text', "RuPay is not supported at the moment."); - getIframeBody().find('[data-testid=cardNoInput]').click(); + getIframeBody().find(`[data-testid=${testIds.cardNoInputTestId}]`).click(); getIframeBody().find('.Error.pt-1').should('not.exist'); }); it("should fail with an empty card number", () => { const { card_exp_month, card_exp_year, cvc } = stripeCards.successCard; - getIframeBody().find('[data-testid=expiryInput]').type(card_exp_month); - getIframeBody().find('[data-testid=expiryInput]').type(card_exp_year); - getIframeBody().find('[data-testid=cvvInput]').type(cvc); + getIframeBody().find(`[data-testid=${testIds.expiryInputTestId}]`).type(card_exp_month); + getIframeBody().find(`[data-testid=${testIds.expiryInputTestId}]`).type(card_exp_year); + getIframeBody().find(`[data-testid=${testIds.cardCVVInputTestId}]`).type(cvc); getIframeBody().get("#submit").click(); getIframeBody().find('.Error.pt-1').should('be.visible') .and('contain.text', "Card Number cannot be empty"); - getIframeBody().find('[data-testid=cardNoInput]').click(); - getIframeBody().find('.Error.pt-1').should('not.exist'); }); }); From 199bfecefb2524443dd33311be8662bd5cdc1170 Mon Sep 17 00:00:00 2001 From: "aritro.ghosh" Date: Tue, 11 Feb 2025 11:41:01 +0530 Subject: [PATCH 4/4] fix: test case name correction --- cypress-tests/cypress/e2e/card-number-validation-test.cy.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cypress-tests/cypress/e2e/card-number-validation-test.cy.ts b/cypress-tests/cypress/e2e/card-number-validation-test.cy.ts index e4f9473d0..a3320e705 100644 --- a/cypress-tests/cypress/e2e/card-number-validation-test.cy.ts +++ b/cypress-tests/cypress/e2e/card-number-validation-test.cy.ts @@ -27,7 +27,7 @@ describe("Card number validation test", () => { }) }); - it("should fail with an undetectable card brand", () => { + it("should fail with an undetectable card brand and invalid card number", () => { const { card_exp_month, card_exp_year, cvc } = stripeCards.successCard; getIframeBody().find(`[data-testid=${testIds.cardNoInputTestId}]`).type("111111");