From c43ab404967868fcacb97ba3a60a65011dc4440d Mon Sep 17 00:00:00 2001 From: preetamrevankar Date: Wed, 6 Nov 2024 16:47:09 +0530 Subject: [PATCH] refactor: addresed comments --- ...t.cy.ts => saved-card-flow-e2e-test.cy.ts} | 5 +- ...ts => stripe-3DS-card-flow-e2e-test.cy.ts} | 27 ++++----- ...e-manual-capture-card-flow-e2e-test.cy.ts} | 16 ++---- ...=> stripe-no-3DS-card-flow-e2e-test.cy.ts} | 55 ++++++++----------- cypress-tests/cypress/support/cards.ts | 32 ----------- 5 files changed, 41 insertions(+), 94 deletions(-) rename cypress-tests/cypress/e2e/{savedcard-test.cy.ts => saved-card-flow-e2e-test.cy.ts} (95%) rename cypress-tests/cypress/e2e/{stripe-3ds-test.cy.ts => stripe-3DS-card-flow-e2e-test.cy.ts} (70%) rename cypress-tests/cypress/e2e/{stripe-Manualcapture-test.cy.ts => stripe-manual-capture-card-flow-e2e-test.cy.ts} (80%) rename cypress-tests/cypress/e2e/{Stripe-no3ds-test.cy.ts => stripe-no-3DS-card-flow-e2e-test.cy.ts} (68%) diff --git a/cypress-tests/cypress/e2e/savedcard-test.cy.ts b/cypress-tests/cypress/e2e/saved-card-flow-e2e-test.cy.ts similarity index 95% rename from cypress-tests/cypress/e2e/savedcard-test.cy.ts rename to cypress-tests/cypress/e2e/saved-card-flow-e2e-test.cy.ts index 39f0c6fb..dc18b8c8 100644 --- a/cypress-tests/cypress/e2e/savedcard-test.cy.ts +++ b/cypress-tests/cypress/e2e/saved-card-flow-e2e-test.cy.ts @@ -10,15 +10,12 @@ describe("Card payment flow test", () => { let getIframeBody: () => Cypress.Chainable>; let iframeSelector = "#orca-payment-element-iframeRef-orca-elements-payment-element-payment-element"; + changeObjectKeyValue(createPaymentBody,"customer_id","hyperswitch_sdk_demo_id") - changeObjectKeyValue(createPaymentBody,"customer_id","hyperswitch_sdk_demo_id") - - beforeEach(() => { getIframeBody = () => cy.iframe(iframeSelector); cy.createPaymentIntent(secretKey, createPaymentBody).then(() => { cy.getGlobalState("clientSecret").then((clientSecret) => { - cy.visit(getClientURL(clientSecret, publishableKey)); }); diff --git a/cypress-tests/cypress/e2e/stripe-3ds-test.cy.ts b/cypress-tests/cypress/e2e/stripe-3DS-card-flow-e2e-test.cy.ts similarity index 70% rename from cypress-tests/cypress/e2e/stripe-3ds-test.cy.ts rename to cypress-tests/cypress/e2e/stripe-3DS-card-flow-e2e-test.cy.ts index 5a64ad3e..fc3687ea 100644 --- a/cypress-tests/cypress/e2e/stripe-3ds-test.cy.ts +++ b/cypress-tests/cypress/e2e/stripe-3DS-card-flow-e2e-test.cy.ts @@ -15,13 +15,11 @@ describe("Card payment flow test", () => { changeObjectKeyValue(createPaymentBody,"authentication_type","three_ds") 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)); + cy.visit(getClientURL(clientSecret, publishableKey)); }); }) @@ -39,20 +37,15 @@ describe("Card payment flow test", () => { }); it("should complete the card payment successfully", () => { - // Visit the page with the payment form -const{ cardNo,cvc, card_exp_month, card_exp_year}=stripeCards.threeDSCard - // Wait for iframe to load and get its body - getIframeBody().find('[data-testid=cardNoInput]').type(cardNo); // Example card number - getIframeBody().find('[data-testid=expiryInput]').type(card_exp_month); // Expiration month - getIframeBody().find('[data-testid=expiryInput]').type(card_exp_year); // Expiration year - getIframeBody().find('[data-testid=cvvInput]').type(cvc); // CVV - - // Click on the submit button - getIframeBody().get("#submit").click(); - - // Wait for the response and assert payment success message - cy.wait(3000); // Adjust wait time based on actual response time - cy.url().should('include', 'hooks.stripe.com/3d_secure_2'); + const{ cardNo,cvc, card_exp_month, card_exp_year}=stripeCards.threeDSCard + 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().then(() => { + cy.url().should('include', 'hooks.stripe.com/3d_secure_2'); + }); }); }); diff --git a/cypress-tests/cypress/e2e/stripe-Manualcapture-test.cy.ts b/cypress-tests/cypress/e2e/stripe-manual-capture-card-flow-e2e-test.cy.ts similarity index 80% rename from cypress-tests/cypress/e2e/stripe-Manualcapture-test.cy.ts rename to cypress-tests/cypress/e2e/stripe-manual-capture-card-flow-e2e-test.cy.ts index bf1430dc..386458db 100644 --- a/cypress-tests/cypress/e2e/stripe-Manualcapture-test.cy.ts +++ b/cypress-tests/cypress/e2e/stripe-manual-capture-card-flow-e2e-test.cy.ts @@ -20,8 +20,7 @@ describe("Card payment flow test", () => { getIframeBody = () => cy.iframe(iframeSelector); cy.createPaymentIntent(secretKey, createPaymentBody).then(() => { cy.getGlobalState("clientSecret").then((clientSecret) => { - - cy.visit(getClientURL(clientSecret, publishableKey)); + cy.visit(getClientURL(clientSecret, publishableKey)); }); }) @@ -31,16 +30,13 @@ it("should complete the card payment successfully", () => { const { cardNo, card_exp_month, card_exp_year, cvc } = stripeCards.successCard; - // Wait for iframe to load and get its body - getIframeBody().find('[data-testid=cardNoInput]').type(cardNo); // Example card number - getIframeBody().find('[data-testid=expiryInput]').type(card_exp_month); // Expiration month - getIframeBody().find('[data-testid=expiryInput]').type(card_exp_year); // Expiration year - getIframeBody().find('[data-testid=cvvInput]').type(cvc); // CVV + 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); - // Click on the submit button getIframeBody().get("#submit").click(); - - // Wait for the response and assert payment processing message + cy.wait(3000); cy.contains('Payment processing! Requires manual capture') .should('be.visible'); diff --git a/cypress-tests/cypress/e2e/Stripe-no3ds-test.cy.ts b/cypress-tests/cypress/e2e/stripe-no-3DS-card-flow-e2e-test.cy.ts similarity index 68% rename from cypress-tests/cypress/e2e/Stripe-no3ds-test.cy.ts rename to cypress-tests/cypress/e2e/stripe-no-3DS-card-flow-e2e-test.cy.ts index 3d3fa246..18f06c7c 100644 --- a/cypress-tests/cypress/e2e/Stripe-no3ds-test.cy.ts +++ b/cypress-tests/cypress/e2e/stripe-no-3DS-card-flow-e2e-test.cy.ts @@ -28,70 +28,63 @@ describe("Card payment flow test", () => { }); it("should complete the card payment successfully", () => { - // Visit the page with the payment form - //cy.visit(CLIENT_URL); const { cardNo, card_exp_month, card_exp_year, cvc } = stripeCards.successCard; - // Wait for iframe to load and get its body - getIframeBody().find('[data-testid=cardNoInput]').type(cardNo); // Example card number - getIframeBody().find('[data-testid=expiryInput]').type(card_exp_month); // Expiration month - getIframeBody().find('[data-testid=expiryInput]').type(card_exp_year); // Expiration year - getIframeBody().find('[data-testid=cvvInput]').type(cvc); // CVV + 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); - // Click on the submit button getIframeBody().get("#submit").click(); - // Wait for the response and assert payment success message - cy.wait(3000); // Adjust wait time based on actual response time + cy.wait(3000); cy.contains("Thanks for your order!").should("be.visible"); }); it("should fail with an invalid card number", () => { - // cy.visit(CLIENT_URL); const { cardNo, card_exp_month, card_exp_year, cvc } = stripeCards.invalidCard; - getIframeBody().find('[data-testid=cardNoInput]').type(cardNo); // Invalid card number - getIframeBody().find('[data-testid=expiryInput]').type(card_exp_month); // Expiration month - getIframeBody().find('[data-testid=expiryInput]').type(card_exp_year); // Expiration year - getIframeBody().find('[data-testid=cvvInput]').type(cvc); // CVV + 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); // Adjust wait time based on actual response time - cy.contains("Please enter valid details").should("be.visible"); // Adjust based on actual error message + cy.wait(3000); + cy.contains("Please enter valid details").should("be.visible"); }); it("should show error for expired card year", () => { - //cy.visit(CLIENT_URL); - const { cardNo, card_exp_month, card_exp_year, cvc } = stripeCards.invalidYear; + const { cardNo, card_exp_month, card_exp_year, cvc } = stripeCards.successCard; - getIframeBody().find('[data-testid=cardNoInput]').type(cardNo); // Valid card number - getIframeBody().find('[data-testid=expiryInput]').type(card_exp_month); // Expiration month - getIframeBody().find('[data-testid=expiryInput]').type(card_exp_year); // Expiration year - getIframeBody().find('[data-testid=cvvInput]').type(cvc); // CVV + getIframeBody().find('[data-testid=cardNoInput]').type(cardNo); + getIframeBody().find('[data-testid=expiryInput]').type(card_exp_month); + getIframeBody().find('[data-testid=expiryInput]').type("10"); + getIframeBody().find('[data-testid=cvvInput]').type(cvc); getIframeBody().get("#submit").click(); - cy.wait(3000); // Adjust wait time based on actual response time + cy.wait(3000); getIframeBody().find('.Error.pt-1').should('be.visible') .and('contain.text', "Your card's expiration year is in the past."); }); it("should show error for incomplete card CVV", () => { - //cy.visit(CLIENT_URL); - const{ cardNo, card_exp_month , card_exp_year ,cvc}=stripeCards.invalidCVC + const{ cardNo, card_exp_month , card_exp_year ,cvc}=stripeCards.successCard; - getIframeBody().find('[data-testid=cardNoInput]').type(cardNo); // Valid card number - getIframeBody().find('[data-testid=expiryInput]').type(card_exp_month); // Expiration month - getIframeBody().find('[data-testid=expiryInput]').type(card_exp_year); // Expiration year - getIframeBody().find('[data-testid=cvvInput]').type(cvc); // Incomplete CVV + 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("1"); getIframeBody().get("#submit").click(); - cy.wait(3000); // Adjust wait time based on actual response time + cy.wait(3000); getIframeBody().find('.Error.pt-1').should('be.visible') .and('contain.text', "Your card's security code is incomplete."); }); + }); diff --git a/cypress-tests/cypress/support/cards.ts b/cypress-tests/cypress/support/cards.ts index 44088f2e..c15b85e9 100644 --- a/cypress-tests/cypress/support/cards.ts +++ b/cypress-tests/cypress/support/cards.ts @@ -10,12 +10,8 @@ export type cardDetails = { type connectorCard = { successCard: cardDetails - failureCard: cardDetails threeDSCard: cardDetails invalidCard: cardDetails - invalidCVC : cardDetails - invalidMonth:cardDetails - invalidYear: cardDetails } @@ -27,27 +23,6 @@ export const stripeCards = { card_exp_month:"12", card_exp_year:"30", }, - failureCard: { - cardNo: "4000000000000002", - cardScheme: "Visa", - cvc: "123", - card_exp_month:"12", - card_exp_year:"30", - }, - invalidYear: { - cardNo: "4242424242424242", - cardScheme: "Visa", - cvc: "123", - card_exp_month:"12", - card_exp_year:"10", - }, - invalidCVC: { - cardNo: "4000000000000002", - cardScheme: "Visa", - cvc: "12", - card_exp_month:"12", - card_exp_year:"30", - }, invalidCard: { cardNo: "400000000000000", cardScheme: "Visa", @@ -55,13 +30,6 @@ export const stripeCards = { card_exp_month:"12", card_exp_year:"30", }, - invalidMonth: { - cardNo: "4000000000000002", - cardScheme: "Visa", - cvc: "123", - card_exp_month:"13", - card_exp_year:"30", - }, threeDSCard: { cardNo: "4000000000003220", cardScheme: "Visa",