Skip to content

Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation

fix(cypress): Add `jwt_token` and `cookie` for routing test (#4953)

Sakil Mostak0a86cdb50606
diff --git a/cypress-tests/cypress/e2e/RoutingTest/00000-AccountCreate.cy.js b/cypress-tests/cypress/e2e/RoutingTest/00000-AccountCreate.cy.js
deleted file mode 100644
index c1b62c883f..0000000000
--- a/cypress-tests/cypress/e2e/RoutingTest/00000-AccountCreate.cy.js
+++ /dev/null
@@ -1,22 +0,0 @@
-import apiKeyCreateBody from "../../fixtures/create-api-key-body.json";
-import merchantCreateBody from "../../fixtures/merchant-create-body.json";
-import State from "../../utils/State";
-
-let globalState;
-describe("Account Create flow test", () => {
- before("seed global state", () => {
- cy.task("getGlobalState").then((state) => {
- globalState = new State(state);
- });
- });
- after("flush global state", () => {
- cy.task("setGlobalState", globalState.data);
- });
-
- it("merchant-create-call-test", () => {
- cy.merchantCreateCallTest(merchantCreateBody, globalState);
- });
- it("api-key-create-call-test", () => {
- cy.apiKeyCreateTest(apiKeyCreateBody, globalState);
- });
-});
diff --git a/cypress-tests/cypress/e2e/RoutingTest/00003-PaymentRoutingTest.cy.js b/cypress-tests/cypress/e2e/RoutingTest/00000-PaymentRoutingTest.cy.js
similarity index 65%
rename from cypress-tests/cypress/e2e/RoutingTest/00003-PaymentRoutingTest.cy.js
rename to cypress-tests/cypress/e2e/RoutingTest/00000-PaymentRoutingTest.cy.js
index 0ac586640f..7d22791396 100644
--- a/cypress-tests/cypress/e2e/RoutingTest/00003-PaymentRoutingTest.cy.js
+++ b/cypress-tests/cypress/e2e/RoutingTest/00000-PaymentRoutingTest.cy.js
@@ -1,4 +1,6 @@
+import apiKeyCreateBody from "../../fixtures/create-api-key-body.json";
import createConfirmPaymentBody from "../../fixtures/create-confirm-body.json";
+import customerCreateBody from "../../fixtures/create-customer-body.json";
import routingConfigBody from "../../fixtures/routing-config-body.json";
import State from "../../utils/State";
import * as utils from "../RoutingUtils/utils";
@@ -17,6 +19,7 @@ describe("Routing Test", () => {
before("seed global state", () => {
cy.task("getGlobalState").then((state) => {
globalState = new State(state);
+
});
});
@@ -25,22 +28,41 @@ describe("Routing Test", () => {
});
context("Routing with Stripe as top priority", () => {
- it("add-routing-config", () => {
- let data = utils.getConnectorDetails("stripe")["routing"];
+ it("create-jwt-token", () => {
+ let data = utils.getConnectorDetails("common")["jwt"];
let req_data = data["Request"];
let res_data = data["Response"];
- let adyen_merchant_connector_id = globalState.get("adyen_mc_id");
- let stripe_merchant_connector_id = globalState.get("stripe_mc_id");
+ cy.createJWTToken(req_data, res_data, globalState);
+ if (should_continue)
+ should_continue = utils.should_continue_further(res_data);
+ });
+
+ it("retrieve-mca", () => {
+ cy.ListMCAbyMID(globalState);
+ });
+
+ it("api-key-create-call-test", () => {
+ cy.apiKeyCreateTest(apiKeyCreateBody, globalState);
+ });
+
+ it("customer-create-call-test", () => {
+ cy.createCustomerCallTest(customerCreateBody, globalState);
+ });
+
+ it("add-routing-config", () => {
+ let data = utils.getConnectorDetails("common")["routing"];
+ let req_data = data["Request"];
+ let res_data = data["Response"];
let routing_data = [
{
connector: "stripe",
- merchant_connector_id: `${stripe_merchant_connector_id}`,
+ merchant_connector_id: globalState.get("stripeMcaId"),
},
{
connector: "adyen",
- merchant_connector_id: `${adyen_merchant_connector_id}`,
+ merchant_connector_id: globalState.get("adyenMcaId"),
},
];
cy.addRoutingConfig(
@@ -49,14 +71,14 @@ describe("Routing Test", () => {
res_data,
"priority",
routing_data,
- globalState
+ globalState,
);
if (should_continue)
should_continue = utils.should_continue_further(res_data);
});
it("retrieve-routing-call-test", () => {
- let data = utils.getConnectorDetails("stripe")["routing"];
+ let data = utils.getConnectorDetails("common")["routing"];
let req_data = data["Request"];
let res_data = data["Response"];
cy.retrieveRoutingConfig(req_data, res_data, globalState);
@@ -65,7 +87,7 @@ describe("Routing Test", () => {
});
it("activate-routing-call-test", () => {
- let data = utils.getConnectorDetails("stripe")["routing"];
+ let data = utils.getConnectorDetails("common")["routing"];
let req_data = data["Request"];
let res_data = data["Response"];
cy.activateRoutingConfig(req_data, res_data, globalState);
@@ -74,7 +96,7 @@ describe("Routing Test", () => {
});
it("payment-routing-test", () => {
- let data = utils.getConnectorDetails("stripe")["card_pm"]["Confirm"];
+ let data = utils.getConnectorDetails("common")["card_pm"]["Confirm"];
let req_data = data["Request"];
let res_data = data["Response"];
cy.createConfirmPaymentTest(
@@ -83,7 +105,7 @@ describe("Routing Test", () => {
res_data,
"no_three_ds",
"automatic",
- globalState
+ globalState,
);
if (should_continue)
should_continue = utils.should_continue_further(res_data);
diff --git a/cypress-tests/cypress/e2e/RoutingTest/00001-CustomerCreate.cy.js b/cypress-tests/cypress/e2e/RoutingTest/00001-CustomerCreate.cy.js
deleted file mode 100644
index 584296bdae..0000000000
--- a/cypress-tests/cypress/e2e/RoutingTest/00001-CustomerCreate.cy.js
+++ /dev/null
@@ -1,18 +0,0 @@
-import customerCreateBody from "../../fixtures/create-customer-body.json";
-import State from "../../utils/State";
-
-let globalState;
-
-describe("Customer Create flow test", () => {
- before("seed global state", () => {
- cy.task("getGlobalState").then((state) => {
- globalState = new State(state);
- });
- });
- after("flush global state", () => {
- cy.task("setGlobalState", globalState.data);
- });
- it("customer-create-call-test", () => {
- cy.createCustomerCallTest(customerCreateBody, globalState);
- });
-});
diff --git a/cypress-tests/cypress/e2e/RoutingTest/00002-ConnectorMultipleCreate.cy.js b/cypress-tests/cypress/e2e/RoutingTest/00002-ConnectorMultipleCreate.cy.js
deleted file mode 100644
index feea07f39e..0000000000
--- a/cypress-tests/cypress/e2e/RoutingTest/00002-ConnectorMultipleCreate.cy.js
+++ /dev/null
@@ -1,33 +0,0 @@
-import createConnectorBody from "../../fixtures/create-connector-body.json";
-import State from "../../utils/State";
-
-let globalState;
-describe("Connector Account Create flow test", () => {
- before("seed global state", () => {
- cy.task("getGlobalState").then((state) => {
- globalState = new State(state);
- });
- });
-
- after("flush global state", () => {
- cy.task("setGlobalState", globalState.data);
- });
-
- it("adyen-connector-create-call-test", () => {
- cy.createConnectorWithNameCallTest(
- createConnectorBody,
- "adyen",
- "payment_processor",
- globalState
- );
- });
-
- it("stripe-connector-create-call-test", () => {
- cy.createConnectorWithNameCallTest(
- createConnectorBody,
- "stripe",
- "payment_processor",
- globalState
- );
- });
-});
diff --git a/cypress-tests/cypress/e2e/RoutingUtils/Stripe.js b/cypress-tests/cypress/e2e/RoutingUtils/Common.js
similarity index 89%
rename from cypress-tests/cypress/e2e/RoutingUtils/Stripe.js
rename to cypress-tests/cypress/e2e/RoutingUtils/Common.js
index 2f207cabe6..eda34969cf 100644
--- a/cypress-tests/cypress/e2e/RoutingUtils/Stripe.js
+++ b/cypress-tests/cypress/e2e/RoutingUtils/Common.js
@@ -22,6 +22,13 @@ export const connectorDetails = {
body: {},
},
},
+ jwt: {
+ Request: {},
+ Response: {
+ status: 200,
+ body: {},
+ },
+ },
card_pm: {
Confirm: {
Request: {
diff --git a/cypress-tests/cypress/e2e/RoutingUtils/utils.js b/cypress-tests/cypress/e2e/RoutingUtils/utils.js
index 3933b7675d..5b0c656796 100644
--- a/cypress-tests/cypress/e2e/RoutingUtils/utils.js
+++ b/cypress-tests/cypress/e2e/RoutingUtils/utils.js
@@ -1,7 +1,7 @@
-import { connectorDetails as stripeConnectorDetails } from "./Stripe.js";
+import { connectorDetails as commonConnectorDetails } from "./Common.js";
const connectorDetails = {
- stripe: stripeConnectorDetails,
+ common: commonConnectorDetails,
};
export const getConnectorDetails = (connectorId) => {
diff --git a/cypress-tests/cypress/support/commands.js b/cypress-tests/cypress/support/commands.js
index adbec2c25f..61a449c5f1 100644
--- a/cypress-tests/cypress/support/commands.js
+++ b/cypress-tests/cypress/support/commands.js
@@ -63,7 +63,6 @@ Cypress.Commands.add(
logRequestId(response.headers["x-request-id"]);
// Handle the response as needed
- globalState.set("profileID", response.body.default_profile);
globalState.set("publishableKey", response.body.publishable_key);
});
},
@@ -153,7 +152,7 @@ Cypress.Commands.add(
return false;
} else {
globalState.set("payoutsExecution", true);
- }
+ }
createConnectorBody.connector_account_details = authDetails;
cy.request({
@@ -185,51 +184,6 @@ Cypress.Commands.add(
},
);
-Cypress.Commands.add(
- "createConnectorWithNameCallTest",
- (createConnectorBody, connector_name, connector_type, globalState) => {
- const merchantId = globalState.get("merchantId");
- createConnectorBody.connector_name = connector_name;
- createConnectorBody.connector_type = connector_type;
- // readFile is used to read the contents of the file and it always returns a promise ([Object Object]) due to its asynchronous nature
- // 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(
- JSON.stringify(jsonContent),
- connector_name,
- );
- createConnectorBody.connector_account_details = authDetails;
- cy.request({
- method: "POST",
- url: `${globalState.get("baseUrl")}/account/${merchantId}/connectors`,
- headers: {
- "Content-Type": "application/json",
- Accept: "application/json",
- "api-key": globalState.get("adminApiKey"),
- },
- body: createConnectorBody,
- failOnStatusCode: false,
- }).then((response) => {
- logRequestId(response.headers["x-request-id"]);
-
- if (response.status === 200) {
- globalState.set(
- `${connector_name}_mc_id`,
- response.body.merchant_connector_id,
- );
- } else {
- cy.task(
- "cli_log",
- "response status -> " + JSON.stringify(response.status),
- );
- }
- });
- },
- );
- },
-);
-
function getValueByKey(jsonObject, key) {
const data =
typeof jsonObject === "string" ? JSON.parse(jsonObject) : jsonObject;
@@ -1231,13 +1185,81 @@ Cypress.Commands.add("retrievePayoutCallTest", (globalState) => {
});
});
+Cypress.Commands.add("createJWTToken", (req_data, res_data, globalState) => {
+ const jwt_body = {
+ email: `${globalState.get("email")}`,
+ password: `${globalState.get("password")}`,
+ };
+
+ cy.request({
+ method: "POST",
+ url: `${globalState.get("baseUrl")}/user/v2/signin`,
+ headers: {
+ "Content-Type": "application/json",
+ },
+ failOnStatusCode: false,
+ body: jwt_body,
+ }).then((response) => {
+ logRequestId(response.headers["x-request-id"]);
+
+ expect(res_data.status).to.equal(response.status);
+ expect(response.headers["content-type"]).to.include("application/json");
+
+ if (response.status === 200) {
+ expect(response.body).to.have.property("token");
+ //set jwt_token
+ globalState.set("jwtToken", response.body.token);
+
+ // set session cookie
+ const sessionCookie = response.headers["set-cookie"][0];
+ const sessionValue = sessionCookie.split(";")[0];
+ globalState.set("cookie", sessionValue);
+
+ // set api key
+ globalState.set("apiKey", globalState.get("routingApiKey"));
+ globalState.set("merchantId", response.body.merchant_id);
+
+ for (const key in res_data.body) {
+ expect(res_data.body[key]).to.equal(response.body[key]);
+ }
+ } else {
+ expect(response.body).to.have.property("error");
+ for (const key in res_data.body.error) {
+ expect(res_data.body.error[key]).to.equal(response.body.error[key]);
+ }
+ }
+ });
+});
+
+Cypress.Commands.add("ListMCAbyMID", (globalState) => {
+ const merchantId = globalState.get("merchantId");
+ cy.request({
+ method: "GET",
+ url: `${globalState.get("baseUrl")}/account/${merchantId}/connectors`,
+ headers: {
+ "Content-Type": "application/json",
+ "api-key": globalState.get("adminApiKey"),
+ },
+ failOnStatusCode: false,
+ }).then((response) => {
+ logRequestId(response.headers["x-request-id"]);
+
+ expect(response.headers["content-type"]).to.include("application/json");
+ globalState.set("profileId", response.body[0].profile_id);
+ globalState.set("stripeMcaId", response.body[0].merchant_connector_id);
+ globalState.set("adyenMcaId", response.body[1].merchant_connector_id);
+
+ });
+});
+
Cypress.Commands.add(
"addRoutingConfig",
(routingBody, req_data, res_data, type, data, globalState) => {
for (const key in req_data) {
routingBody[key] = req_data[key];
}
- routingBody.profile_id = globalState.get("profileID");
+ // set profile id from env
+ routingBody.profile_id = globalState.get("profileId");
routingBody.algorithm.type = type;
routingBody.algorithm.data = data;
@@ -1246,7 +1268,8 @@ Cypress.Commands.add(
url: `${globalState.get("baseUrl")}/routing`,
headers: {
"Content-Type": "application/json",
- "api-key": globalState.get("apiKey"),
+ Cookie: `${globalState.get("cookie")}`,
+ "api-key": `Bearer ${globalState.get("jwtToken")}`,
},
failOnStatusCode: false,
body: routingBody,
@@ -1281,6 +1304,7 @@ Cypress.Commands.add(
url: `${globalState.get("baseUrl")}/routing/${routing_config_id}/activate`,
headers: {
"Content-Type": "application/json",
+ Cookie: `${globalState.get("cookie")}`,
"api-key": globalState.get("apiKey"),
},
failOnStatusCode: false,
@@ -1314,6 +1338,7 @@ Cypress.Commands.add(
url: `${globalState.get("baseUrl")}/routing/${routing_config_id}`,
headers: {
"Content-Type": "application/json",
+ Cookie: `${globalState.get("cookie")}`,
"api-key": globalState.get("apiKey"),
},
failOnStatusCode: false,
diff --git a/cypress-tests/cypress/utils/State.js b/cypress-tests/cypress/utils/State.js
index b7b96dae5e..1f81703bdc 100644
--- a/cypress-tests/cypress/utils/State.js
+++ b/cypress-tests/cypress/utils/State.js
@@ -5,6 +5,8 @@ class State {
this.data["connectorId"] = Cypress.env("CONNECTOR");
this.data["baseUrl"] = Cypress.env("BASEURL");
this.data["adminApiKey"] = Cypress.env("ADMINAPIKEY");
+ this.data["email"] = Cypress.env("HS_EMAIL");
+ this.data["password"] = Cypress.env("HS_PASSWORD");
this.data["connectorAuthFilePath"] = Cypress.env(
"CONNECTOR_AUTH_FILE_PATH",
);
diff --git a/cypress-tests/package-lock.json b/cypress-tests/package-lock.json
index 10bda21a9b..41c069fea0 100644
--- a/cypress-tests/package-lock.json
+++ b/cypress-tests/package-lock.json
@@ -8,6 +8,9 @@
"name": "test",
"version": "1.0.0",
"license": "ISC",
+ "dependencies": {
+ "prettier": "^3.3.2"
+ },
"devDependencies": {
"cypress": "^13.10.0",
"jsqr": "^1.4.0"
@@ -1596,6 +1599,20 @@
"node": ">=0.10.0"
}
},
+ "node_modules/prettier": {
+ "version": "3.3.2",
+ "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.3.2.tgz",
+ "integrity": "sha512-rAVeHYMcv8ATV5d508CFdn+8/pHPpXeIid1DdrPwXnaAdH7cqjVbpJaT5eq4yRAFU/lsbwYwSF/n5iNrdJHPQA==",
+ "bin": {
+ "prettier": "bin/prettier.cjs"
+ },
+ "engines": {
+ "node": ">=14"
+ },
+ "funding": {
+ "url": "https://github.com/prettier/prettier?sponsor=1"
+ }
+ },
"node_modules/pretty-bytes": {
"version": "5.6.0",
"resolved": "https://registry.npmjs.org/pretty-bytes/-/pretty-bytes-5.6.0.tgz",
diff --git a/cypress-tests/package.json b/cypress-tests/package.json
index 63602d7230..b2693e9d1f 100644
--- a/cypress-tests/package.json
+++ b/cypress-tests/package.json
@@ -16,5 +16,8 @@
"devDependencies": {
"cypress": "^13.10.0",
"jsqr": "^1.4.0"
+ },
+ "dependencies": {
+ "prettier": "^3.3.2"
}
}
diff --git a/cypress-tests/readme.md b/cypress-tests/readme.md
index dccb66ed0e..db497bd331 100644
--- a/cypress-tests/readme.md
+++ b/cypress-tests/readme.md
@@ -159,7 +159,7 @@ Cypress.Commands.add("listMandateCallTest", (globalState) => {
} else {
cy.task(
"cli_log",
- "x-request-id is not available in the response headers"
+ "x-request-id is not available in the response headers",
);
}
expect(response.headers["content-type"]).to.include("application/json");