From 0f30cf0e4b92dbec88a1ced4e419f782d309a5ac Mon Sep 17 00:00:00 2001 From: shubhamchasing Date: Thu, 24 Oct 2024 07:32:56 +0530 Subject: [PATCH] test(adyen): add e2e test for successful card payment flow --- .../e2e/adyen-card-flow-e2e-test.cy.ts | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 cypress-tests/cypress/e2e/adyen-card-flow-e2e-test.cy.ts diff --git a/cypress-tests/cypress/e2e/adyen-card-flow-e2e-test.cy.ts b/cypress-tests/cypress/e2e/adyen-card-flow-e2e-test.cy.ts new file mode 100644 index 000000000..cd9de58dc --- /dev/null +++ b/cypress-tests/cypress/e2e/adyen-card-flow-e2e-test.cy.ts @@ -0,0 +1,71 @@ +import * as testIds from "../../../src/Utilities/TestUtils.bs"; +import { + getClientURL, + createPaymentBody, + changeObjectKeyValue, +} from "../support/utils"; + +describe("Adyen Card payment flow test", () => { + const publishableKey = Cypress.env("HYPERSWITCH_PUBLISHABLE_KEY"); + const secretKey = Cypress.env("HYPERSWITCH_SECRET_KEY"); + let getIframeBody: () => Cypress.Chainable>; + const iframeSelector = + "#orca-payment-element-iframeRef-orca-elements-payment-element-payment-element"; + const adyenIframeSelector = ".adyen-checkout__iframe--threeDSIframe"; + + changeObjectKeyValue( + createPaymentBody, + "profile_id", + Cypress.env("PROFILE_ID") + ); + changeObjectKeyValue(createPaymentBody, "authentication_type", "three_ds"); + + beforeEach(() => { + getIframeBody = () => cy.iframe(iframeSelector); + cy.createPaymentIntent(secretKey, createPaymentBody).then(() => { + cy.getGlobalState("clientSecret").then((clientSecret) => { + cy.visit(getClientURL(clientSecret, publishableKey)); + }); + }); + }); + + it("title rendered correctly", () => { + cy.contains("Hyperswitch Unified Checkout").should("be.visible"); + }); + + it("orca-payment-element iframe loaded", () => { + cy.frameLoaded(iframeSelector); + }); + + it("submit payment form and make successful payment", () => { + getIframeBody().find(`[data-testid=${testIds.addNewCardIcon}]`).click(); + cy.enterValueInIframe(testIds.cardNoInputTestId, "4917 6100 0000 0000"); + cy.enterValueInIframe(testIds.expiryInputTestId, "03/30"); + cy.enterValueInIframe(testIds.cardCVVInputTestId, "737"); + + cy.intercept("**/payments/redirect/**").as("hyperswitchRedriect"); + cy.intercept("**/checkoutshopper/threeDS2.shtml*").as("adyenCheckout"); + + getIframeBody().get("#submit").click(); + + //redirect through hyperswitch + cy.wait("@hyperswitchRedriect").then(() => { + cy.location("pathname").should("include", "/payments/redirect"); + cy.contains("Please wait while we process your payment...").should( + "be.visible" + ); + }); + + //adyen checkout page + cy.wait("@adyenCheckout").then(() => { + //not using cy.iframe as it can only be applied to exactly one iframe at a time + cy.get(adyenIframeSelector).should("be.visible"); + + cy.getIframeElement(adyenIframeSelector, ".input-field").type("password"); + cy.getIframeElement(adyenIframeSelector, "#buttonSubmit").click(); + + cy.contains("Returning to JuspayDEECOM"); + }); + cy.contains("Thanks for your order!").should("be.visible"); + }); +});