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

test(cypress): add routing evaluate coverage (#12133)

HS-QUALIBOT5e50bf91cf62
diff --git a/cypress-tests/cypress/e2e/configs/Routing/Commons.js b/cypress-tests/cypress/e2e/configs/Routing/Commons.js
index b9ec5e4d5e..d624bb7dc4 100644
--- a/cypress-tests/cypress/e2e/configs/Routing/Commons.js
+++ b/cypress-tests/cypress/e2e/configs/Routing/Commons.js
@@ -174,6 +174,21 @@ export const connectorDetails = {
},
},
},
+ routingEvaluate: {
+ Request: {
+ name: "routing evaluate",
+ description: "routing evaluate test config",
+ algorithm: {
+ type: "advanced",
+ data: [],
+ },
+ profile_id: "{{profile_id}}",
+ },
+ Response: {
+ status: 200,
+ body: {},
+ },
+ },
deactivateDynamicRouting: {
Request: {},
Response: {
diff --git a/cypress-tests/cypress/e2e/spec/Routing/00005-RoutingEvaluate.cy.js b/cypress-tests/cypress/e2e/spec/Routing/00005-RoutingEvaluate.cy.js
new file mode 100644
index 0000000000..248d8a798a
--- /dev/null
+++ b/cypress-tests/cypress/e2e/spec/Routing/00005-RoutingEvaluate.cy.js
@@ -0,0 +1,193 @@
+import * as fixtures from "../../../fixtures/imports";
+import State from "../../../utils/State";
+import * as utils from "../../configs/Routing/Utils";
+
+let globalState;
+
+describe("Routing Evaluate Test", () => {
+ context("Evaluate routing: card payment method rule → stripe", () => {
+ before("seed global state", () => {
+ cy.task("getGlobalState").then((state) => {
+ globalState = new State(state);
+ });
+ });
+
+ afterEach("flush global state", () => {
+ cy.task("setGlobalState", globalState.data);
+ });
+
+ it("retrieve-mca", () => {
+ cy.ListMcaByMid(globalState);
+ });
+
+ it("add-routing-config", () => {
+ const data = utils.getConnectorDetails("common")["routingEvaluate"];
+ const routing_data = {
+ defaultSelection: {
+ type: "priority",
+ data: [],
+ },
+ metadata: {},
+ rules: [
+ {
+ name: "rule_card_to_stripe",
+ connectorSelection: {
+ type: "priority",
+ data: [
+ {
+ connector: "stripe",
+ merchant_connector_id: globalState.get("stripeMcaId"),
+ },
+ ],
+ },
+ statements: [
+ {
+ condition: [
+ {
+ lhs: "payment_method",
+ comparison: "equal",
+ value: { type: "enum_variant", value: "card" },
+ metadata: {},
+ },
+ ],
+ },
+ ],
+ },
+ ],
+ };
+
+ cy.addRoutingConfig(
+ fixtures.routingConfigBody,
+ data,
+ "advanced",
+ routing_data,
+ globalState
+ );
+ });
+
+ it("retrieve-routing-call-test", () => {
+ const data = utils.getConnectorDetails("common")["routingEvaluate"];
+ cy.retrieveRoutingConfig(data, globalState);
+ });
+
+ it("activate-routing-call-test", () => {
+ const data = utils.getConnectorDetails("common")["routingEvaluate"];
+ cy.activateRoutingConfig(data, globalState);
+ });
+
+ it("evaluate-routing-card-to-stripe", () => {
+ const data = utils.getConnectorDetails("common")["routingEvaluate"];
+
+ const evaluate_params = {
+ expectedConnector: "stripe",
+ parameters: {
+ payment_method: { type: "enum_variant", value: "card" },
+ amount: { type: "number", value: 100 },
+ currency: { type: "enum_variant", value: "USD" },
+ },
+ fallback_output: [
+ {
+ gateway_name: "stripe",
+ gateway_id: globalState.get("stripeMcaId"),
+ },
+ ],
+ };
+
+ cy.evaluateRoutingRule(data, evaluate_params, globalState);
+ });
+ });
+
+ context(
+ "Evaluate routing: currency-based rule (USD → stripe, default → adyen)",
+ () => {
+ before("seed global state", () => {
+ cy.task("getGlobalState").then((state) => {
+ globalState = new State(state);
+ });
+ });
+
+ afterEach("flush global state", () => {
+ cy.task("setGlobalState", globalState.data);
+ });
+
+ it("retrieve-mca", () => {
+ cy.ListMcaByMid(globalState);
+ });
+
+ it("add-currency-routing-config", () => {
+ const data = utils.getConnectorDetails("common")["routingEvaluate"];
+ const routing_data = {
+ defaultSelection: {
+ type: "priority",
+ data: [
+ {
+ connector: "adyen",
+ merchant_connector_id: globalState.get("adyenMcaId"),
+ },
+ ],
+ },
+ metadata: {},
+ rules: [
+ {
+ name: "rule_usd_to_stripe",
+ connectorSelection: {
+ type: "priority",
+ data: [
+ {
+ connector: "stripe",
+ merchant_connector_id: globalState.get("stripeMcaId"),
+ },
+ ],
+ },
+ statements: [
+ {
+ condition: [
+ {
+ lhs: "currency",
+ comparison: "equal",
+ value: { type: "enum_variant", value: "USD" },
+ metadata: {},
+ },
+ ],
+ },
+ ],
+ },
+ ],
+ };
+
+ cy.addRoutingConfig(
+ fixtures.routingConfigBody,
+ data,
+ "advanced",
+ routing_data,
+ globalState
+ );
+ });
+
+ it("retrieve-routing-call-test", () => {
+ const data = utils.getConnectorDetails("common")["routingEvaluate"];
+ cy.retrieveRoutingConfig(data, globalState);
+ });
+
+ it("activate-routing-call-test", () => {
+ const data = utils.getConnectorDetails("common")["routingEvaluate"];
+ cy.activateRoutingConfig(data, globalState);
+ });
+
+ it("evaluate-routing-usd-to-stripe", () => {
+ const data = utils.getConnectorDetails("common")["routingEvaluate"];
+
+ const evaluate_params = {
+ expectedConnector: "stripe",
+ parameters: {
+ currency: { type: "enum_variant", value: "USD" },
+ amount: { type: "number", value: 100 },
+ },
+ fallback_output: [],
+ };
+
+ cy.evaluateRoutingRule(data, evaluate_params, globalState);
+ });
+ }
+ );
+});
diff --git a/cypress-tests/cypress/support/commands.js b/cypress-tests/cypress/support/commands.js
index 7b40522e7b..12b1d1642f 100644
--- a/cypress-tests/cypress/support/commands.js
+++ b/cypress-tests/cypress/support/commands.js
@@ -5331,6 +5331,54 @@ Cypress.Commands.add(
}
);
+Cypress.Commands.add(
+ "evaluateRoutingRule",
+ (data, evaluate_params, globalState) => {
+ const { Response: resData } = data || {};
+ const profileId = globalState.get("profileId");
+ const expectedConnector = evaluate_params.expectedConnector;
+
+ cy.request({
+ method: "POST",
+ url: `${globalState.get("baseUrl")}/routing/rule/evaluate`,
+ headers: {
+ "api-key": globalState.get("apiKey"),
+ "Content-Type": "application/json",
+ },
+ body: {
+ created_by: profileId,
+ parameters: evaluate_params.parameters,
+ fallback_output: evaluate_params.fallback_output || [],
+ },
+ failOnStatusCode: false,
+ }).then((response) => {
+ logRequestId(response.headers["x-request-id"]);
+
+ cy.wrap(response).then(() => {
+ expect(response.headers["content-type"]).to.include("application/json");
+
+ if (response.status === 200) {
+ expect(response.body).to.have.property("status", "success");
+ expect(response.body).to.have.property("evaluated_output");
+ expect(response.body).to.have.property("eligible_connectors");
+ expect(response.body.evaluated_output).to.be.an("array");
+
+ if (expectedConnector) {
+ const connectors = response.body.evaluated_output.map(
+ (c) => c.connector
+ );
+ expect(connectors).to.include(expectedConnector);
+ }
+
+ globalState.set("routingEvaluateResult", response.body);
+ } else {
+ defaultErrorHandler(response, resData);
+ }
+ });
+ });
+ }
+);
+
Cypress.Commands.add("deactivateRoutingConfig", (data, globalState) => {
const { Request: reqData, Response: resData } = data || {};