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
ci(cypress): Add test coverage for Surcharge DSL configuration (#12100)
HS-QUALIBOTed4f6a90bd9e
diff --git a/cypress-tests/cypress/e2e/configs/Routing/Commons.js b/cypress-tests/cypress/e2e/configs/Routing/Commons.jsindex 389d3b4085..def88729b0 100644--- a/cypress-tests/cypress/e2e/configs/Routing/Commons.js+++ b/cypress-tests/cypress/e2e/configs/Routing/Commons.js@@ -66,4 +66,75 @@ export const connectorDetails = {body: {},},},+ SurchargeDecisionManager: {+ Create: {+ Request: {+ name: "surcharge_config_rate",+ merchant_surcharge_configs: {},+ algorithm: {+ type: "rate",+ rate: 2.5,+ defaultSelection: {+ surcharge_type: "rate",+ rate: 2.5,+ },+ rules: [],+ },+ },+ Response: {+ status: 200,+ body: {+ name: "surcharge_config_rate",+ merchant_surcharge_configs: {},+ algorithm: {+ type: "rate",+ rate: 2.5,+ defaultSelection: {+ surcharge_type: "rate",+ rate: 2.5,+ },+ rules: [],+ },+ },+ },+ },+ Retrieve: {+ Request: {},+ Response: {+ status: 200,+ body: {+ name: "surcharge_config_rate",+ merchant_surcharge_configs: {},+ algorithm: {+ type: "rate",+ rate: 2.5,+ defaultSelection: {+ surcharge_type: "rate",+ rate: 2.5,+ },+ rules: [],+ },+ },+ },+ },+ Delete: {+ Request: {},+ Response: {+ status: 200,+ body: {+ name: "surcharge_config_rate",+ merchant_surcharge_configs: {},+ algorithm: {+ type: "rate",+ rate: 2.5,+ defaultSelection: {+ surcharge_type: "rate",+ rate: 2.5,+ },+ rules: [],+ },+ },+ },+ },+ },};diff --git a/cypress-tests/cypress/e2e/spec/Routing/00005-SurchargeDSLConfiguration.cy.js b/cypress-tests/cypress/e2e/spec/Routing/00005-SurchargeDSLConfiguration.cy.jsnew file mode 100644index 0000000000..7764b77a57--- /dev/null+++ b/cypress-tests/cypress/e2e/spec/Routing/00005-SurchargeDSLConfiguration.cy.js@@ -0,0 +1,174 @@+import State from "../../../utils/State";+import * as utils from "../../configs/Routing/Utils";++let globalState;++describe("Surcharge DSL Configuration Test", () => {+ before("seed global state", () => {+ cy.task("getGlobalState").then((state) => {+ globalState = new State(state);+ });+ });++ afterEach("flush global state", () => {+ cy.task("setGlobalState", globalState.data);+ });++ context("Surcharge DSL with rate-based default selection", () => {+ it("create-surcharge-dsl-config-rate", () => {+ const data =+ utils.getConnectorDetails("common")["SurchargeDecisionManager"][+ "Create"+ ];+ const surchargeBody = {+ name: "surcharge_config_rate",+ merchant_surcharge_configs: {},+ algorithm: {+ type: "rate",+ rate: 2.5,+ defaultSelection: {+ surcharge_type: "rate",+ rate: 2.5,+ },+ rules: [],+ },+ };++ cy.createSurchargeDSLConfig(surchargeBody, data, globalState);+ });++ it("retrieve-surcharge-dsl-config", () => {+ const data =+ utils.getConnectorDetails("common")["SurchargeDecisionManager"][+ "Retrieve"+ ];++ cy.retrieveSurchargeDSLConfig(data, globalState);+ });++ it("delete-surcharge-dsl-config", () => {+ const data =+ utils.getConnectorDetails("common")["SurchargeDecisionManager"][+ "Delete"+ ];++ cy.deleteSurchargeDSLConfig(data, globalState);+ });++ it("verify-delete-by-retrieve-empty", () => {+ const data =+ utils.getConnectorDetails("common")["SurchargeDecisionManager"][+ "Retrieve"+ ];++ cy.retrieveSurchargeDSLConfig(data, globalState);+ });+ });++ context("Surcharge DSL with fixed amount default selection", () => {+ it("create-surcharge-dsl-config-fixed", () => {+ const data =+ utils.getConnectorDetails("common")["SurchargeDecisionManager"][+ "Create"+ ];+ const surchargeBody = {+ name: "surcharge_config_fixed",+ merchant_surcharge_configs: {},+ algorithm: {+ type: "fixed",+ amount: 100,+ defaultSelection: {+ surcharge_type: "fixed",+ amount: 100,+ },+ rules: [],+ },+ };++ cy.createSurchargeDSLConfig(surchargeBody, data, globalState);+ });++ it("retrieve-surcharge-dsl-config-fixed", () => {+ const data =+ utils.getConnectorDetails("common")["SurchargeDecisionManager"][+ "Retrieve"+ ];++ cy.retrieveSurchargeDSLConfig(data, globalState);+ });++ it("delete-surcharge-dsl-config-fixed", () => {+ const data =+ utils.getConnectorDetails("common")["SurchargeDecisionManager"][+ "Delete"+ ];++ cy.deleteSurchargeDSLConfig(data, globalState);+ });+ });++ context("Surcharge DSL with conditional rules", () => {+ it("create-surcharge-dsl-config-with-rules", () => {+ const data =+ utils.getConnectorDetails("common")["SurchargeDecisionManager"][+ "Create"+ ];+ const surchargeBody = {+ name: "surcharge_config_rules",+ merchant_surcharge_configs: {},+ algorithm: {+ type: "rate",+ rate: 2.5,+ defaultSelection: {+ surcharge_type: "rate",+ rate: 2.5,+ },+ rules: [+ {+ name: "card_surcharge_rule",+ surcharge_value: {+ surcharge_type: "rate",+ rate: 3.0,+ },+ statements: [+ {+ condition: [+ {+ lhs: "payment_method",+ comparison: "equal",+ value: {+ type: "enum_variant",+ value: "card",+ },+ metadata: {},+ },+ ],+ },+ ],+ },+ ],+ },+ };++ cy.createSurchargeDSLConfig(surchargeBody, data, globalState);+ });++ it("retrieve-surcharge-dsl-config-with-rules", () => {+ const data =+ utils.getConnectorDetails("common")["SurchargeDecisionManager"][+ "Retrieve"+ ];++ cy.retrieveSurchargeDSLConfig(data, globalState);+ });++ it("delete-surcharge-dsl-config-with-rules", () => {+ const data =+ utils.getConnectorDetails("common")["SurchargeDecisionManager"][+ "Delete"+ ];++ cy.deleteSurchargeDSLConfig(data, globalState);+ });+ });+});diff --git a/cypress-tests/cypress/support/commands.js b/cypress-tests/cypress/support/commands.jsindex b535875a0c..7a70defeb5 100644--- a/cypress-tests/cypress/support/commands.js+++ b/cypress-tests/cypress/support/commands.js@@ -5217,6 +5217,100 @@ Cypress.Commands.add("retrieveRoutingConfig", (data, globalState) => {});});+Cypress.Commands.add(+ "createSurchargeDSLConfig",+ (surchargeBody, data, globalState) => {+ const { Response: resData } = data || {};+ const profileId = globalState.get("profileId");++ if (surchargeBody && surchargeBody.program) {+ surchargeBody.program.profile_id = profileId;+ }++ cy.request({+ method: "PUT",+ url: `${globalState.get("baseUrl")}/routing/decision/surcharge`,+ headers: {+ "api-key": globalState.get("apiKey"),+ "Content-Type": "application/json",+ },+ body: surchargeBody,+ 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) {+ globalState.set("surchargeDSLConfig", response.body);+ 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 || {};++ cy.request({+ method: "GET",+ url: `${globalState.get("baseUrl")}/routing/decision/surcharge`,+ headers: {+ "api-key": globalState.get("apiKey"),+ "Content-Type": "application/json",+ },+ 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) {+ for (const key in resData.body) {+ expect(resData.body[key]).to.deep.equal(response.body[key]);+ }+ } else {+ defaultErrorHandler(response, resData);+ }+ });+ });+});++Cypress.Commands.add("deleteSurchargeDSLConfig", (data, globalState) => {+ const { Response: resData } = data || {};++ cy.request({+ method: "DELETE",+ url: `${globalState.get("baseUrl")}/routing/decision/surcharge`,+ headers: {+ "api-key": globalState.get("apiKey"),+ "Content-Type": "application/json",+ },+ 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) {+ for (const key in resData.body) {+ expect(resData.body[key]).to.deep.equal(response.body[key]);+ }+ } else {+ defaultErrorHandler(response, resData);+ }+ });+ });+});+Cypress.Commands.add("updateGsmConfig",(gsmBody, globalState, step_up_possible) => {