Skip to content

Commit e677b13

Browse files
ci(cypress): verify if card fields are populated on updating card info (#7743)
Co-authored-by: likhinbopanna <[email protected]>
1 parent 2595a5c commit e677b13

File tree

3 files changed

+259
-0
lines changed

3 files changed

+259
-0
lines changed

cypress-tests/cypress/e2e/spec/Payment/00014-SaveCardFlow.cy.js

+86
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as fixtures from "../../../fixtures/imports";
22
import State from "../../../utils/State";
3+
import { generateRandomName } from "../../../utils/RequestBodyUtils";
34
import getConnectorDetails, * as utils from "../../configs/Payment/Utils";
45

56
let globalState;
@@ -652,4 +653,89 @@ describe("Card - SaveCard payment flow test", () => {
652653
});
653654
}
654655
);
656+
context(
657+
"Check if card fields are populated when saving card again after a metadata update",
658+
() => {
659+
let shouldContinue = true; // variable that will be used to skip tests if a previous test fails
660+
661+
beforeEach(function () {
662+
saveCardBody = Cypress._.cloneDeep(fixtures.saveCardConfirmBody);
663+
if (!shouldContinue) {
664+
this.skip();
665+
}
666+
});
667+
668+
it("customer-create-call-test", () => {
669+
cy.createCustomerCallTest(fixtures.customerCreateBody, globalState);
670+
});
671+
672+
it("create+confirm-payment-call-test", () => {
673+
const data = getConnectorDetails(globalState.get("connectorId"))[
674+
"card_pm"
675+
]["SaveCardUseNo3DSAutoCapture"];
676+
677+
cy.createConfirmPaymentTest(
678+
fixtures.createConfirmPaymentBody,
679+
data,
680+
"no_three_ds",
681+
"automatic",
682+
globalState
683+
);
684+
685+
if (shouldContinue)
686+
shouldContinue = utils.should_continue_further(data);
687+
});
688+
689+
it("retrieve-customerPM-call-test", () => {
690+
cy.listCustomerPMCallTest(globalState);
691+
});
692+
693+
it("create+confirm-payment-call-test", () => {
694+
const data = getConnectorDetails(globalState.get("connectorId"))[
695+
"card_pm"
696+
]["SaveCardUseNo3DSAutoCapture"];
697+
698+
// generates random name (first name and last name)
699+
const card_holder_name = generateRandomName();
700+
// Create a new configuration object 'newData' based on the original 'data'.
701+
// This uses the spread operator (...) to create copies at each level,
702+
// ensuring the original 'data' object remains unchanged (immutability).
703+
const newData = {
704+
// Copy all top-level properties from the original 'data'.
705+
...data,
706+
// Override the 'Request' object with a new one.
707+
Request: {
708+
// Copy all properties from the original 'data.Request'.
709+
...data.Request,
710+
// Override the 'payment_method_data' object within the Request.
711+
payment_method_data: {
712+
// Override the 'card' object within payment_method_data.
713+
card: {
714+
// Copy all properties from the original card details.
715+
...data.Request.payment_method_data.card,
716+
// Set the desired modifications for this specific test case.
717+
card_exp_year: "55", // Update expiry year.
718+
card_holder_name: card_holder_name, // Update card holder name.
719+
},
720+
},
721+
},
722+
};
723+
724+
cy.createConfirmPaymentTest(
725+
fixtures.createConfirmPaymentBody,
726+
newData,
727+
"no_three_ds",
728+
"automatic",
729+
globalState
730+
);
731+
732+
if (shouldContinue)
733+
shouldContinue = utils.should_continue_further(data);
734+
});
735+
736+
it("retrieve-customerPM-call-test", () => {
737+
cy.listCustomerPMCallTest(globalState);
738+
});
739+
}
740+
);
655741
});

cypress-tests/cypress/support/commands.js

+6
Original file line numberDiff line numberDiff line change
@@ -3142,6 +3142,7 @@ Cypress.Commands.add("listCustomerPMCallTest", (globalState, order = 0) => {
31423142
if (response.body.customer_payment_methods[order]?.payment_token) {
31433143
const paymentToken =
31443144
response.body.customer_payment_methods[order].payment_token;
3145+
const cardInfo = response.body.customer_payment_methods[order].card;
31453146
const paymentMethodId =
31463147
response.body.customer_payment_methods[order].payment_method_id;
31473148
const lastUsedAt =
@@ -3150,6 +3151,11 @@ Cypress.Commands.add("listCustomerPMCallTest", (globalState, order = 0) => {
31503151
globalState.set("paymentMethodId", paymentMethodId);
31513152
globalState.set("paymentToken", paymentToken);
31523153

3154+
if (cardInfo) {
3155+
expect(cardInfo.expiry_year, "expiry_year").to.not.be.null;
3156+
expect(cardInfo.card_holder_name, "card_holder_name").to.not.be.null;
3157+
}
3158+
31533159
// Validate last_used_at timestamp
31543160
expect(new Date(lastUsedAt).getTime(), "last_used_at").to.be.lessThan(
31553161
Date.now()

cypress-tests/cypress/utils/RequestBodyUtils.js

+167
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,170 @@ export function validateEnv(baseUrl, keyIdType) {
7474

7575
return prefix;
7676
}
77+
78+
/**
79+
* Generates a random-ish card holder name from predefined lists.
80+
* @returns {string} A randomly generated full name (e.g., "Jane Smith").
81+
*/
82+
export function generateRandomName() {
83+
const firstNames = [
84+
"Alex",
85+
"Jamie",
86+
"Taylor",
87+
"Morgan",
88+
"Casey",
89+
"Jordan",
90+
"Pat",
91+
"Sam",
92+
"Chris",
93+
"Dana",
94+
"Olivia",
95+
"Liam",
96+
"Emma",
97+
"Noah",
98+
"Ava",
99+
"William",
100+
"Sophia",
101+
"James",
102+
"Isabella",
103+
"Oliver",
104+
"Charlotte",
105+
"Benjamin",
106+
"Amelia",
107+
"Elijah",
108+
"Mia",
109+
"Lucas",
110+
"Harper",
111+
"Mason",
112+
"Evelyn",
113+
"Logan",
114+
"Abigail",
115+
"Alexander",
116+
"Emily",
117+
"Ethan",
118+
"Elizabeth",
119+
"Jacob",
120+
"Mila",
121+
"Michael",
122+
"Ella",
123+
"Daniel",
124+
"Avery",
125+
"Henry",
126+
"Sofia",
127+
"Jackson",
128+
"Camila",
129+
"Sebastian",
130+
"Aria",
131+
"Aiden",
132+
"Scarlett",
133+
"Matthew",
134+
"Victoria",
135+
"Samuel",
136+
"Madison",
137+
"David",
138+
"Luna",
139+
"Joseph",
140+
"Grace",
141+
"Carter",
142+
"Chloe",
143+
"Owen",
144+
"Penelope",
145+
"Wyatt",
146+
"Layla",
147+
"John",
148+
"Riley",
149+
"Jack",
150+
"Zoey",
151+
"Luke",
152+
"Nora",
153+
"Jayden",
154+
"Lily",
155+
];
156+
const lastNames = [
157+
"Smith",
158+
"Jones",
159+
"Williams",
160+
"Brown",
161+
"Davis",
162+
"Miller",
163+
"Wilson",
164+
"Moore",
165+
"Taylor",
166+
"Lee",
167+
"Dylan",
168+
"Eleanor",
169+
"Grayson",
170+
"Hannah",
171+
"Levi",
172+
"Lillian",
173+
"Isaac",
174+
"Addison",
175+
"Gabriel",
176+
"Aubrey",
177+
"Julian",
178+
"Ellie",
179+
"Mateo",
180+
"Stella",
181+
"Anthony",
182+
"Natalie",
183+
"Jaxon",
184+
"Zoe",
185+
"Lincoln",
186+
"Leah",
187+
"Joshua",
188+
"Hazel",
189+
"Christopher",
190+
"Violet",
191+
"Andrew",
192+
"Aurora",
193+
"Theodore",
194+
"Savannah",
195+
"Caleb",
196+
"Audrey",
197+
"Ryan",
198+
"Brooklyn",
199+
"Asher",
200+
"Bella",
201+
"Nathan",
202+
"Claire",
203+
"Thomas",
204+
"Skylar",
205+
"Leo",
206+
"Lucy",
207+
"Isaiah",
208+
"Paisley",
209+
"Charles",
210+
"Everly",
211+
"Josiah",
212+
"Anna",
213+
"Hudson",
214+
"Caroline",
215+
"Christian",
216+
"Nova",
217+
"Hunter",
218+
"Genesis",
219+
"Connor",
220+
"Emilia",
221+
"Eli",
222+
"Kennedy",
223+
"Ezra",
224+
"Samantha",
225+
"Aaron",
226+
"Maya",
227+
"Landon",
228+
"Willow",
229+
"Adrian",
230+
"Kinsley",
231+
"Jonathan",
232+
"Naomi",
233+
"Nolan",
234+
"Aaliyah",
235+
];
236+
237+
const randomFirstName =
238+
firstNames[Math.floor(Math.random() * firstNames.length)];
239+
const randomLastName =
240+
lastNames[Math.floor(Math.random() * lastNames.length)];
241+
242+
return `${randomFirstName} ${randomLastName}`;
243+
}

0 commit comments

Comments
 (0)