Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add e2e test for card payment for Adyen connector successful flow #749

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
278f1b5
feat: add getIframeElement for accessing iframe elements
shubhamchasing Oct 24, 2024
0f30cf0
test(adyen): add e2e test for successful card payment flow
shubhamchasing Oct 24, 2024
30c060c
feat: add clickElementInIframe command and use cy.iframe in getIframe…
shubhamchasing Oct 24, 2024
c2da6a7
feat: add adyen3DSCardDetails in fixture and make necessary changes
shubhamchasing Oct 24, 2024
be45ed4
Merge branch 'main' into test/adyen-card-e2e-success-flow
PritishBudhiraja Oct 31, 2024
24e2446
refactor: move adyen card details to utils
shubhamchasing Nov 8, 2024
43ffffb
fix: add test cases only for normal card payment
shubhamchasing Nov 12, 2024
133087c
Merge branch 'main' into test/adyen-card-e2e-success-flow
shubhamchasing Nov 12, 2024
e40e6d7
Merge branch 'main' into test/adyen-card-e2e-success-flow
shubhamchasing Nov 12, 2024
d1443d4
Merge branch 'main' into test/adyen-card-e2e-success-flow
PritishBudhiraja Nov 13, 2024
5c1f651
Merge branch 'main' into test/adyen-card-e2e-success-flow
shubhamchasing Nov 14, 2024
5bfe097
Merge branch 'main' into test/adyen-card-e2e-success-flow
shubhamchasing Nov 19, 2024
3caabc5
Merge branch 'main' into test/adyen-card-e2e-success-flow
shubhamchasing Nov 26, 2024
7df9fd0
Merge branch 'main' into test/adyen-card-e2e-success-flow
shubhamchasing Dec 5, 2024
5a16b6d
Merge branch 'main' into test/adyen-card-e2e-success-flow
shubhamchasing Dec 16, 2024
5192264
Merge branch 'main' into test/adyen-card-e2e-success-flow
shubhamchasing Jan 12, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions cypress-tests/cypress/e2e/adyen-card-flow-e2e-test.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
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<JQuery<HTMLBodyElement>>;
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")
shubhamchasing marked this conversation as resolved.
Show resolved Hide resolved
);
changeObjectKeyValue(createPaymentBody, "authentication_type", "three_ds");
shubhamchasing marked this conversation as resolved.
Show resolved Hide resolved

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", () => {
cy.clickElementInIframe(testIds.addNewCardIcon);

cy.fixture("adyen3DSCardDetails").then((cardDetails) => {
cy.enterValueInIframe(testIds.cardNoInputTestId, cardDetails.cardNumber);
cy.enterValueInIframe(testIds.expiryInputTestId, cardDetails.expiryDate);
cy.enterValueInIframe(testIds.cardCVVInputTestId, cardDetails.cvv);
shubhamchasing marked this conversation as resolved.
Show resolved Hide resolved
});

cy.intercept("**/payments/redirect/**").as("hyperswitchRedriect");
cy.intercept("**/checkoutshopper/threeDS2.shtml*").as("adyenCheckout");
shubhamchasing marked this conversation as resolved.
Show resolved Hide resolved

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(() => {
cy.frameLoaded(adyenIframeSelector);
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");
});
shubhamchasing marked this conversation as resolved.
Show resolved Hide resolved
});
5 changes: 5 additions & 0 deletions cypress-tests/cypress/fixtures/adyen3DSCardDetails.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"cardNumber": "4917 6100 0000 0000",
"expiryDate": "03/30",
"cvv": "737"
}
shubhamchasing marked this conversation as resolved.
Show resolved Hide resolved
61 changes: 37 additions & 24 deletions cypress-tests/cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
import "cypress-iframe";
import { createPaymentBody } from "./utils"
import { createPaymentBody } from "./utils";
import * as testIds from "../../../src/Utilities/TestUtils.bs";
// commands.js or your custom support file
const iframeSelector =
Expand All @@ -46,6 +46,13 @@ Cypress.Commands.add("selectValueInIframe", (selector, value) => {
.select(value);
});

Cypress.Commands.add("clickElementInIframe", (selector) => {
cy.iframe(iframeSelector)
.find(`[data-testid=${selector}]`)
.should("be.visible")
.click();
});

shubhamchasing marked this conversation as resolved.
Show resolved Hide resolved
Cypress.Commands.add("hardReload", () => {
cy.wrap(
Cypress.automation("remote:debugger:protocol", {
Expand Down Expand Up @@ -146,30 +153,36 @@ Cypress.Commands.add(
}
);


Cypress.Commands.add("createPaymentIntent", (secretKey: string, createPaymentBody: any) => {
return cy
.request({
method: "POST",
url: "https://sandbox.hyperswitch.io/payments",
headers: {
"Content-Type": "application/json",
Accept: "application/json",
"api-key": secretKey,
},
body: JSON.stringify(createPaymentBody),
})
.then((response) => {
expect(response.headers["content-type"]).to.include("application/json");
expect(response.body).to.have.property("client_secret");
const clientSecret = response.body.client_secret;
cy.log(clientSecret);
cy.log(response.toString());

globalState["clientSecret"] = clientSecret;
});
});
Cypress.Commands.add(
"createPaymentIntent",
(secretKey: string, createPaymentBody: any) => {
return cy
.request({
method: "POST",
url: "https://sandbox.hyperswitch.io/payments",
headers: {
"Content-Type": "application/json",
Accept: "application/json",
"api-key": secretKey,
},
body: JSON.stringify(createPaymentBody),
})
.then((response) => {
expect(response.headers["content-type"]).to.include("application/json");
expect(response.body).to.have.property("client_secret");
const clientSecret = response.body.client_secret;
cy.log(clientSecret);
cy.log(response.toString());

globalState["clientSecret"] = clientSecret;
});
}
);
shubhamchasing marked this conversation as resolved.
Show resolved Hide resolved

Cypress.Commands.add("getGlobalState", (key: any) => {
return globalState[key];
});

Cypress.Commands.add("getIframeElement", (iframeSelector, elementSelector) => {
return cy.iframe(iframeSelector).find(elementSelector).should("be.visible");
});
shubhamchasing marked this conversation as resolved.
Show resolved Hide resolved
67 changes: 41 additions & 26 deletions cypress-tests/cypress/support/types.ts
shubhamchasing marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,31 +1,46 @@

export { }; // indicate that file is a module
export {}; // indicate that file is a module

export type CustomerData = {
cardNo: string
cardExpiry: string
cardCVV: string
cardHolderName: string
email: string
address: string
city: string
country: string
state: string
postalCode: string
threeDSCardNo: string
}
cardNo: string;
cardExpiry: string;
cardCVV: string;
cardHolderName: string;
email: string;
address: string;
city: string;
country: string;
state: string;
postalCode: string;
threeDSCardNo: string;
};

declare global {
namespace Cypress {
interface Chainable {
enterValueInIframe(selector: string, value: string): Chainable<JQuery<HTMLElement>>
selectValueInIframe(selector: string, value: string): Chainable<JQuery<HTMLElement>>
hardReload(): Chainable<JQuery<HTMLElement>>
testDynamicFields(
customerData: CustomerData, testIdsToRemoveArr: string[], isThreeDSEnabled: boolean
): Chainable<JQuery<HTMLElement>>
createPaymentIntent(secretKey: string, createPaymentBody: Record<string, any>): Chainable<Response<any>>
getGlobalState(key: string): Chainable<Response<any>>
}
namespace Cypress {
interface Chainable {
enterValueInIframe(
selector: string,
value: string
): Chainable<JQuery<HTMLElement>>;
selectValueInIframe(
selector: string,
value: string
): Chainable<JQuery<HTMLElement>>;
clickElementInIframe(selector: string): Chainable<JQuery<HTMLElement>>;
hardReload(): Chainable<JQuery<HTMLElement>>;
testDynamicFields(
customerData: CustomerData,
testIdsToRemoveArr: string[],
isThreeDSEnabled: boolean
): Chainable<JQuery<HTMLElement>>;
createPaymentIntent(
secretKey: string,
createPaymentBody: Record<string, any>
): Chainable<Response<any>>;
getGlobalState(key: string): Chainable<Response<any>>;
getIframeElement(
iframeSelector: string,
elementSelector: string
): Chainable<JQuery<HTMLElement>>;
}
}
}
}
Loading