Skip to content

Commit d773c58

Browse files
test: added cypress test for cybersource and trustpay (#1163)
Co-authored-by: ArushKapoorJuspay <121166031+ArushKapoorJuspay@users.noreply.github.com>
1 parent 565960c commit d773c58

2 files changed

Lines changed: 178 additions & 0 deletions

File tree

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import * as testIds from "../../../src/Utilities/TestUtils.bs";
2+
import { getClientURL } from "../support/utils";
3+
import { createPaymentBody } from "../support/utils";
4+
import { changeObjectKeyValue } from "../support/utils";
5+
import { cybersourceCards } from "cypress/support/cards";
6+
import { connectorEnum, connectorProfileIdMapping } from "../support/utils";
7+
8+
describe("Cybersource Card Payment flow test", () => {
9+
const publishableKey = Cypress.env("HYPERSWITCH_PUBLISHABLE_KEY");
10+
const secretKey = Cypress.env("HYPERSWITCH_SECRET_KEY");
11+
let getIframeBody: () => Cypress.Chainable<JQuery<HTMLBodyElement>>;
12+
let iframeSelector =
13+
"#orca-payment-element-iframeRef-orca-elements-payment-element-payment-element";
14+
15+
beforeEach(() => {
16+
getIframeBody = () => cy.iframe(iframeSelector);
17+
changeObjectKeyValue(
18+
createPaymentBody,
19+
"profile_id",
20+
connectorProfileIdMapping.get(connectorEnum.CYBERSOURCE),
21+
);
22+
});
23+
24+
it("should complete the card payment successfully (No 3DS)", () => {
25+
changeObjectKeyValue(
26+
createPaymentBody,
27+
"authentication_type",
28+
"no_three_ds",
29+
);
30+
changeObjectKeyValue(createPaymentBody, "customer_id", "new_customer_id");
31+
cy.createPaymentIntent(secretKey, createPaymentBody).then(() => {
32+
cy.getGlobalState("clientSecret").then((clientSecret) => {
33+
cy.visit(getClientURL(clientSecret, publishableKey));
34+
});
35+
});
36+
37+
const { cardNo, card_exp_month, card_exp_year, cvc } =
38+
cybersourceCards.successCard;
39+
40+
getIframeBody().find("[data-testid=cardNoInput]").type(cardNo);
41+
getIframeBody().find("[data-testid=expiryInput]").type(card_exp_month);
42+
getIframeBody().find("[data-testid=expiryInput]").type(card_exp_year);
43+
getIframeBody().find("[data-testid=cvvInput]").type(cvc);
44+
45+
getIframeBody().get("#submit").click();
46+
47+
cy.wait(3000);
48+
cy.contains("Thanks for your order!").should("be.visible");
49+
});
50+
51+
it("should fail with an invalid card number", () => {
52+
changeObjectKeyValue(
53+
createPaymentBody,
54+
"authentication_type",
55+
"no_three_ds",
56+
);
57+
cy.createPaymentIntent(secretKey, createPaymentBody).then(() => {
58+
cy.getGlobalState("clientSecret").then((clientSecret) => {
59+
cy.visit(getClientURL(clientSecret, publishableKey));
60+
});
61+
});
62+
63+
const { cardNo, card_exp_month, card_exp_year, cvc } =
64+
cybersourceCards.invalidCard;
65+
66+
getIframeBody().find("[data-testid=cardNoInput]").type(cardNo);
67+
getIframeBody().find("[data-testid=expiryInput]").type(card_exp_month);
68+
getIframeBody().find("[data-testid=expiryInput]").type(card_exp_year);
69+
getIframeBody().find("[data-testid=cvvInput]").type(cvc);
70+
71+
getIframeBody().get("#submit").click();
72+
73+
cy.wait(3000);
74+
cy.contains("Please enter valid details").should("be.visible");
75+
});
76+
});
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
import * as testIds from "../../../src/Utilities/TestUtils.bs";
2+
import { getClientURL } from "../support/utils";
3+
import { createPaymentBody } from "../support/utils";
4+
import { changeObjectKeyValue } from "../support/utils";
5+
import { trustpayCards } from "cypress/support/cards";
6+
import { connectorEnum, connectorProfileIdMapping } from "../support/utils";
7+
8+
describe("Trustpay Card Payment flow test", () => {
9+
const publishableKey = Cypress.env("HYPERSWITCH_PUBLISHABLE_KEY");
10+
const secretKey = Cypress.env("HYPERSWITCH_SECRET_KEY");
11+
let getIframeBody: () => Cypress.Chainable<JQuery<HTMLBodyElement>>;
12+
let iframeSelector =
13+
"#orca-payment-element-iframeRef-orca-elements-payment-element-payment-element";
14+
15+
beforeEach(() => {
16+
getIframeBody = () => cy.iframe(iframeSelector);
17+
changeObjectKeyValue(
18+
createPaymentBody,
19+
"profile_id",
20+
connectorProfileIdMapping.get(connectorEnum.TRUSTPAY),
21+
);
22+
});
23+
24+
it("should complete the card payment successfully (No 3DS)", () => {
25+
changeObjectKeyValue(
26+
createPaymentBody,
27+
"authentication_type",
28+
"no_three_ds",
29+
);
30+
changeObjectKeyValue(createPaymentBody, "customer_id", "new_customer_id");
31+
cy.createPaymentIntent(secretKey, createPaymentBody).then(() => {
32+
cy.getGlobalState("clientSecret").then((clientSecret) => {
33+
cy.visit(getClientURL(clientSecret, publishableKey));
34+
});
35+
});
36+
37+
const { cardNo, card_exp_month, card_exp_year, cvc } =
38+
trustpayCards.successCard;
39+
40+
getIframeBody().find("[data-testid=cardNoInput]").type(cardNo);
41+
getIframeBody().find("[data-testid=expiryInput]").type(card_exp_month);
42+
getIframeBody().find("[data-testid=expiryInput]").type(card_exp_year);
43+
getIframeBody().find("[data-testid=cvvInput]").type(cvc);
44+
45+
getIframeBody().get("#submit").click();
46+
47+
cy.wait(3000);
48+
cy.contains("Thanks for your order!").should("be.visible");
49+
});
50+
51+
it("should show the 3DS challenge page", () => {
52+
changeObjectKeyValue(createPaymentBody, "authentication_type", "three_ds");
53+
cy.createPaymentIntent(secretKey, createPaymentBody).then(() => {
54+
cy.getGlobalState("clientSecret").then((clientSecret) => {
55+
cy.visit(getClientURL(clientSecret, publishableKey));
56+
});
57+
});
58+
59+
const { cardNo, card_exp_month, card_exp_year, cvc } =
60+
trustpayCards.threeDSCard;
61+
62+
getIframeBody().find("[data-testid=cardNoInput]").type(cardNo);
63+
getIframeBody().find("[data-testid=expiryInput]").type(card_exp_month);
64+
getIframeBody().find("[data-testid=expiryInput]").type(card_exp_year);
65+
getIframeBody().find("[data-testid=cvvInput]").type(cvc);
66+
67+
getIframeBody().get("#submit").click();
68+
cy.wait(3000);
69+
70+
cy.get("body").then(($body) => {
71+
if ($body.find("#tp-iframe").length > 0) {
72+
cy.iframe("#tp-iframe").should("be.visible");
73+
}
74+
});
75+
});
76+
77+
it("should fail with an invalid card number", () => {
78+
changeObjectKeyValue(
79+
createPaymentBody,
80+
"authentication_type",
81+
"no_three_ds",
82+
);
83+
cy.createPaymentIntent(secretKey, createPaymentBody).then(() => {
84+
cy.getGlobalState("clientSecret").then((clientSecret) => {
85+
cy.visit(getClientURL(clientSecret, publishableKey));
86+
});
87+
});
88+
89+
const { cardNo, card_exp_month, card_exp_year, cvc } =
90+
trustpayCards.invalidCard;
91+
92+
getIframeBody().find("[data-testid=cardNoInput]").type(cardNo);
93+
getIframeBody().find("[data-testid=expiryInput]").type(card_exp_month);
94+
getIframeBody().find("[data-testid=expiryInput]").type(card_exp_year);
95+
getIframeBody().find("[data-testid=cvvInput]").type(cvc);
96+
97+
getIframeBody().get("#submit").click();
98+
99+
cy.wait(3000);
100+
cy.contains("Please enter valid details").should("be.visible");
101+
});
102+
});

0 commit comments

Comments
 (0)