Skip to content

Commit

Permalink
refactor: addresed comments
Browse files Browse the repository at this point in the history
  • Loading branch information
preetamrevankar committed Nov 6, 2024
1 parent df18e2b commit c43ab40
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 94 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,12 @@ describe("Card payment flow test", () => {
let getIframeBody: () => Cypress.Chainable<JQuery<HTMLBodyElement>>;
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));
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
});

})
Expand All @@ -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');
});
});
});

Original file line number Diff line number Diff line change
Expand Up @@ -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));
});

})
Expand All @@ -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');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
});


});
32 changes: 0 additions & 32 deletions cypress-tests/cypress/support/cards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,8 @@ export type cardDetails = {

type connectorCard = {
successCard: cardDetails
failureCard: cardDetails
threeDSCard: cardDetails
invalidCard: cardDetails
invalidCVC : cardDetails
invalidMonth:cardDetails
invalidYear: cardDetails
}


Expand All @@ -27,41 +23,13 @@ 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",
cvc: "123",
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",
Expand Down

0 comments on commit c43ab40

Please sign in to comment.