ci(cypressV2): update cypress v2 framework to accommodate hyperswitch v2 changes (#6493)

This commit is contained in:
Pa1NarK
2024-11-08 17:42:30 +05:30
committed by GitHub
parent d9ce42fd0c
commit 28e3c36693
9 changed files with 412 additions and 196 deletions

View File

@ -26,10 +26,9 @@
// cy.task can only be used in support files (spec files or commands file)
import {
getValueByKey,
isoTimeTomorrow,
} from "../e2e/configs/Payment/Utils.js";
import { nanoid } from "nanoid";
import { getValueByKey } from "../e2e/configs/Payment/Utils.js";
import { isoTimeTomorrow, validateEnv } from "../utils/RequestBodyUtils.js";
function logRequestId(xRequestId) {
if (xRequestId) {
@ -48,6 +47,9 @@ Cypress.Commands.add(
const base_url = globalState.get("baseUrl");
const url = `${base_url}/v2/organization`;
// Update request body
organizationCreateBody.organization_name += " " + nanoid();
cy.request({
method: "POST",
url: url,
@ -71,7 +73,7 @@ Cypress.Commands.add(
} else {
// to be updated
throw new Error(
`Organization create call failed with status ${response.status} and message ${response.body.message}`
`Organization create call failed with status ${response.status} and message: "${response.body.error.message}"`
);
}
});
@ -111,7 +113,7 @@ Cypress.Commands.add("organizationRetrieveCall", (globalState) => {
} else {
// to be updated
throw new Error(
`Organization retrieve call failed with status ${response.status} and message ${response.body.message}`
`Organization retrieve call failed with status ${response.status} and message: "${response.body.error.message}"`
);
}
});
@ -125,6 +127,9 @@ Cypress.Commands.add(
const organization_id = globalState.get("organizationId");
const url = `${base_url}/v2/organization/${organization_id}`;
// Update request body
organizationUpdateBody.organization_name += " " + nanoid();
cy.request({
method: "PUT",
url: url,
@ -152,7 +157,7 @@ Cypress.Commands.add(
} else {
// to be updated
throw new Error(
`Organization update call failed with status ${response.status} and message ${response.body.message}`
`Organization update call failed with status ${response.status} and message: "${response.body.error.message}"`
);
}
});
@ -166,6 +171,8 @@ Cypress.Commands.add(
// Define the necessary variables and constants
const api_key = globalState.get("adminApiKey");
const base_url = globalState.get("baseUrl");
const key_id_type = "publishable_key";
const key_id = validateEnv(base_url, key_id_type);
const organization_id = globalState.get("organizationId");
const url = `${base_url}/v2/merchant_accounts`;
@ -192,14 +199,9 @@ Cypress.Commands.add(
.and.to.include(`${merchant_name}_`)
.and.to.be.a("string").and.not.be.empty;
if (base_url.includes("sandbox") || base_url.includes("integ"))
expect(response.body)
.to.have.property("publishable_key")
.and.to.include("pk_snd").and.to.not.be.empty;
else if (base_url.includes("localhost"))
expect(response.body)
.to.have.property("publishable_key")
.and.to.include("pk_dev").and.to.not.be.empty;
expect(response.body)
.to.have.property(key_id_type)
.and.to.include(key_id).and.to.not.be.empty;
globalState.set("merchantId", response.body.id);
globalState.set("publishableKey", response.body.publishable_key);
@ -208,7 +210,7 @@ Cypress.Commands.add(
} else {
// to be updated
throw new Error(
`Merchant create call failed with status ${response.status} and message ${response.body.message}`
`Merchant create call failed with status ${response.status} and message: "${response.body.error.message}"`
);
}
});
@ -218,6 +220,8 @@ Cypress.Commands.add("merchantAccountRetrieveCall", (globalState) => {
// Define the necessary variables and constants
const api_key = globalState.get("adminApiKey");
const base_url = globalState.get("baseUrl");
const key_id_type = "publishable_key";
const key_id = validateEnv(base_url, key_id_type);
const merchant_id = globalState.get("merchantId");
const url = `${base_url}/v2/merchant_accounts/${merchant_id}`;
@ -236,14 +240,8 @@ Cypress.Commands.add("merchantAccountRetrieveCall", (globalState) => {
expect(response.body).to.have.property("id").and.to.be.a("string").and.not
.be.empty;
if (base_url.includes("sandbox") || base_url.includes("integ"))
expect(response.body)
.to.have.property("publishable_key")
.and.to.include("pk_snd").and.to.not.be.empty;
else
expect(response.body)
.to.have.property("publishable_key")
.and.to.include("pk_dev").and.to.not.be.empty;
expect(response.body).to.have.property(key_id_type).and.to.include(key_id)
.and.to.not.be.empty;
if (merchant_id === undefined || merchant_id === null) {
globalState.set("merchantId", response.body.id);
@ -253,7 +251,7 @@ Cypress.Commands.add("merchantAccountRetrieveCall", (globalState) => {
} else {
// to be updated
throw new Error(
`Merchant account retrieve call failed with status ${response.status} and message ${response.body.message}`
`Merchant account retrieve call failed with status ${response.status} and message: "${response.body.error.message}"`
);
}
});
@ -264,6 +262,8 @@ Cypress.Commands.add(
// Define the necessary variables and constants
const api_key = globalState.get("adminApiKey");
const base_url = globalState.get("baseUrl");
const key_id_type = "publishable_key";
const key_id = validateEnv(base_url, key_id_type);
const merchant_id = globalState.get("merchantId");
const url = `${base_url}/v2/merchant_accounts/${merchant_id}`;
@ -284,14 +284,10 @@ Cypress.Commands.add(
if (response.status === 200) {
expect(response.body.id).to.equal(merchant_id);
if (base_url.includes("sandbox") || base_url.includes("integ"))
expect(response.body)
.to.have.property("publishable_key")
.and.to.include("pk_snd").and.to.not.be.empty;
else
expect(response.body)
.to.have.property("publishable_key")
.and.to.include("pk_dev").and.to.not.be.empty;
expect(response.body)
.to.have.property(key_id_type)
.and.to.include(key_id).and.to.not.be.empty;
expect(response.body.merchant_name).to.equal(merchant_name);
if (merchant_id === undefined || merchant_id === null) {
@ -302,7 +298,7 @@ Cypress.Commands.add(
} else {
// to be updated
throw new Error(
`Merchant account update call failed with status ${response.status} and message ${response.body.message}`
`Merchant account update call failed with status ${response.status} and message: "${response.body.error.message}"`
);
}
});
@ -349,7 +345,7 @@ Cypress.Commands.add(
} else {
// to be updated
throw new Error(
`Business profile create call failed with status ${response.status} and message ${response.body.message}`
`Business profile create call failed with status ${response.status} and message: "${response.body.error.message}"`
);
}
});
@ -390,7 +386,7 @@ Cypress.Commands.add("businessProfileRetrieveCall", (globalState) => {
} else {
// to be updated
throw new Error(
`Business profile retrieve call failed with status ${response.status} and message ${response.body.message}`
`Business profile retrieve call failed with status ${response.status} and message: "${response.body.error.message}"`
);
}
});
@ -436,7 +432,7 @@ Cypress.Commands.add(
} else {
// to be updated
throw new Error(
`Business profile update call failed with status ${response.status} and message ${response.body.message}`
`Business profile update call failed with status ${response.status} and message: "${response.body.error.message}"`
);
}
});
@ -494,8 +490,8 @@ Cypress.Commands.add(
authDetails.connector_account_details;
if (authDetails && authDetails.metadata) {
createConnectorBody.metadata = {
...createConnectorBody.metadata, // Preserve existing metadata fields
mcaCreateBody.metadata = {
...mcaCreateBody.metadata, // Preserve existing metadata fields
...authDetails.metadata, // Merge with authDetails.metadata
};
}
@ -525,7 +521,7 @@ Cypress.Commands.add(
} else {
// to be updated
throw new Error(
`Merchant connector account create call failed with status ${response.status} and message ${response.body.message}`
`Merchant connector account create call failed with status ${response.status} and message: "${response.body.error.message}"`
);
}
});
@ -573,7 +569,7 @@ Cypress.Commands.add("mcaRetrieveCall", (globalState) => {
} else {
// to be updated
throw new Error(
`Merchant connector account retrieve call failed with status ${response.status} and message ${response.body.message}`
`Merchant connector account retrieve call failed with status ${response.status} and message: "${response.body.error.message}"`
);
}
});
@ -638,7 +634,7 @@ Cypress.Commands.add(
} else {
// to be updated
throw new Error(
`Merchant connector account update call failed with status ${response.status} and message ${response.body.message}`
`Merchant connector account update call failed with status ${response.status} and message: "${response.body.error.message}"`
);
}
});
@ -654,6 +650,8 @@ Cypress.Commands.add("apiKeyCreateCall", (apiKeyCreateBody, globalState) => {
// We do not want to keep API Key forever,
// so we set the expiry to tomorrow as new merchant accounts are created with every run
const expiry = isoTimeTomorrow();
const key_id_type = "key_id";
const key_id = validateEnv(base_url, key_id_type);
const merchant_id = globalState.get("merchantId");
const url = `${base_url}/v2/api_keys`;
@ -682,13 +680,8 @@ Cypress.Commands.add("apiKeyCreateCall", (apiKeyCreateBody, globalState) => {
expect(response.body.description).to.equal(apiKeyCreateBody.description);
// API Key assertions are intentionally excluded to avoid being exposed in the logs
if (base_url.includes("sandbox") || base_url.includes("integ")) {
expect(response.body).to.have.property("key_id").and.to.include("snd_")
.and.to.not.be.empty;
} else if (base_url.includes("localhost")) {
expect(response.body).to.have.property("key_id").and.to.include("dev_")
.and.to.not.be.empty;
}
expect(response.body).to.have.property(key_id_type).and.to.include(key_id)
.and.to.not.be.empty;
globalState.set("apiKeyId", response.body.key_id);
globalState.set("apiKey", response.body.api_key);
@ -697,7 +690,7 @@ Cypress.Commands.add("apiKeyCreateCall", (apiKeyCreateBody, globalState) => {
} else {
// to be updated
throw new Error(
`API Key create call failed with status ${response.status} and message ${response.body.message}`
`API Key create call failed with status ${response.status} and message: "${response.body.error.message}"`
);
}
});
@ -706,6 +699,8 @@ Cypress.Commands.add("apiKeyRetrieveCall", (globalState) => {
// Define the necessary variables and constant
const api_key = globalState.get("adminApiKey");
const base_url = globalState.get("baseUrl");
const key_id_type = "key_id";
const key_id = validateEnv(base_url, key_id_type);
const merchant_id = globalState.get("merchantId");
const api_key_id = globalState.get("apiKeyId");
const url = `${base_url}/v2/api_keys/${api_key_id}`;
@ -728,15 +723,9 @@ Cypress.Commands.add("apiKeyRetrieveCall", (globalState) => {
if (response.status === 200) {
expect(response.body.merchant_id).to.equal(merchant_id);
// API Key assertions are intentionally excluded to avoid being exposed in the logs
if (base_url.includes("sandbox") || base_url.includes("integ")) {
expect(response.body).to.have.property("key_id").and.to.include("snd_")
.and.to.not.be.empty;
} else if (base_url.includes("localhost")) {
expect(response.body).to.have.property("key_id").and.to.include("dev_")
.and.to.not.be.empty;
}
expect(response.body).to.have.property(key_id_type).and.to.include(key_id)
.and.to.not.be.empty;
if (api_key === undefined || api_key === null) {
globalState.set("apiKey", response.body.api_key);
@ -745,7 +734,7 @@ Cypress.Commands.add("apiKeyRetrieveCall", (globalState) => {
} else {
// to be updated
throw new Error(
`API Key retrieve call failed with status ${response.status} and message ${response.body.message}`
`API Key retrieve call failed with status ${response.status} and message: "${response.body.error.message}"`
);
}
});
@ -758,6 +747,8 @@ Cypress.Commands.add("apiKeyUpdateCall", (apiKeyUpdateBody, globalState) => {
// We do not want to keep API Key forever,
// so we set the expiry to tomorrow as new merchant accounts are created with every run
const expiry = isoTimeTomorrow();
const key_id_type = "key_id";
const key_id = validateEnv(base_url, key_id_type);
const merchant_id = globalState.get("merchantId");
const url = `${base_url}/v2/api_keys/${api_key_id}`;
@ -786,13 +777,8 @@ Cypress.Commands.add("apiKeyUpdateCall", (apiKeyUpdateBody, globalState) => {
expect(response.body.description).to.equal(apiKeyUpdateBody.description);
// API Key assertions are intentionally excluded to avoid being exposed in the logs
if (base_url.includes("sandbox") || base_url.includes("integ")) {
expect(response.body).to.have.property("key_id").and.to.include("snd_")
.and.to.not.be.empty;
} else if (base_url.includes("localhost")) {
expect(response.body).to.have.property("key_id").and.to.include("dev_")
.and.to.not.be.empty;
}
expect(response.body).to.have.property(key_id_type).and.to.include(key_id)
.and.to.not.be.empty;
if (api_key === undefined || api_key === null) {
globalState.set("apiKey", response.body.api_key);
@ -801,7 +787,7 @@ Cypress.Commands.add("apiKeyUpdateCall", (apiKeyUpdateBody, globalState) => {
} else {
// to be updated
throw new Error(
`API Key update call failed with status ${response.status} and message ${response.body.message}`
`API Key update call failed with status ${response.status} and message: "${response.body.error.message}"`
);
}
});
@ -847,7 +833,7 @@ Cypress.Commands.add(
} else {
// to be updated
throw new Error(
`Routing algorithm setup call failed with status ${response.status} and message ${response.body.message}`
`Routing algorithm setup call failed with status ${response.status} and message: "${response.body.error.message}"`
);
}
});
@ -886,7 +872,7 @@ Cypress.Commands.add(
} else {
// to be updated
throw new Error(
`Routing algorithm activation call failed with status ${response.status} and message ${response.body.message}`
`Routing algorithm activation call failed with status ${response.status} and message: "${response.body.error.message}"`
);
}
});
@ -925,7 +911,7 @@ Cypress.Commands.add("routingActivationRetrieveCall", (globalState) => {
} else {
// to be updated
throw new Error(
`Routing algorithm activation retrieve call failed with status ${response.status} and message ${response.body.message}`
`Routing algorithm activation retrieve call failed with status ${response.status} and message: "${response.body.error.message}"`
);
}
});
@ -960,7 +946,7 @@ Cypress.Commands.add("routingDeactivateCall", (globalState) => {
} else {
// to be updated
throw new Error(
`Routing algorithm deactivation call failed with status ${response.status} and message ${response.body.message}`
`Routing algorithm deactivation call failed with status ${response.status} and message: "${response.body.error.message}"`
);
}
});
@ -997,7 +983,7 @@ Cypress.Commands.add("routingRetrieveCall", (globalState) => {
} else {
// to be updated
throw new Error(
`Routing algorithm activation retrieve call failed with status ${response.status} and message ${response.body.message}`
`Routing algorithm activation retrieve call failed with status ${response.status} and message: "${response.body.error.message}"`
);
}
});
@ -1016,7 +1002,7 @@ Cypress.Commands.add(
routingDefaultFallbackBody = payload;
cy.request({
method: "POST",
method: "PATCH",
url: url,
headers: {
Authorization: `Bearer ${api_key}`,
@ -1032,7 +1018,7 @@ Cypress.Commands.add(
} else {
// to be updated
throw new Error(
`Routing algorithm activation retrieve call failed with status ${response.status} and message ${response.body.message}`
`Routing algorithm activation retrieve call failed with status ${response.status} and message: "${response.body.error.message}"`
);
}
});
@ -1061,7 +1047,7 @@ Cypress.Commands.add("routingFallbackRetrieveCall", (globalState) => {
} else {
// to be updated
throw new Error(
`Routing algorithm activation retrieve call failed with status ${response.status} and message ${response.body.message}`
`Routing algorithm activation retrieve call failed with status ${response.status} and message: "${response.body.error.message}"`
);
}
});
@ -1100,7 +1086,7 @@ Cypress.Commands.add("userLogin", (globalState) => {
} else {
// to be updated
throw new Error(
`User login call failed to get totp token with status ${response.status} and message ${response.body.message}`
`User login call failed to get totp token with status ${response.status} and message: "${response.body.error.message}"`
);
}
});
@ -1133,7 +1119,7 @@ Cypress.Commands.add("terminate2Fa", (globalState) => {
} else {
// to be updated
throw new Error(
`2FA terminate call failed with status ${response.status} and message ${response.body.message}`
`2FA terminate call failed with status ${response.status} and message: "${response.body.error.message}"`
);
}
});
@ -1166,7 +1152,7 @@ Cypress.Commands.add("userInfo", (globalState) => {
} else {
// to be updated
throw new Error(
`User login call failed to fetch user info with status ${response.status} and message ${response.body.message}`
`User login call failed to fetch user info with status ${response.status} and message: "${response.body.error.message}"`
);
}
});
@ -1177,6 +1163,8 @@ Cypress.Commands.add("merchantAccountsListCall", (globalState) => {
// Define the necessary variables and constants
const api_key = globalState.get("adminApiKey");
const base_url = globalState.get("baseUrl");
const key_id_type = "publishable_key";
const key_id = validateEnv(base_url, key_id_type);
const organization_id = globalState.get("organizationId");
const url = `${base_url}/v2/organization/${organization_id}/merchant_accounts`;
@ -1198,21 +1186,15 @@ Cypress.Commands.add("merchantAccountsListCall", (globalState) => {
expect(response.body[key])
.to.have.property("organization_id")
.and.to.equal(organization_id);
if (base_url.includes("integ") || base_url.includes("sandbox")) {
expect(response.body[key])
.to.have.property("publishable_key")
.and.include("pk_snd_").and.to.not.be.empty;
} else if (base_url.includes("localhost")) {
expect(response.body[key])
.to.have.property("publishable_key")
.and.include("pk_dev_").and.to.not.be.empty;
}
expect(response.body[key])
.to.have.property(key_id_type)
.and.include(key_id).and.to.not.be.empty;
expect(response.body[key]).to.have.property("id").and.to.not.be.empty;
}
} else {
// to be updated
throw new Error(
`Merchant accounts list call failed with status ${response.status} and message ${response.body.message}`
`Merchant accounts list call failed with status ${response.status} and message: "${response.body.error.message}"`
);
}
});
@ -1253,7 +1235,7 @@ Cypress.Commands.add("businessProfilesListCall", (globalState) => {
} else {
// to be updated
throw new Error(
`Business profiles list call failed with status ${response.status} and message ${response.body.message}`
`Business profiles list call failed with status ${response.status} and message: "${response.body.error.message}"`
);
}
});
@ -1314,7 +1296,7 @@ Cypress.Commands.add("mcaListCall", (globalState, service_type) => {
} else {
// to be updated
throw new Error(
`Merchant connector account list call failed with status ${response.status} and message ${response.body.message}`
`Merchant connector account list call failed with status ${response.status} and message: "${response.body.error.message}"`
);
}
});
@ -1323,6 +1305,8 @@ Cypress.Commands.add("apiKeysListCall", (globalState) => {
// Define the necessary variables and constants
const api_key = globalState.get("adminApiKey");
const base_url = globalState.get("baseUrl");
const key_id_type = "key_id";
const key_id = validateEnv(base_url, key_id_type);
const merchant_id = globalState.get("merchantId");
const url = `${base_url}/v2/api_keys/list`;
@ -1347,8 +1331,8 @@ Cypress.Commands.add("apiKeysListCall", (globalState) => {
expect(response.body).to.be.an("array").and.to.not.be.empty;
for (const key in response.body) {
expect(response.body[key])
.to.have.property("key_id")
.and.to.include("dev_").and.to.not.be.empty;
.to.have.property(key_id_type)
.and.to.include(key_id).and.to.not.be.empty;
expect(response.body[key])
.to.have.property("merchant_id")
.and.to.equal(merchant_id).and.to.not.be.empty;
@ -1356,13 +1340,74 @@ Cypress.Commands.add("apiKeysListCall", (globalState) => {
} else {
// to be updated
throw new Error(
`API Keys list call failed with status ${response.status} and message ${response.body.message}`
`API Keys list call failed with status ${response.status} and message: "${response.body.error.message}"`
);
}
});
});
// templates
// Payment API calls
// Update the below commands while following the conventions
// Below is an example of how the payment intent create call should look like (update the below command as per the need)
Cypress.Commands.add(
"paymentIntentCreateCall",
(
globalState,
paymentRequestBody,
paymentResponseBody
/* Add more variables based on the need*/
) => {
// Define the necessary variables and constants at the top
// Also construct the URL here
const api_key = globalState.get("apiKey");
const base_url = globalState.get("baseUrl");
const profile_id = globalState.get("profileId");
const url = `${base_url}/v2/payments/create-intent`;
// Update request body if needed
paymentRequestBody = {};
// Pass Custom Headers
const customHeaders = {
"x-profile-id": profile_id,
};
cy.request({
method: "POST",
url: url,
headers: {
"api-key": api_key,
"Content-Type": "application/json",
...customHeaders,
},
body: paymentRequestBody,
failOnStatusCode: false,
}).then((response) => {
// Logging x-request-id is mandatory
logRequestId(response.headers["x-request-id"]);
if (response.status === 200) {
// Update the assertions based on the need
expect(response.body).to.deep.equal(paymentResponseBody);
} else if (response.status === 400) {
// Add 4xx validations here
expect(response.body).to.deep.equal(paymentResponseBody);
} else if (response.status === 500) {
// Add 5xx validations here
expect(response.body).to.deep.equal(paymentResponseBody);
} else {
// If status code is other than the ones mentioned above, default should be thrown
throw new Error(
`Payment intent create call failed with status ${response.status} and message: "${response.body.error.message}"`
);
}
});
}
);
Cypress.Commands.add("paymentIntentConfirmCall", (globalState) => {});
Cypress.Commands.add("paymentIntentRetrieveCall", (globalState) => {});
// templates for future use
Cypress.Commands.add("", () => {
cy.request({}).then((response) => {});
});