mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-02 04:04:43 +08:00
ci: add tests that make use of locker (#6735)
This commit is contained in:
@ -25,7 +25,11 @@
|
||||
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
|
||||
|
||||
// commands.js or your custom support file
|
||||
import { defaultErrorHandler, getValueByKey } from "../e2e/PaymentUtils/Utils";
|
||||
import {
|
||||
defaultErrorHandler,
|
||||
extractIntegerAtEnd,
|
||||
getValueByKey,
|
||||
} from "../e2e/PaymentUtils/Utils";
|
||||
import { execConfig, validateConfig } from "../utils/featureFlags";
|
||||
import * as RequestBodyUtils from "../utils/RequestBodyUtils";
|
||||
import { handleRedirection } from "./redirectionHandler";
|
||||
@ -197,15 +201,15 @@ Cypress.Commands.add(
|
||||
|
||||
Cypress.Commands.add(
|
||||
"createBusinessProfileTest",
|
||||
(createBusinessProfile, globalState, profile_prefix = "profile") => {
|
||||
const api_key = globalState.get("adminApiKey");
|
||||
const base_url = globalState.get("baseUrl");
|
||||
const connector_id = globalState.get("connectorId");
|
||||
const merchant_id = globalState.get("merchantId");
|
||||
const profile_name = `${connector_id}_${profile_prefix}_${Math.random().toString(36).substring(7)}`;
|
||||
const url = `${base_url}/account/${merchant_id}/business_profile`;
|
||||
(createBusinessProfile, globalState, profilePrefix = "profile") => {
|
||||
const apiKey = globalState.get("adminApiKey");
|
||||
const baseUrl = globalState.get("baseUrl");
|
||||
const connectorId = globalState.get("connectorId");
|
||||
const merchantId = globalState.get("merchantId");
|
||||
const profileName = `${profilePrefix}_${RequestBodyUtils.generateRandomString(connectorId)}`;
|
||||
const url = `${baseUrl}/account/${merchantId}/business_profile`;
|
||||
|
||||
createBusinessProfile.profile_name = profile_name;
|
||||
createBusinessProfile.profile_name = profileName;
|
||||
|
||||
cy.request({
|
||||
method: "POST",
|
||||
@ -213,13 +217,14 @@ Cypress.Commands.add(
|
||||
headers: {
|
||||
Accept: "application/json",
|
||||
"Content-Type": "application/json",
|
||||
"api-key": api_key,
|
||||
"api-key": apiKey,
|
||||
},
|
||||
body: createBusinessProfile,
|
||||
failOnStatusCode: false,
|
||||
}).then((response) => {
|
||||
logRequestId(response.headers["x-request-id"]);
|
||||
globalState.set(`${profile_prefix}Id`, response.body.profile_id);
|
||||
|
||||
globalState.set(`${profilePrefix}Id`, response.body.profile_id);
|
||||
|
||||
if (response.status === 200) {
|
||||
expect(response.body.profile_id).to.not.to.be.null;
|
||||
@ -235,35 +240,39 @@ Cypress.Commands.add(
|
||||
Cypress.Commands.add(
|
||||
"UpdateBusinessProfileTest",
|
||||
(
|
||||
updateBusinessProfile,
|
||||
updateBusinessProfileBody,
|
||||
is_connector_agnostic_mit_enabled,
|
||||
collect_billing_details_from_wallet_connector,
|
||||
collect_shipping_details_from_wallet_connector,
|
||||
always_collect_billing_details_from_wallet_connector,
|
||||
always_collect_shipping_details_from_wallet_connector,
|
||||
globalState
|
||||
globalState,
|
||||
profilePrefix = "profile"
|
||||
) => {
|
||||
updateBusinessProfile.is_connector_agnostic_mit_enabled =
|
||||
updateBusinessProfileBody.is_connector_agnostic_mit_enabled =
|
||||
is_connector_agnostic_mit_enabled;
|
||||
updateBusinessProfile.collect_shipping_details_from_wallet_connector =
|
||||
updateBusinessProfileBody.collect_shipping_details_from_wallet_connector =
|
||||
collect_shipping_details_from_wallet_connector;
|
||||
updateBusinessProfile.collect_billing_details_from_wallet_connector =
|
||||
updateBusinessProfileBody.collect_billing_details_from_wallet_connector =
|
||||
collect_billing_details_from_wallet_connector;
|
||||
updateBusinessProfile.always_collect_billing_details_from_wallet_connector =
|
||||
updateBusinessProfileBody.always_collect_billing_details_from_wallet_connector =
|
||||
always_collect_billing_details_from_wallet_connector;
|
||||
updateBusinessProfile.always_collect_shipping_details_from_wallet_connector =
|
||||
updateBusinessProfileBody.always_collect_shipping_details_from_wallet_connector =
|
||||
always_collect_shipping_details_from_wallet_connector;
|
||||
const merchant_id = globalState.get("merchantId");
|
||||
const profile_id = globalState.get("profileId");
|
||||
|
||||
const apiKey = globalState.get("adminApiKey");
|
||||
const merchantId = globalState.get("merchantId");
|
||||
const profileId = globalState.get(`${profilePrefix}Id`);
|
||||
|
||||
cy.request({
|
||||
method: "POST",
|
||||
url: `${globalState.get("baseUrl")}/account/${merchant_id}/business_profile/${profile_id}`,
|
||||
url: `${globalState.get("baseUrl")}/account/${merchantId}/business_profile/${profileId}`,
|
||||
headers: {
|
||||
Accept: "application/json",
|
||||
"Content-Type": "application/json",
|
||||
"api-key": globalState.get("adminApiKey"),
|
||||
"api-key": apiKey,
|
||||
},
|
||||
body: updateBusinessProfile,
|
||||
body: updateBusinessProfileBody,
|
||||
failOnStatusCode: false,
|
||||
}).then((response) => {
|
||||
logRequestId(response.headers["x-request-id"]);
|
||||
@ -433,7 +442,7 @@ Cypress.Commands.add(
|
||||
// it is best to use then() to handle the response within the same block of code
|
||||
cy.readFile(globalState.get("connectorAuthFilePath")).then(
|
||||
(jsonContent) => {
|
||||
const authDetails = getValueByKey(
|
||||
const { authDetails } = getValueByKey(
|
||||
JSON.stringify(jsonContent),
|
||||
connectorName
|
||||
);
|
||||
@ -481,14 +490,14 @@ Cypress.Commands.add(
|
||||
createConnectorBody,
|
||||
payment_methods_enabled,
|
||||
globalState,
|
||||
profile_prefix = "profile",
|
||||
mca_prefix = "merchantConnector"
|
||||
profilePrefix = "profile",
|
||||
mcaPrefix = "merchantConnector"
|
||||
) => {
|
||||
const api_key = globalState.get("adminApiKey");
|
||||
const base_url = globalState.get("baseUrl");
|
||||
const connector_id = globalState.get("connectorId");
|
||||
const merchant_id = globalState.get("merchantId");
|
||||
const profile_id = globalState.get(`${profile_prefix}Id`);
|
||||
const profile_id = globalState.get(`${profilePrefix}Id`);
|
||||
const url = `${base_url}/account/${merchant_id}/connectors`;
|
||||
|
||||
createConnectorBody.connector_type = connectorType;
|
||||
@ -500,11 +509,20 @@ Cypress.Commands.add(
|
||||
// it is best to use then() to handle the response within the same block of code
|
||||
cy.readFile(globalState.get("connectorAuthFilePath")).then(
|
||||
(jsonContent) => {
|
||||
const authDetails = getValueByKey(
|
||||
const { authDetails, stateUpdate } = getValueByKey(
|
||||
JSON.stringify(jsonContent),
|
||||
connector_id
|
||||
connector_id,
|
||||
extractIntegerAtEnd(profilePrefix)
|
||||
);
|
||||
|
||||
if (stateUpdate) {
|
||||
// cy.task("setGlobalState", stateUpdate);
|
||||
globalState.set(
|
||||
"MULTIPLE_CONNECTORS",
|
||||
stateUpdate.MULTIPLE_CONNECTORS
|
||||
);
|
||||
}
|
||||
|
||||
createConnectorBody.connector_account_details =
|
||||
authDetails.connector_account_details;
|
||||
|
||||
@ -533,7 +551,7 @@ Cypress.Commands.add(
|
||||
response.body.connector_name
|
||||
);
|
||||
globalState.set(
|
||||
`${mca_prefix}Id`,
|
||||
`${mcaPrefix}Id`,
|
||||
response.body.merchant_connector_id
|
||||
);
|
||||
} else {
|
||||
@ -566,7 +584,7 @@ Cypress.Commands.add(
|
||||
// it is best to use then() to handle the response within the same block of code
|
||||
cy.readFile(globalState.get("connectorAuthFilePath")).then(
|
||||
(jsonContent) => {
|
||||
const authDetails = getValueByKey(
|
||||
const { authDetails } = getValueByKey(
|
||||
JSON.stringify(jsonContent),
|
||||
`${connectorName}_payout`
|
||||
);
|
||||
@ -678,9 +696,11 @@ Cypress.Commands.add(
|
||||
const connector_id = globalState.get("connectorId");
|
||||
const merchant_id = globalState.get("merchantId");
|
||||
const merchant_connector_id = globalState.get("merchantConnectorId");
|
||||
const connectorLabel = `updated_${RequestBodyUtils.generateRandomString(connector_id)}`;
|
||||
const url = `${base_url}/account/${merchant_id}/connectors/${merchant_connector_id}`;
|
||||
|
||||
updateConnectorBody.connector_type = connectorType;
|
||||
updateConnectorBody.connector_label = connectorLabel;
|
||||
|
||||
cy.request({
|
||||
method: "POST",
|
||||
@ -700,7 +720,7 @@ Cypress.Commands.add(
|
||||
expect(response.body.merchant_connector_id).to.equal(
|
||||
merchant_connector_id
|
||||
);
|
||||
expect(response.body.connector_label).to.equal("updated_connector_label");
|
||||
expect(response.body.connector_label).to.equal(connectorLabel);
|
||||
});
|
||||
}
|
||||
);
|
||||
@ -1037,8 +1057,8 @@ Cypress.Commands.add(
|
||||
);
|
||||
}
|
||||
|
||||
const config_info = execConfig(validateConfig(configs));
|
||||
const profile_id = globalState.get(config_info.profile_id);
|
||||
const configInfo = execConfig(validateConfig(configs));
|
||||
const profile_id = globalState.get(`${configInfo.profilePrefix}Id`);
|
||||
|
||||
for (const key in reqData) {
|
||||
createPaymentBody[key] = reqData[key];
|
||||
@ -1245,14 +1265,18 @@ Cypress.Commands.add("createPaymentMethodTest", (globalState, data) => {
|
||||
});
|
||||
});
|
||||
|
||||
Cypress.Commands.add("deletePaymentMethodTest", (globalState, resData) => {
|
||||
const payment_method_id = globalState.get("paymentMethodId");
|
||||
Cypress.Commands.add("deletePaymentMethodTest", (globalState) => {
|
||||
const apiKey = globalState.get("apiKey");
|
||||
const baseUrl = globalState.get("baseUrl");
|
||||
const paymentMethodId = globalState.get("paymentMethodId");
|
||||
const url = `${baseUrl}/payment_methods/${paymentMethodId}`;
|
||||
|
||||
cy.request({
|
||||
method: "DELETE",
|
||||
url: `${globalState.get("baseUrl")}/payment_methods/${payment_method_id}`,
|
||||
url: url,
|
||||
headers: {
|
||||
Accept: "application/json",
|
||||
"api-key": globalState.get("apiKey"),
|
||||
"api-key": apiKey,
|
||||
},
|
||||
failOnStatusCode: false,
|
||||
}).then((response) => {
|
||||
@ -1260,10 +1284,16 @@ Cypress.Commands.add("deletePaymentMethodTest", (globalState, resData) => {
|
||||
expect(response.headers["content-type"]).to.include("application/json");
|
||||
|
||||
if (response.status === 200) {
|
||||
expect(response.body.payment_method_id).to.equal(payment_method_id);
|
||||
expect(response.body.payment_method_id).to.equal(paymentMethodId);
|
||||
expect(response.body.deleted).to.be.true;
|
||||
} else if (response.status === 500 && baseUrl.includes("localhost")) {
|
||||
// delete payment method api endpoint requires tartarus (hyperswitch card vault) to be set up since it makes a call to the locker service to delete the payment method
|
||||
expect(response.body.error.code).to.include("HE_00");
|
||||
expect(response.body.error.message).to.include("Something went wrong");
|
||||
} else {
|
||||
defaultErrorHandler(response, resData);
|
||||
throw new Error(
|
||||
`Payment Method Delete Call Failed with error message: ${response.body.error.message}`
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
@ -1271,6 +1301,7 @@ Cypress.Commands.add("deletePaymentMethodTest", (globalState, resData) => {
|
||||
Cypress.Commands.add("setDefaultPaymentMethodTest", (globalState) => {
|
||||
const payment_method_id = globalState.get("paymentMethodId");
|
||||
const customer_id = globalState.get("customerId");
|
||||
|
||||
cy.request({
|
||||
method: "POST",
|
||||
url: `${globalState.get("baseUrl")}/customers/${customer_id}/payment_methods/${payment_method_id}/default`,
|
||||
@ -1306,10 +1337,10 @@ Cypress.Commands.add(
|
||||
const baseUrl = globalState.get("baseUrl");
|
||||
const configInfo = execConfig(validateConfig(configs));
|
||||
const merchantConnectorId = globalState.get(
|
||||
configInfo.merchant_connector_id
|
||||
`${configInfo.merchantConnectorPrefix}Id`
|
||||
);
|
||||
const paymentIntentID = globalState.get("paymentID");
|
||||
const profileId = globalState.get(configInfo.profile_id);
|
||||
const profileId = globalState.get(`${configInfo.profilePrefix}Id`);
|
||||
const url = `${baseUrl}/payments/${paymentIntentID}/confirm`;
|
||||
|
||||
confirmBody.client_secret = globalState.get("clientSecret");
|
||||
@ -1424,10 +1455,10 @@ Cypress.Commands.add(
|
||||
Response: resData,
|
||||
} = data || {};
|
||||
|
||||
const config_info = execConfig(validateConfig(configs));
|
||||
const configInfo = execConfig(validateConfig(configs));
|
||||
const connectorId = globalState.get("connectorId");
|
||||
const paymentIntentId = globalState.get("paymentID");
|
||||
const profile_id = globalState.get(config_info.profile_id);
|
||||
const profile_id = globalState.get(`${configInfo.profilePrefix}Id`);
|
||||
|
||||
for (const key in reqData) {
|
||||
confirmBody[key] = reqData[key];
|
||||
@ -1532,9 +1563,9 @@ Cypress.Commands.add(
|
||||
Response: resData,
|
||||
} = data || {};
|
||||
|
||||
const config_info = execConfig(validateConfig(configs));
|
||||
const configInfo = execConfig(validateConfig(configs));
|
||||
const paymentIntentID = globalState.get("paymentID");
|
||||
const profile_id = globalState.get(config_info.profile_id);
|
||||
const profile_id = globalState.get(`${configInfo.profilePrefix}Id`);
|
||||
|
||||
for (const key in reqData) {
|
||||
confirmBody[key] = reqData[key];
|
||||
@ -1616,9 +1647,9 @@ Cypress.Commands.add(
|
||||
Response: resData,
|
||||
} = data || {};
|
||||
|
||||
const config_info = execConfig(validateConfig(configs));
|
||||
const configInfo = execConfig(validateConfig(configs));
|
||||
const paymentId = globalState.get("paymentID");
|
||||
const profile_id = globalState.get(config_info.profile_id);
|
||||
const profile_id = globalState.get(`${configInfo.profilePrefix}Id`);
|
||||
|
||||
for (const key in reqData) {
|
||||
confirmBody[key] = reqData[key];
|
||||
@ -1692,11 +1723,11 @@ Cypress.Commands.add(
|
||||
Response: resData,
|
||||
} = data || {};
|
||||
|
||||
const config_info = execConfig(validateConfig(configs));
|
||||
const configInfo = execConfig(validateConfig(configs));
|
||||
const merchant_connector_id = globalState.get(
|
||||
config_info.merchant_connector_id
|
||||
`${configInfo.merchantConnectorPrefix}Id`
|
||||
);
|
||||
const profile_id = globalState.get(config_info.profile_id);
|
||||
const profile_id = globalState.get(`${configInfo.profilePrefix}Id`);
|
||||
|
||||
createConfirmPaymentBody.authentication_type = authentication_type;
|
||||
createConfirmPaymentBody.capture_method = capture_method;
|
||||
@ -1811,12 +1842,12 @@ Cypress.Commands.add(
|
||||
Response: resData,
|
||||
} = data || {};
|
||||
|
||||
const config_info = execConfig(validateConfig(configs));
|
||||
const configInfo = execConfig(validateConfig(configs));
|
||||
const merchant_connector_id = globalState.get(
|
||||
config_info.merchant_connector_id
|
||||
`${configInfo.merchantConnectorPrefix}Id`
|
||||
);
|
||||
const paymentIntentID = globalState.get("paymentID");
|
||||
const profile_id = globalState.get(config_info.profile_id);
|
||||
const profile_id = globalState.get(`${configInfo.profilePrefix}Id`);
|
||||
|
||||
if (reqData.setup_future_usage === "on_session") {
|
||||
saveCardConfirmBody.card_cvc = reqData.payment_method_data.card.card_cvc;
|
||||
@ -1920,9 +1951,9 @@ Cypress.Commands.add(
|
||||
(requestBody, data, amount_to_capture, globalState) => {
|
||||
const { Configs: configs = {}, Response: resData } = data || {};
|
||||
|
||||
const config_info = execConfig(validateConfig(configs));
|
||||
const configInfo = execConfig(validateConfig(configs));
|
||||
const payment_id = globalState.get("paymentID");
|
||||
const profile_id = globalState.get(config_info.profile_id);
|
||||
const profile_id = globalState.get(`${configInfo.profilePrefix}Id`);
|
||||
|
||||
requestBody.amount_to_capture = amount_to_capture;
|
||||
requestBody.profile_id = profile_id;
|
||||
@ -1955,9 +1986,9 @@ Cypress.Commands.add(
|
||||
Cypress.Commands.add("voidCallTest", (requestBody, data, globalState) => {
|
||||
const { Configs: configs = {}, Response: resData } = data || {};
|
||||
|
||||
const config_info = execConfig(validateConfig(configs));
|
||||
const configInfo = execConfig(validateConfig(configs));
|
||||
const payment_id = globalState.get("paymentID");
|
||||
const profile_id = globalState.get(config_info.profile_id);
|
||||
const profile_id = globalState.get(`${configInfo.profilePrefix}Id`);
|
||||
|
||||
requestBody.profile_id = profile_id;
|
||||
|
||||
@ -1989,9 +2020,9 @@ Cypress.Commands.add(
|
||||
(globalState, data, autoretries = false, attempt = 1) => {
|
||||
const { Configs: configs = {} } = data || {};
|
||||
|
||||
const config_info = execConfig(validateConfig(configs));
|
||||
const configInfo = execConfig(validateConfig(configs));
|
||||
const merchant_connector_id = globalState.get(
|
||||
config_info.merchant_connector_id
|
||||
`${configInfo.merchantConnectorPrefix}Id`
|
||||
);
|
||||
const payment_id = globalState.get("paymentID");
|
||||
|
||||
@ -2138,10 +2169,10 @@ Cypress.Commands.add(
|
||||
Response: resData,
|
||||
} = data || {};
|
||||
|
||||
const config_info = execConfig(validateConfig(configs));
|
||||
const profile_id = globalState.get(config_info.profile_id);
|
||||
const configInfo = execConfig(validateConfig(configs));
|
||||
const profile_id = globalState.get(`${configInfo.profilePrefix}Id`);
|
||||
const merchant_connector_id = globalState.get(
|
||||
config_info.merchant_connector_id
|
||||
`${configInfo.merchantConnectorPrefix}Id`
|
||||
);
|
||||
|
||||
for (const key in reqData) {
|
||||
@ -2261,15 +2292,15 @@ Cypress.Commands.add(
|
||||
Request: reqData,
|
||||
Response: resData,
|
||||
} = data || {};
|
||||
const config_info = execConfig(validateConfig(configs));
|
||||
const profile_id = globalState.get(config_info.profile_id);
|
||||
const configInfo = execConfig(validateConfig(configs));
|
||||
const profile_id = globalState.get(`${configInfo.profilePrefix}Id`);
|
||||
|
||||
for (const key in reqData) {
|
||||
requestBody[key] = reqData[key];
|
||||
}
|
||||
|
||||
const merchant_connector_id = globalState.get(
|
||||
config_info.merchant_connector_id
|
||||
`${configInfo.merchantConnectorPrefix}Id`
|
||||
);
|
||||
|
||||
requestBody.amount = amount;
|
||||
@ -2375,34 +2406,54 @@ Cypress.Commands.add(
|
||||
Response: resData,
|
||||
} = data || {};
|
||||
|
||||
const configInfo = execConfig(validateConfig(configs));
|
||||
const profileId = globalState.get(`${configInfo.profilePrefix}Id`);
|
||||
|
||||
const apiKey = globalState.get("apiKey");
|
||||
const baseUrl = globalState.get("baseUrl");
|
||||
const customerId = globalState.get("customerId");
|
||||
const paymentMethodId = globalState.get("paymentMethodId");
|
||||
const url = `${baseUrl}/payments`;
|
||||
|
||||
for (const key in reqData) {
|
||||
requestBody[key] = reqData[key];
|
||||
}
|
||||
|
||||
const configInfo = execConfig(validateConfig(configs));
|
||||
const profileId = globalState.get(configInfo.profile_id);
|
||||
|
||||
requestBody.amount = amount;
|
||||
requestBody.capture_method = capture_method;
|
||||
requestBody.confirm = confirm;
|
||||
requestBody.customer_id = globalState.get("customerId");
|
||||
requestBody.customer_id = customerId;
|
||||
requestBody.profile_id = profileId;
|
||||
requestBody.recurring_details.data = globalState.get("paymentMethodId");
|
||||
requestBody.recurring_details.data = paymentMethodId;
|
||||
|
||||
cy.request({
|
||||
method: "POST",
|
||||
url: `${globalState.get("baseUrl")}/payments`,
|
||||
url: url,
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"api-key": globalState.get("apiKey"),
|
||||
"api-key": apiKey,
|
||||
},
|
||||
failOnStatusCode: false,
|
||||
body: requestBody,
|
||||
}).then((response) => {
|
||||
logRequestId(response.headers["x-request-id"]);
|
||||
expect(response.headers["content-type"]).to.include("application/json");
|
||||
|
||||
if (response.status === 200) {
|
||||
globalState.set("paymentID", response.body.payment_id);
|
||||
|
||||
expect(response.body.payment_method_id, "payment_method_id").to.include(
|
||||
"pm_"
|
||||
).and.to.not.be.null;
|
||||
expect(
|
||||
response.body.connector_transaction_id,
|
||||
"connector_transaction_id"
|
||||
).to.not.be.null;
|
||||
expect(
|
||||
response.body.payment_method_status,
|
||||
"payment_method_status"
|
||||
).to.equal("active");
|
||||
|
||||
if (response.body.capture_method === "automatic") {
|
||||
if (response.body.authentication_type === "three_ds") {
|
||||
expect(response.body)
|
||||
@ -2462,7 +2513,7 @@ Cypress.Commands.add(
|
||||
Response: resData,
|
||||
} = data || {};
|
||||
const configInfo = execConfig(validateConfig(configs));
|
||||
const profileId = globalState.get(configInfo.profile_id);
|
||||
const profileId = globalState.get(`${configInfo.profilePrefix}Id`);
|
||||
|
||||
for (const key in reqData) {
|
||||
requestBody[key] = reqData[key];
|
||||
@ -2710,6 +2761,7 @@ Cypress.Commands.add("listCustomerPMCallTest", (globalState) => {
|
||||
|
||||
Cypress.Commands.add("listCustomerPMByClientSecret", (globalState) => {
|
||||
const clientSecret = globalState.get("clientSecret");
|
||||
|
||||
cy.request({
|
||||
method: "GET",
|
||||
url: `${globalState.get("baseUrl")}/customers/payment_methods?client_secret=${clientSecret}`,
|
||||
|
||||
Reference in New Issue
Block a user