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

feat(Cypress): Add routing test (#4768)

Sakil Mostak39d46fd0156c
diff --git a/cypress-tests/cypress/e2e/RoutingTest/00000-AccountCreate.cy.js b/cypress-tests/cypress/e2e/RoutingTest/00000-AccountCreate.cy.js
new file mode 100644
index 0000000000..f58eb194db
--- /dev/null
+++ b/cypress-tests/cypress/e2e/RoutingTest/00000-AccountCreate.cy.js
@@ -0,0 +1,24 @@
+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);
+ console.log("seeding globalState -> " + JSON.stringify(globalState));
+ });
+ });
+ after("flush global state", () => {
+ console.log("flushing globalState -> " + JSON.stringify(globalState));
+ 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/00001-CustomerCreate.cy.js b/cypress-tests/cypress/e2e/RoutingTest/00001-CustomerCreate.cy.js
new file mode 100644
index 0000000000..996ec85ee3
--- /dev/null
+++ b/cypress-tests/cypress/e2e/RoutingTest/00001-CustomerCreate.cy.js
@@ -0,0 +1,20 @@
+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);
+ console.log("seeding globalState -> " + JSON.stringify(globalState));
+ });
+ });
+ after("flush global state", () => {
+ console.log("flushing globalState -> " + JSON.stringify(globalState));
+ 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
new file mode 100644
index 0000000000..a5acdc2465
--- /dev/null
+++ b/cypress-tests/cypress/e2e/RoutingTest/00002-ConnectorMultipleCreate.cy.js
@@ -0,0 +1,35 @@
+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);
+ console.log("seeding globalState -> " + JSON.stringify(globalState));
+ });
+ });
+
+ after("flush global state", () => {
+ console.log("flushing globalState -> " + JSON.stringify(globalState));
+ 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/RoutingTest/00003-PaymentRoutingTest.cy.js b/cypress-tests/cypress/e2e/RoutingTest/00003-PaymentRoutingTest.cy.js
new file mode 100644
index 0000000000..f176d1f82d
--- /dev/null
+++ b/cypress-tests/cypress/e2e/RoutingTest/00003-PaymentRoutingTest.cy.js
@@ -0,0 +1,106 @@
+import routingConfigBody from "../../fixtures/routing-config-body.json";
+import createConfirmPaymentBody from "../../fixtures/create-confirm-body.json";
+import State from "../../utils/State";
+import * as utils from "../RoutingUtils/utils";
+
+let globalState;
+
+describe("Routing Test", () => {
+ let should_continue = true; // variable that will be used to skip tests if a previous test fails
+
+ beforeEach(function () {
+ if (!should_continue) {
+ this.skip();
+ }
+ });
+
+ before("seed global state", () => {
+ cy.task("getGlobalState").then((state) => {
+ globalState = new State(state);
+ console.log("seeding globalState -> " + JSON.stringify(globalState));
+ cy.task(
+ "cli_log",
+ "SEEDING GLOBAL STATE -> " + JSON.stringify(globalState),
+ );
+ });
+ });
+
+ afterEach("flush global state", () => {
+ console.log("flushing globalState -> " + JSON.stringify(globalState));
+ cy.task("setGlobalState", globalState.data);
+ cy.task(
+ "cli_log",
+ " FLUSHING GLOBAL STATE -> " + JSON.stringify(globalState),
+ );
+ });
+
+ context("Routing with Stripe as top priority", () => {
+ it("add-routing-config", () => {
+ let data = utils.getConnectorDetails("stripe")["routing"];
+ 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");
+
+ let routing_data = [
+ {
+ connector: "stripe",
+ merchant_connector_id: `${stripe_merchant_connector_id}`,
+ },
+ {
+ connector: "adyen",
+ merchant_connector_id: `${adyen_merchant_connector_id}`,
+ },
+ ];
+ cy.addRoutingConfig(
+ routingConfigBody,
+ req_data,
+ res_data,
+ "priority",
+ routing_data,
+ globalState,
+ );
+ if (should_continue)
+ should_continue = utils.should_continue_further(res_data);
+ });
+
+ it("retrieve-routing-call-test", () => {
+ let data = utils.getConnectorDetails("stripe")["routing"];
+ let req_data = data["Request"];
+ let res_data = data["Response"];
+ cy.retrieveRoutingConfig(req_data, res_data, globalState);
+ if (should_continue)
+ should_continue = utils.should_continue_further(res_data);
+ });
+
+ it("activate-routing-call-test", () => {
+ let data = utils.getConnectorDetails("stripe")["routing"];
+ let req_data = data["Request"];
+ let res_data = data["Response"];
+ cy.activateRoutingConfig(req_data, res_data, globalState);
+ if (should_continue)
+ should_continue = utils.should_continue_further(res_data);
+ });
+
+ it("payment-routing-test", () => {
+ let data = utils.getConnectorDetails("stripe")["card_pm"]["Confirm"];
+ let req_data = data["Request"];
+ let res_data = data["Response"];
+ cy.createConfirmPaymentTest(
+ createConfirmPaymentBody,
+ req_data,
+ res_data,
+ "no_three_ds",
+ "automatic",
+ globalState,
+ );
+ if (should_continue)
+ should_continue = utils.should_continue_further(res_data);
+ });
+
+ it("retrieve-payment-call-test", () => {
+ cy.retrievePaymentCallTest(globalState);
+ });
+ });
+});
diff --git a/cypress-tests/cypress/e2e/RoutingUtils/Stripe.js b/cypress-tests/cypress/e2e/RoutingUtils/Stripe.js
new file mode 100644
index 0000000000..2f207cabe6
--- /dev/null
+++ b/cypress-tests/cypress/e2e/RoutingUtils/Stripe.js
@@ -0,0 +1,42 @@
+const card_data = {
+ card_number: "4242424242424242",
+ card_exp_month: "03",
+ card_exp_year: "30",
+ card_holder_name: "morino",
+ card_cvc: "737",
+};
+
+export const connectorDetails = {
+ routing: {
+ Request: {
+ name: "stripe config",
+ description: "some desc",
+ algorithm: {
+ type: "priority",
+ data: [],
+ },
+ profile_id: "{{profile_id}}",
+ },
+ Response: {
+ status: 200,
+ body: {},
+ },
+ },
+ card_pm: {
+ Confirm: {
+ Request: {
+ card: card_data,
+ currency: "USD",
+ customer_acceptance: null,
+ setup_future_usage: "on_session",
+ },
+ Response: {
+ status: 200,
+ body: {
+ status: "succeeded",
+ connector: "stripe",
+ },
+ },
+ },
+ },
+};
diff --git a/cypress-tests/cypress/e2e/RoutingUtils/utils.js b/cypress-tests/cypress/e2e/RoutingUtils/utils.js
new file mode 100644
index 0000000000..3933b7675d
--- /dev/null
+++ b/cypress-tests/cypress/e2e/RoutingUtils/utils.js
@@ -0,0 +1,33 @@
+import { connectorDetails as stripeConnectorDetails } from "./Stripe.js";
+
+const connectorDetails = {
+ stripe: stripeConnectorDetails,
+};
+
+export const getConnectorDetails = (connectorId) => {
+ let x = getValueByKey(connectorDetails, connectorId);
+ return x;
+};
+
+function getValueByKey(jsonObject, key) {
+ const data =
+ typeof jsonObject === "string" ? JSON.parse(jsonObject) : jsonObject;
+
+ if (data && typeof data === "object" && key in data) {
+ return data[key];
+ } else {
+ return null;
+ }
+}
+
+export const should_continue_further = (res_data) => {
+ if (
+ res_data.body.error !== undefined ||
+ res_data.body.error_code !== undefined ||
+ res_data.body.error_message !== undefined
+ ) {
+ return false;
+ } else {
+ return true;
+ }
+};
diff --git a/cypress-tests/cypress/fixtures/create-connector-body.json b/cypress-tests/cypress/fixtures/create-connector-body.json
index 0bfa7e4911..8f4b795c9e 100644
--- a/cypress-tests/cypress/fixtures/create-connector-body.json
+++ b/cypress-tests/cypress/fixtures/create-connector-body.json
@@ -3,7 +3,6 @@
"connector_name": "stripe",
"business_country": "US",
"business_label": "default",
- "connector_label": "first_stripe_connector",
"connector_account_details": {
"auth_type": "BodyKey",
"api_key": "api-key",
diff --git a/cypress-tests/cypress/fixtures/routing-config-body.json b/cypress-tests/cypress/fixtures/routing-config-body.json
new file mode 100644
index 0000000000..f0f1cbd9b9
--- /dev/null
+++ b/cypress-tests/cypress/fixtures/routing-config-body.json
@@ -0,0 +1,5 @@
+{
+ "name": "advanced config",
+ "description": "It is my ADVANCED config",
+ "algorithm": {}
+}
diff --git a/cypress-tests/cypress/support/commands.js b/cypress-tests/cypress/support/commands.js
index 59a2016686..15c2653244 100644
--- a/cypress-tests/cypress/support/commands.js
+++ b/cypress-tests/cypress/support/commands.js
@@ -63,6 +63,7 @@ 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);
});
},
@@ -174,6 +175,51 @@ 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;
@@ -1174,3 +1220,110 @@ Cypress.Commands.add("retrievePayoutCallTest", (globalState) => {
expect(response.body.amount).to.equal(globalState.get("payoutAmount"));
});
});
+
+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");
+ routingBody.algorithm.type = type;
+ routingBody.algorithm.data = data;
+
+ cy.request({
+ method: "POST",
+ url: `${globalState.get("baseUrl")}/routing`,
+ headers: {
+ "Content-Type": "application/json",
+ "api-key": globalState.get("apiKey"),
+ },
+ failOnStatusCode: false,
+ body: routingBody,
+ }).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("id");
+ globalState.set("routingConfigId", response.body.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(
+ "activateRoutingConfig",
+ (req_data, res_data, globalState) => {
+ let routing_config_id = globalState.get("routingConfigId");
+ cy.request({
+ method: "POST",
+ url: `${globalState.get("baseUrl")}/routing/${routing_config_id}/activate`,
+ headers: {
+ "Content-Type": "application/json",
+ "api-key": globalState.get("apiKey"),
+ },
+ failOnStatusCode: false,
+ }).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.id).to.equal(routing_config_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(
+ "retrieveRoutingConfig",
+ (req_data, res_data, globalState) => {
+ let routing_config_id = globalState.get("routingConfigId");
+ cy.request({
+ method: "GET",
+ url: `${globalState.get("baseUrl")}/routing/${routing_config_id}`,
+ headers: {
+ "Content-Type": "application/json",
+ "api-key": globalState.get("apiKey"),
+ },
+ failOnStatusCode: false,
+ }).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.id).to.equal(routing_config_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]);
+ }
+ }
+ });
+ },
+);
diff --git a/cypress-tests/package.json b/cypress-tests/package.json
index 4bb7e41534..63602d7230 100644
--- a/cypress-tests/package.json
+++ b/cypress-tests/package.json
@@ -8,7 +8,8 @@
"cypress-e2e": "npx cypress run --e2e",
"cypress:ci": "npx cypress run --headless",
"cypress:payments": "cypress run --spec 'cypress/e2e/PaymentTest/**/*'",
- "cypress:payouts": "cypress run --spec 'cypress/e2e/PayoutTest/**/*'"
+ "cypress:payouts": "cypress run --spec 'cypress/e2e/PayoutTest/**/*'",
+ "cypress:routing": "cypress run --spec 'cypress/e2e/RoutingTest/**/*'"
},
"author": "",
"license": "ISC",