mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-30 01:27:31 +08:00
ci(cypress): verify if card fields are populated on updating card info (#7743)
Co-authored-by: likhinbopanna <131246334+likhinbopanna@users.noreply.github.com>
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
import * as fixtures from "../../../fixtures/imports";
|
||||
import State from "../../../utils/State";
|
||||
import { generateRandomName } from "../../../utils/RequestBodyUtils";
|
||||
import getConnectorDetails, * as utils from "../../configs/Payment/Utils";
|
||||
|
||||
let globalState;
|
||||
@ -652,4 +653,89 @@ describe("Card - SaveCard payment flow test", () => {
|
||||
});
|
||||
}
|
||||
);
|
||||
context(
|
||||
"Check if card fields are populated when saving card again after a metadata update",
|
||||
() => {
|
||||
let shouldContinue = true; // variable that will be used to skip tests if a previous test fails
|
||||
|
||||
beforeEach(function () {
|
||||
saveCardBody = Cypress._.cloneDeep(fixtures.saveCardConfirmBody);
|
||||
if (!shouldContinue) {
|
||||
this.skip();
|
||||
}
|
||||
});
|
||||
|
||||
it("customer-create-call-test", () => {
|
||||
cy.createCustomerCallTest(fixtures.customerCreateBody, globalState);
|
||||
});
|
||||
|
||||
it("create+confirm-payment-call-test", () => {
|
||||
const data = getConnectorDetails(globalState.get("connectorId"))[
|
||||
"card_pm"
|
||||
]["SaveCardUseNo3DSAutoCapture"];
|
||||
|
||||
cy.createConfirmPaymentTest(
|
||||
fixtures.createConfirmPaymentBody,
|
||||
data,
|
||||
"no_three_ds",
|
||||
"automatic",
|
||||
globalState
|
||||
);
|
||||
|
||||
if (shouldContinue)
|
||||
shouldContinue = utils.should_continue_further(data);
|
||||
});
|
||||
|
||||
it("retrieve-customerPM-call-test", () => {
|
||||
cy.listCustomerPMCallTest(globalState);
|
||||
});
|
||||
|
||||
it("create+confirm-payment-call-test", () => {
|
||||
const data = getConnectorDetails(globalState.get("connectorId"))[
|
||||
"card_pm"
|
||||
]["SaveCardUseNo3DSAutoCapture"];
|
||||
|
||||
// generates random name (first name and last name)
|
||||
const card_holder_name = generateRandomName();
|
||||
// Create a new configuration object 'newData' based on the original 'data'.
|
||||
// This uses the spread operator (...) to create copies at each level,
|
||||
// ensuring the original 'data' object remains unchanged (immutability).
|
||||
const newData = {
|
||||
// Copy all top-level properties from the original 'data'.
|
||||
...data,
|
||||
// Override the 'Request' object with a new one.
|
||||
Request: {
|
||||
// Copy all properties from the original 'data.Request'.
|
||||
...data.Request,
|
||||
// Override the 'payment_method_data' object within the Request.
|
||||
payment_method_data: {
|
||||
// Override the 'card' object within payment_method_data.
|
||||
card: {
|
||||
// Copy all properties from the original card details.
|
||||
...data.Request.payment_method_data.card,
|
||||
// Set the desired modifications for this specific test case.
|
||||
card_exp_year: "55", // Update expiry year.
|
||||
card_holder_name: card_holder_name, // Update card holder name.
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
cy.createConfirmPaymentTest(
|
||||
fixtures.createConfirmPaymentBody,
|
||||
newData,
|
||||
"no_three_ds",
|
||||
"automatic",
|
||||
globalState
|
||||
);
|
||||
|
||||
if (shouldContinue)
|
||||
shouldContinue = utils.should_continue_further(data);
|
||||
});
|
||||
|
||||
it("retrieve-customerPM-call-test", () => {
|
||||
cy.listCustomerPMCallTest(globalState);
|
||||
});
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
@ -3142,6 +3142,7 @@ Cypress.Commands.add("listCustomerPMCallTest", (globalState, order = 0) => {
|
||||
if (response.body.customer_payment_methods[order]?.payment_token) {
|
||||
const paymentToken =
|
||||
response.body.customer_payment_methods[order].payment_token;
|
||||
const cardInfo = response.body.customer_payment_methods[order].card;
|
||||
const paymentMethodId =
|
||||
response.body.customer_payment_methods[order].payment_method_id;
|
||||
const lastUsedAt =
|
||||
@ -3150,6 +3151,11 @@ Cypress.Commands.add("listCustomerPMCallTest", (globalState, order = 0) => {
|
||||
globalState.set("paymentMethodId", paymentMethodId);
|
||||
globalState.set("paymentToken", paymentToken);
|
||||
|
||||
if (cardInfo) {
|
||||
expect(cardInfo.expiry_year, "expiry_year").to.not.be.null;
|
||||
expect(cardInfo.card_holder_name, "card_holder_name").to.not.be.null;
|
||||
}
|
||||
|
||||
// Validate last_used_at timestamp
|
||||
expect(new Date(lastUsedAt).getTime(), "last_used_at").to.be.lessThan(
|
||||
Date.now()
|
||||
|
||||
@ -74,3 +74,170 @@ export function validateEnv(baseUrl, keyIdType) {
|
||||
|
||||
return prefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a random-ish card holder name from predefined lists.
|
||||
* @returns {string} A randomly generated full name (e.g., "Jane Smith").
|
||||
*/
|
||||
export function generateRandomName() {
|
||||
const firstNames = [
|
||||
"Alex",
|
||||
"Jamie",
|
||||
"Taylor",
|
||||
"Morgan",
|
||||
"Casey",
|
||||
"Jordan",
|
||||
"Pat",
|
||||
"Sam",
|
||||
"Chris",
|
||||
"Dana",
|
||||
"Olivia",
|
||||
"Liam",
|
||||
"Emma",
|
||||
"Noah",
|
||||
"Ava",
|
||||
"William",
|
||||
"Sophia",
|
||||
"James",
|
||||
"Isabella",
|
||||
"Oliver",
|
||||
"Charlotte",
|
||||
"Benjamin",
|
||||
"Amelia",
|
||||
"Elijah",
|
||||
"Mia",
|
||||
"Lucas",
|
||||
"Harper",
|
||||
"Mason",
|
||||
"Evelyn",
|
||||
"Logan",
|
||||
"Abigail",
|
||||
"Alexander",
|
||||
"Emily",
|
||||
"Ethan",
|
||||
"Elizabeth",
|
||||
"Jacob",
|
||||
"Mila",
|
||||
"Michael",
|
||||
"Ella",
|
||||
"Daniel",
|
||||
"Avery",
|
||||
"Henry",
|
||||
"Sofia",
|
||||
"Jackson",
|
||||
"Camila",
|
||||
"Sebastian",
|
||||
"Aria",
|
||||
"Aiden",
|
||||
"Scarlett",
|
||||
"Matthew",
|
||||
"Victoria",
|
||||
"Samuel",
|
||||
"Madison",
|
||||
"David",
|
||||
"Luna",
|
||||
"Joseph",
|
||||
"Grace",
|
||||
"Carter",
|
||||
"Chloe",
|
||||
"Owen",
|
||||
"Penelope",
|
||||
"Wyatt",
|
||||
"Layla",
|
||||
"John",
|
||||
"Riley",
|
||||
"Jack",
|
||||
"Zoey",
|
||||
"Luke",
|
||||
"Nora",
|
||||
"Jayden",
|
||||
"Lily",
|
||||
];
|
||||
const lastNames = [
|
||||
"Smith",
|
||||
"Jones",
|
||||
"Williams",
|
||||
"Brown",
|
||||
"Davis",
|
||||
"Miller",
|
||||
"Wilson",
|
||||
"Moore",
|
||||
"Taylor",
|
||||
"Lee",
|
||||
"Dylan",
|
||||
"Eleanor",
|
||||
"Grayson",
|
||||
"Hannah",
|
||||
"Levi",
|
||||
"Lillian",
|
||||
"Isaac",
|
||||
"Addison",
|
||||
"Gabriel",
|
||||
"Aubrey",
|
||||
"Julian",
|
||||
"Ellie",
|
||||
"Mateo",
|
||||
"Stella",
|
||||
"Anthony",
|
||||
"Natalie",
|
||||
"Jaxon",
|
||||
"Zoe",
|
||||
"Lincoln",
|
||||
"Leah",
|
||||
"Joshua",
|
||||
"Hazel",
|
||||
"Christopher",
|
||||
"Violet",
|
||||
"Andrew",
|
||||
"Aurora",
|
||||
"Theodore",
|
||||
"Savannah",
|
||||
"Caleb",
|
||||
"Audrey",
|
||||
"Ryan",
|
||||
"Brooklyn",
|
||||
"Asher",
|
||||
"Bella",
|
||||
"Nathan",
|
||||
"Claire",
|
||||
"Thomas",
|
||||
"Skylar",
|
||||
"Leo",
|
||||
"Lucy",
|
||||
"Isaiah",
|
||||
"Paisley",
|
||||
"Charles",
|
||||
"Everly",
|
||||
"Josiah",
|
||||
"Anna",
|
||||
"Hudson",
|
||||
"Caroline",
|
||||
"Christian",
|
||||
"Nova",
|
||||
"Hunter",
|
||||
"Genesis",
|
||||
"Connor",
|
||||
"Emilia",
|
||||
"Eli",
|
||||
"Kennedy",
|
||||
"Ezra",
|
||||
"Samantha",
|
||||
"Aaron",
|
||||
"Maya",
|
||||
"Landon",
|
||||
"Willow",
|
||||
"Adrian",
|
||||
"Kinsley",
|
||||
"Jonathan",
|
||||
"Naomi",
|
||||
"Nolan",
|
||||
"Aaliyah",
|
||||
];
|
||||
|
||||
const randomFirstName =
|
||||
firstNames[Math.floor(Math.random() * firstNames.length)];
|
||||
const randomLastName =
|
||||
lastNames[Math.floor(Math.random() * lastNames.length)];
|
||||
|
||||
return `${randomFirstName} ${randomLastName}`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user