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
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
test(cypress): add dynamic routing coverage for success-based and elimination routing (#12055)
HS-QUALIBOT5319725cf991
diff --git a/cypress-tests/cypress/e2e/configs/Routing/Commons.js b/cypress-tests/cypress/e2e/configs/Routing/Commons.jsindex def88729b0..b9ec5e4d5e 100644--- a/cypress-tests/cypress/e2e/configs/Routing/Commons.js+++ b/cypress-tests/cypress/e2e/configs/Routing/Commons.js@@ -66,6 +66,43 @@ export const connectorDetails = {body: {},},},+ dynamicRouting: {+ Request: {+ decision_engine_configs: {+ defaultBucketSize: 200,+ defaultHedgingPercent: 5,+ },+ },+ Response: {+ status: 200,+ body: {},+ },+ },+ deactivateRouting: {+ Request: {+ profile_id: "{{profile_id}}",+ algorithm_for: "payment",+ },+ Response: {+ status: 200,+ body: {},+ },+ },+ deactivateRoutingNegative: {+ Request: {+ profile_id: "{{profile_id}}",+ algorithm_for: "payment",+ },+ Response: {+ status: 400,+ body: {+ error: {+ message: "Algorithm is already inactive",+ code: "IR_16",+ },+ },+ },+ },SurchargeDecisionManager: {Create: {Request: {@@ -137,4 +174,20 @@ export const connectorDetails = {},},},+ deactivateDynamicRouting: {+ Request: {},+ Response: {+ status: 200,+ body: {},+ },+ },+ toggleRouting: {+ Request: {},+ Response: {+ status: 200,+ body: {+ kind: "dynamic",+ },+ },+ },};diff --git a/cypress-tests/cypress/e2e/spec/Routing/00005-DynamicRouting.cy.js b/cypress-tests/cypress/e2e/spec/Routing/00005-DynamicRouting.cy.jsnew file mode 100644index 0000000000..8fd1d76fa3--- /dev/null+++ b/cypress-tests/cypress/e2e/spec/Routing/00005-DynamicRouting.cy.js@@ -0,0 +1,164 @@+import * as fixtures from "../../../fixtures/imports";+import State from "../../../utils/State";+import * as utils from "../../configs/Routing/Utils";++let globalState;+let shouldContinue = true;++describe("Dynamic Routing Test", () => {+ context("Success-based dynamic routing with stripe as primary", () => {+ before("seed global state", () => {+ shouldContinue = true;+ cy.task("getGlobalState").then((state) => {+ globalState = new State(state);+ });+ });++ afterEach("flush global state", () => {+ cy.task("setGlobalState", globalState.data);+ });++ it("list-mca-by-mid", () => {+ cy.ListMcaByMid(globalState);+ });++ it("add-success-based-dynamic-routing-config", () => {+ const data = utils.getConnectorDetails("common")["dynamicRouting"];+ // Success-based dynamic routing uses decision_engine_configs, not connectors array+ cy.addDynamicRoutingConfig(+ fixtures.routingConfigBody,+ data,+ "success_based",+ null,+ globalState+ );+ if (shouldContinue) shouldContinue = utils.should_continue_further(data);+ });++ it("retrieve-routing-call-test", () => {+ if (!shouldContinue) return;+ const data = utils.getConnectorDetails("common")["dynamicRouting"];+ cy.retrieveRoutingConfig(data, globalState);+ if (shouldContinue) shouldContinue = utils.should_continue_further(data);+ });++ it("payment-routing-test", () => {+ if (!shouldContinue) return;+ globalState.set("connectorId", "stripe");+ globalState.set("merchantConnectorId", globalState.get("stripeMcaId"));+ const data =+ utils.getConnectorDetails("stripe")["card_pm"]["No3DSAutoCapture"];+ cy.createConfirmPaymentTest(+ fixtures.createConfirmPaymentBody,+ data,+ "no_three_ds",+ "automatic",+ globalState+ );+ });++ it("retrieve-payment-call-test", () => {+ cy.retrievePaymentCallTest({ globalState });+ });+ });++ context("Elimination dynamic routing with adyen as primary", () => {+ before("seed global state", () => {+ shouldContinue = true;+ cy.task("getGlobalState").then((state) => {+ globalState = new State(state);+ });+ });++ afterEach("flush global state", () => {+ cy.task("setGlobalState", globalState.data);+ });++ it("list-mca-by-mid", () => {+ cy.ListMcaByMid(globalState);+ });++ it("deactivate-previous-routing-config", () => {+ const data =+ utils.getConnectorDetails("common")["deactivateDynamicRouting"];+ cy.deactivateDynamicRoutingConfig("success_based", data, globalState);+ if (shouldContinue) shouldContinue = utils.should_continue_further(data);+ });++ it("add-elimination-dynamic-routing-config", () => {+ const data = utils.getConnectorDetails("common")["dynamicRouting"];+ // Elimination dynamic routing uses decision_engine_configs, not connectors array+ cy.addDynamicRoutingConfig(+ fixtures.routingConfigBody,+ data,+ "elimination",+ null,+ globalState+ );+ if (shouldContinue) shouldContinue = utils.should_continue_further(data);+ });++ it("retrieve-routing-call-test", () => {+ if (!shouldContinue) return;+ const data = utils.getConnectorDetails("common")["dynamicRouting"];+ cy.retrieveRoutingConfig(data, globalState);+ if (shouldContinue) shouldContinue = utils.should_continue_further(data);+ });++ it("payment-routing-test", () => {+ if (!shouldContinue) return;+ // Dynamic routing can route to either stripe or adyen+ // The connector field validation is handled in commands.js+ const data =+ utils.getConnectorDetails("adyen")["card_pm"]["No3DSAutoCapture"];+ cy.createConfirmPaymentDynamicRouting(+ fixtures.createConfirmPaymentBody,+ data,+ "no_three_ds",+ "automatic",+ globalState+ );+ });++ it("retrieve-payment-call-test", () => {+ cy.retrievePaymentDynamicRoutingTest({ globalState });+ });+ });++ context(+ "Success-based toggle endpoint (404 - endpoint not registered)",+ () => {+ before("seed global state", () => {+ cy.task("getGlobalState").then((state) => {+ globalState = new State(state);+ });+ });++ afterEach("flush global state", () => {+ cy.task("setGlobalState", globalState.data);+ });++ xit("toggle-success-based-dynamic-routing", () => {+ const data = utils.getConnectorDetails("common")["toggleRouting"];+ cy.toggleDynamicRoutingByType("success_based", data, globalState);+ });+ }+ );++ context("Elimination toggle endpoint (404 - endpoint not registered)", () => {+ before("seed global state", () => {+ cy.task("getGlobalState").then((state) => {+ globalState = new State(state);+ });+ });++ afterEach("flush global state", () => {+ cy.task("setGlobalState", globalState.data);+ });++ xit("toggle-elimination-dynamic-routing", () => {+ const data = utils.getConnectorDetails("common")["toggleRouting"];+ cy.toggleDynamicRoutingByType("elimination", data, globalState);+ });+ });+});diff --git a/cypress-tests/cypress/fixtures/create-confirm-body.json b/cypress-tests/cypress/fixtures/create-confirm-body.jsonindex 8d30e379ee..531ae94024 100644--- a/cypress-tests/cypress/fixtures/create-confirm-body.json+++ b/cypress-tests/cypress/fixtures/create-confirm-body.json@@ -25,11 +25,11 @@"payment_method_type": "debit","payment_method_data": {"card": {- "card_number": "4242424242424242",- "card_exp_month": "01",- "card_exp_year": "50",+ "card_number": "4111111111111111",+ "card_exp_month": "03",+ "card_exp_year": "30","card_holder_name": "joseph Doe",- "card_cvc": "123"+ "card_cvc": "737"}},"billing": {diff --git a/cypress-tests/cypress/support/commands.js b/cypress-tests/cypress/support/commands.jsindex ecfcee0382..c0c3673fbb 100644--- a/cypress-tests/cypress/support/commands.js+++ b/cypress-tests/cypress/support/commands.js@@ -5217,6 +5217,82 @@ Cypress.Commands.add("retrieveRoutingConfig", (data, globalState) => {});});+Cypress.Commands.add(+ "addDynamicRoutingConfig",+ (dynamicRoutingBody, data, routingType, routing_data, globalState) => {+ const { Request: reqData, Response: resData } = data || {};+ const merchantId = globalState.get("merchantId");+ const profileId = globalState.get("profileId");++ // Success-based dynamic routing uses decision_engine_configs+ // Volume-based routing uses algorithm_for and connectors+ const body = { ...dynamicRoutingBody, ...reqData };++ cy.request({+ method: "POST",+ url: `${globalState.get("baseUrl")}/account/${merchantId}/business_profile/${profileId}/dynamic_routing/${routingType}/create?enable=dynamic_connector_selection`,+ headers: {+ "api-key": globalState.get("apiKey"),+ "Content-Type": "application/json",+ },+ failOnStatusCode: false,+ body: body,+ }).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("id");+ globalState.set("routingConfigId", response.body.id);+ for (const key in resData.body) {+ expect(resData.body[key]).to.deep.equal(response.body[key]);+ }+ } else {+ defaultErrorHandler(response, resData);+ }+ });+ });+ }+);++Cypress.Commands.add(+ "deactivateDynamicRoutingConfig",+ (routingType, data, globalState) => {+ const { Response: resData } = data || {};+ const merchantId = globalState.get("merchantId");+ const profileId = globalState.get("profileId");++ const dynamicRoutingUrl = `${globalState.get("baseUrl")}/account/${merchantId}/business_profile/${profileId}/dynamic_routing/${routingType}/create?enable=none`;++ cy.request({+ method: "POST",+ url: dynamicRoutingUrl,+ headers: {+ "api-key": globalState.get("apiKey"),+ "Content-Type": "application/json",+ },+ failOnStatusCode: false,+ body: {},+ }).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) {+ for (const key in resData.body) {+ expect(resData.body[key]).to.deep.equal(response.body[key]);+ }+ } else {+ defaultErrorHandler(response, resData);+ }+ });+ });+ }+);+Cypress.Commands.add("createSurchargeDSLConfig",(surchargeBody, data, globalState) => {@@ -5255,6 +5331,38 @@ Cypress.Commands.add(});+Cypress.Commands.add("deactivateRoutingConfig", (data, globalState) => {+ const { Request: reqData, Response: resData } = data || {};++ const body = { ...reqData };+ body.profile_id = globalState.get("profileId");++ cy.request({+ method: "POST",+ url: `${globalState.get("baseUrl")}/routing/deactivate`,+ headers: {+ "api-key": globalState.get("apiKey"),+ "Content-Type": "application/json",+ },+ failOnStatusCode: false,+ body: body,+ }).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) {+ for (const key in resData.body) {+ expect(resData.body[key]).to.deep.equal(response.body[key]);+ }+ } else {+ defaultErrorHandler(response, resData);+ }+ });+ });+});+Cypress.Commands.add("retrieveSurchargeDSLConfig", (data, globalState) => {const { Response: resData } = data || {};@@ -7233,6 +7341,138 @@ Cypress.Commands.add(});+Cypress.Commands.add(+ "createConfirmPaymentDynamicRouting",+ (+ createConfirmPaymentBody,+ data,+ authentication_type,+ capture_method,+ globalState+ ) => {+ const { Request: reqData, Response: resData } = data || {};++ const profile_id = globalState.get("profileId");+ const customer_id = globalState.get("customerId");++ createConfirmPaymentBody.authentication_type = authentication_type;+ createConfirmPaymentBody.capture_method = capture_method;+ createConfirmPaymentBody.profile_id = profile_id;+ createConfirmPaymentBody.customer_id = customer_id;++ for (const key in reqData) {+ createConfirmPaymentBody[key] = reqData[key];+ }++ cy.request({+ method: "POST",+ url: `${globalState.get("baseUrl")}/payments`,+ headers: {+ "Content-Type": "application/json",+ "api-key": globalState.get("apiKey"),+ },+ failOnStatusCode: false,+ body: createConfirmPaymentBody,+ }).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) {+ globalState.set("paymentAmount", createConfirmPaymentBody.amount);+ globalState.set("paymentID", response.body.payment_id);+ globalState.set("clientSecret", response.body.client_secret);++ const routedConnector = response.body.connector;+ globalState.set("connectorId", routedConnector);++ if (routedConnector === "adyen") {+ globalState.set(+ "merchantConnectorId",+ globalState.get("adyenMcaId")+ );+ } else {+ globalState.set(+ "merchantConnectorId",+ globalState.get("stripeMcaId")+ );+ }++ for (const key in resData.body) {+ // Skip connector comparison for dynamic routing - either stripe or adyen is valid+ if (key === "connector") {+ expect(response.body[key]).to.be.oneOf(["adyen", "stripe"]);+ } else {+ expect(resData.body[key], [key]).to.deep.equal(+ response.body[key]+ );+ }+ }+ } else {+ defaultErrorHandler(response, resData);+ }+ });+ });+ }+);++Cypress.Commands.add("retrievePaymentDynamicRoutingTest", ({ globalState }) => {+ const payment_id = globalState.get("paymentID");++ cy.request({+ method: "GET",+ url: `${globalState.get("baseUrl")}/payments/${payment_id}?force_sync=true`,+ headers: {+ "Content-Type": "application/json",+ "api-key": globalState.get("apiKey"),+ },+ failOnStatusCode: false,+ }).then((response) => {+ logRequestId(response.headers["x-request-id"]);++ cy.wrap(response).then(() => {+ expect(response.status).to.equal(200);+ expect(response.body.payment_id).to.equal(payment_id);+ expect(response.body.connector).to.equal(globalState.get("connectorId"));+ });+ });+});++Cypress.Commands.add(+ "toggleDynamicRoutingByType",+ (routingType, data, globalState) => {+ const { Response: resData } = data || {};+ const merchantId = globalState.get("merchantId");+ const profileId = globalState.get("profileId");++ cy.request({+ method: "POST",+ url: `${globalState.get("baseUrl")}/account/${merchantId}/business_profile/${profileId}/dynamic_routing/${routingType}/toggle?enable=dynamic_connector_selection`,+ headers: {+ "api-key": globalState.get("apiKey"),+ "Content-Type": "application/json",+ },+ failOnStatusCode: false,+ body: {},+ }).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) {+ for (const key in resData.body) {+ expect(resData.body[key]).to.equal(response.body[key]);+ }+ } else {+ defaultErrorHandler(response, resData);+ }+ });+ });+ }+);+Cypress.Commands.add("blocklistToggle", (status, globalState) => {const apiKey = globalState.get("apiKey");const baseUrl = globalState.get("baseUrl");