-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add automated Cypress test for card number input validation
- Loading branch information
1 parent
6484f18
commit ab51e8b
Showing
1 changed file
with
107 additions
and
0 deletions.
There are no files selected for viewing
107 changes: 107 additions & 0 deletions
107
cypress-tests/cypress/e2e/card-number-validation-test.cy.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
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("should complete the card payment successfully", () => { | ||
const { cardNo, card_exp_month, card_exp_year, cvc } = stripeCards.successCard; | ||
|
||
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); | ||
cy.contains("Thanks for your order!").should("be.visible"); | ||
}); | ||
|
||
it("should fail with an undetectable card brand", () => { | ||
const { card_exp_month, card_exp_year, cvc } = stripeCards.successCard; | ||
|
||
getIframeBody().find('[data-testid=cardNoInput]').type("111111"); | ||
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); | ||
|
||
getIframeBody().find('.Error.pt-1').should('be.visible') | ||
.and('contain.text', "Please enter a valid card number."); | ||
}); | ||
|
||
it("should fail with a detectable but invalid card number", () => { | ||
const { card_exp_month, card_exp_year, cvc } = stripeCards.successCard; | ||
|
||
getIframeBody().find('[data-testid=cardNoInput]').type("424242"); | ||
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); | ||
|
||
getIframeBody().find('.Error.pt-1').should('be.visible') | ||
.and('contain.text', "Card number is invalid."); | ||
}); | ||
|
||
it("should fail with an unsupported card brand (RuPay)", () => { | ||
const { card_exp_month, card_exp_year, cvc } = stripeCards.successCard; | ||
|
||
getIframeBody().find('[data-testid=cardNoInput]').type("6082015309577308"); | ||
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); | ||
|
||
getIframeBody().find('.Error.pt-1').should('be.visible') | ||
.and('contain.text', "RuPay is not supported at the moment."); | ||
}); | ||
|
||
it("should fail with an empty card number", () => { | ||
const { card_exp_month, card_exp_year, cvc } = stripeCards.successCard; | ||
|
||
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); | ||
|
||
getIframeBody().find('.Error.pt-1').should('be.visible') | ||
.and('contain.text', "Card Number cannot be empty"); | ||
}); | ||
|
||
}); |