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: card cypress test added #599

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 6 additions & 6 deletions Hyperswitch-React-Demo-App/.env
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
STATIC_DIR=./dist
HYPERSWITCH_PUBLISHABLE_KEY=
HYPERSWITCH_SECRET_KEY=
HYPERSWITCH_SERVER_URL=
HYPERSWITCH_CLIENT_URL=
SELF_SERVER_URL=
PROFILE_ID=""
HYPERSWITCH_PUBLISHABLE_KEY="pk_snd_3dbcd4a313b248f78f046dfe0090636e"
HYPERSWITCH_SECRET_KEY="snd_6jXxdUbFxGW4EulF5hl0fWpJ3ABRuSDyI1vFfGaG26SdR43k6MYisvvWIqoSeKJh"
HYPERSWITCH_SERVER_URL="https://sandbox.hyperswitch.io"
HYPERSWITCH_CLIENT_URL="http://localhost:9050"
SELF_SERVER_URL=""
PROFILE_ID="pro_ka4Uc7Cj4b3hjUXxRSZY"
2 changes: 1 addition & 1 deletion Hyperswitch-React-Demo-App/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const paymentData = {
],
confirm: false,
capture_method: "automatic",
authentication_type: "three_ds",
authentication_type: "no_three_ds",
customer_id: "hyperswitch_sdk_demo_id",
email: "[email protected]",
description: "Hello this is description",
Expand Down
1 change: 1 addition & 0 deletions cypress-tests/cypress.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const { defineConfig } = require("cypress");

module.exports = defineConfig({
watchForFileChanges:true,
projectId: "6r9ayw",
chromeWebSecurity: false,
e2e: {
Expand Down
49 changes: 49 additions & 0 deletions cypress-tests/cypress/e2e/3ds-card-test.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import * as testIds from "../../../src/Utilities/TestUtils.bs";
import { CLIENT_URL } from "../support/utils";

describe("Card payment flow test", () => {
// Define the type for getIframeBody function
let getIframeBody: () => Cypress.Chainable<JQuery<HTMLBodyElement>>;
const iframeSelector = "#orca-payment-element-iframeRef-orca-elements-payment-element-payment-element";

beforeEach(() => {
// Initialize the getIframeBody function
getIframeBody = () => cy.iframe(iframeSelector);

// Visit the page with the payment form
cy.visit(CLIENT_URL);
});

it("page loaded successfully", () => {
cy.visit(CLIENT_URL);
});

it("title rendered correctly", () => {
cy.contains("Hyperswitch Unified Checkout").should("be.visible");
});

it("orca-payment-element iframe loaded", () => {
cy.get(iframeSelector)
.should("be.visible")
.its("0.contentDocument")
.its("body");
});

it("should complete the card payment successfully", () => {
// Visit the page with the payment form
cy.visit(CLIENT_URL);

// Wait for iframe to load and get its body
getIframeBody().find('[data-testid=cardNoInput]').type('4000000000003220'); // Example card number
getIframeBody().find('[data-testid=expiryInput]').type('12'); // Expiration month
getIframeBody().find('[data-testid=expiryInput]').type('25'); // Expiration year
getIframeBody().find('[data-testid=cvvInput]').type('123'); // 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');
});
});
1 change: 1 addition & 0 deletions cypress-tests/cypress/e2e/card-flow-e2e-test.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,4 @@ describe("Card payment flow test", () => {
});
});
});

85 changes: 85 additions & 0 deletions cypress-tests/cypress/e2e/no3ds-card-test.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import * as testIds from "../../../src/Utilities/TestUtils.bs";
import { CLIENT_URL } from "../support/utils";

// Define a type for the getIframeBody function
type GetIframeBody = () => Cypress.Chainable<JQuery<HTMLBodyElement>>;

describe("Card payment flow test", () => {
let getIframeBody: GetIframeBody;
const iframeSelector = "#orca-payment-element-iframeRef-orca-elements-payment-element-payment-element";

before(() => {
// Initialize the getIframeBody function
getIframeBody = () => cy.iframe(iframeSelector);
cy.visit(CLIENT_URL);
});

it("orca-payment-element iframe loaded", () => {
cy.get(iframeSelector)
.should("be.visible")
.its("0.contentDocument")
.its("body");
});

it("should complete the card payment successfully", () => {
// Visit the page with the payment form
cy.visit(CLIENT_URL);

// Wait for iframe to load and get its body
getIframeBody().find('[data-testid=cardNoInput]').type('4242424242424242'); // Example card number
getIframeBody().find('[data-testid=expiryInput]').type('12'); // Expiration month
getIframeBody().find('[data-testid=expiryInput]').type('25'); // Expiration year
getIframeBody().find('[data-testid=cvvInput]').type('123'); // 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.contains("Thanks for your order!").should("be.visible");
});

it("should fail with an invalid card number", () => {
cy.visit(CLIENT_URL);

getIframeBody().find('[data-testid=cardNoInput]').type('1234567812345678'); // Invalid card number
getIframeBody().find('[data-testid=expiryInput]').type('12'); // Expiration month
getIframeBody().find('[data-testid=expiryInput]').type('25'); // Expiration year
getIframeBody().find('[data-testid=cvvInput]').type('123'); // CVV

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
});

it("should show error for expired card year", () => {
cy.visit(CLIENT_URL);

getIframeBody().find('[data-testid=cardNoInput]').type('4242424242424242'); // Valid card number
getIframeBody().find('[data-testid=expiryInput]').type('12'); // Expiration month
getIframeBody().find('[data-testid=expiryInput]').type('20'); // Expiration year
getIframeBody().find('[data-testid=cvvInput]').type('123'); // CVV

getIframeBody().get("#submit").click();

cy.wait(3000); // Adjust wait time based on actual response time
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);

getIframeBody().find('[data-testid=cardNoInput]').type('4242424242424242'); // Valid card number
getIframeBody().find('[data-testid=expiryInput]').type('12'); // Expiration month
getIframeBody().find('[data-testid=expiryInput]').type('25'); // Expiration year
getIframeBody().find('[data-testid=cvvInput]').type('12'); // Incomplete CVV

getIframeBody().get("#submit").click();

cy.wait(3000); // Adjust wait time based on actual response time
getIframeBody().find('.Error.pt-1').should('be.visible')
.and('contain.text', "Your card's security code is incomplete.");
});
});
4 changes: 1 addition & 3 deletions cypress-tests/cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ Cypress.Commands.add(
if (isThreeDSEnabled) {
mapping[testIds.cardNoInputTestId] = customerData.threeDSCardNo;
}
let publishableKey = "pk_snd_3b33cd9404234113804aa1accaabe22f";
let clientSecret:string;
cy.request({
method: "GET",
Expand Down Expand Up @@ -148,7 +147,7 @@ Cypress.Commands.add(
const request = {
currency: "USD",
amount: 6500,
authentication_type: "three_ds",
authentication_type: "no_three_ds",
description: "Joseph First Crypto",
email: "[email protected]",
connector_metadata: {
Expand All @@ -173,7 +172,6 @@ Cypress.Commands.add("createPaymentIntent", () => {
headers: {
"Content-Type": "application/json",
Accept: "application/json",
"api-key": "snd_c691ade6995743bd88c166ba509ff5da",
},
body: JSON.stringify(request),
})
Expand Down
2 changes: 1 addition & 1 deletion cypress-tests/cypress/support/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export const CLIENT_URL = "http://localhost:9060"
export const request = {
currency: "USD",
amount: 6500,
authentication_type: "three_ds",
authentication_type: "no_three_ds",
description: "Joseph First Crypto",
email: "[email protected]",
connector_metadata: {
Expand Down
Loading