Skip to content

Commit

Permalink
test: test card payment with multiple card brands
Browse files Browse the repository at this point in the history
  • Loading branch information
aritro2002 committed Dec 9, 2024
1 parent 77f3c3b commit f51614e
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 1 deletion.
88 changes: 88 additions & 0 deletions cypress-tests/cypress/e2e/multiple-card-test.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
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<JQuery<HTMLBodyElement>>;
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("19 digit visa card", () => {
const { cardNo, card_exp_month, card_exp_year, cvc } = stripeCards.visaCard19;

getIframeBody().find(`[data-testid=${testIds.cardNoInputTestId}]`).type(cardNo);
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();


cy.contains("Thanks for your order!").should("be.visible");
});


it("16 digit master card", () => {
const { cardNo, card_exp_month, card_exp_year, cvc } = stripeCards.masterCard16;

getIframeBody().find(`[data-testid=${testIds.cardNoInputTestId}]`).type(cardNo);
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();


cy.contains("Thanks for your order!").should("be.visible");
});

it("15 digit american express card", () => {
const { cardNo, card_exp_month, card_exp_year, cvc } = stripeCards.amexCard15;

getIframeBody().find(`[data-testid=${testIds.cardNoInputTestId}]`).type(cardNo);
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();


cy.contains("Thanks for your order!").should("be.visible");
});

it("14 digit diners club card", () => {
const { cardNo, card_exp_month, card_exp_year, cvc } = stripeCards.dinersClubCard14;

getIframeBody().find(`[data-testid=${testIds.cardNoInputTestId}]`).type(cardNo);
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();


cy.contains("Thanks for your order!").should("be.visible");
});

});
32 changes: 31 additions & 1 deletion cypress-tests/cypress/support/cards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,34 @@ export const stripeCards = {
card_exp_month:"13",
card_exp_year:"30",
},
}
visaCard19: {
cardNo: "4479667352342682672",
cardScheme: "Visa",
cvc: "123",
card_exp_month: "12",
card_exp_year: "30",
},
masterCard16: {
cardNo: "5555555555554444",
cardScheme: "MasterCard",
cvc: "123",
card_exp_month: "12",
card_exp_year: "30",
},
amexCard15: {
cardNo: "378282246310005",
cardScheme: "American Express",
cvc: "1234",
card_exp_month: "12",
card_exp_year: "30",
},
dinersClubCard14: {
cardNo: "36227206271667",
cardScheme: "Diners Club",
cvc: "123",
card_exp_month: "12",
card_exp_year: "30",
},

}

0 comments on commit f51614e

Please sign in to comment.