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): repair Surcharge DSL Configuration routing spec (#13176)

HS-QUALIBOT064609bd95a0
diff --git a/cypress-tests/cypress/e2e/configs/Routing/Commons.js b/cypress-tests/cypress/e2e/configs/Routing/Commons.js
index 2ad0702915..50248c6f6d 100644
--- a/cypress-tests/cypress/e2e/configs/Routing/Commons.js
+++ b/cypress-tests/cypress/e2e/configs/Routing/Commons.js
@@ -181,28 +181,29 @@ export const connectorDetails = {
name: "surcharge_config_rate",
merchant_surcharge_configs: {},
algorithm: {
- type: "rate",
- rate: 2.5,
defaultSelection: {
- surcharge_type: "rate",
- rate: 2.5,
+ surcharge_details: {
+ surcharge: { type: "rate", value: { percentage: 2.5 } },
+ },
},
rules: [],
+ metadata: {},
},
},
Response: {
status: 200,
body: {
name: "surcharge_config_rate",
- merchant_surcharge_configs: {},
+ merchant_surcharge_configs: { show_surcharge_breakup_screen: null },
algorithm: {
- type: "rate",
- rate: 2.5,
defaultSelection: {
- surcharge_type: "rate",
- rate: 2.5,
+ surcharge_details: {
+ surcharge: { type: "rate", value: { percentage: 2.5 } },
+ tax_on_surcharge: null,
+ },
},
rules: [],
+ metadata: {},
},
},
},
@@ -213,34 +214,167 @@ export const connectorDetails = {
status: 200,
body: {
name: "surcharge_config_rate",
- merchant_surcharge_configs: {},
+ merchant_surcharge_configs: { show_surcharge_breakup_screen: null },
algorithm: {
- type: "rate",
- rate: 2.5,
defaultSelection: {
- surcharge_type: "rate",
- rate: 2.5,
+ surcharge_details: {
+ surcharge: { type: "rate", value: { percentage: 2.5 } },
+ tax_on_surcharge: null,
+ },
},
rules: [],
+ metadata: {},
},
},
},
},
Delete: {
+ Request: {},
+ Response: {
+ status: 200,
+ body: {},
+ },
+ },
+ CreateFixed: {
Request: {},
Response: {
status: 200,
body: {
- name: "surcharge_config_rate",
- merchant_surcharge_configs: {},
+ name: "surcharge_config_fixed",
+ merchant_surcharge_configs: { show_surcharge_breakup_screen: null },
+ algorithm: {
+ defaultSelection: {
+ surcharge_details: {
+ surcharge: { type: "fixed", value: { amount: 100 } },
+ tax_on_surcharge: null,
+ },
+ },
+ rules: [],
+ metadata: {},
+ },
+ },
+ },
+ },
+ RetrieveFixed: {
+ Request: {},
+ Response: {
+ status: 200,
+ body: {
+ name: "surcharge_config_fixed",
+ merchant_surcharge_configs: { show_surcharge_breakup_screen: null },
algorithm: {
- type: "rate",
- rate: 2.5,
defaultSelection: {
- surcharge_type: "rate",
- rate: 2.5,
+ surcharge_details: {
+ surcharge: { type: "fixed", value: { amount: 100 } },
+ tax_on_surcharge: null,
+ },
},
rules: [],
+ metadata: {},
+ },
+ },
+ },
+ },
+ CreateWithRules: {
+ Request: {},
+ Response: {
+ status: 200,
+ body: {
+ name: "surcharge_config_rules",
+ merchant_surcharge_configs: { show_surcharge_breakup_screen: null },
+ algorithm: {
+ defaultSelection: {
+ surcharge_details: {
+ surcharge: { type: "rate", value: { percentage: 2.5 } },
+ tax_on_surcharge: null,
+ },
+ },
+ rules: [
+ {
+ connectorSelection: {
+ surcharge_details: {
+ surcharge: { type: "rate", value: { percentage: 3 } },
+ tax_on_surcharge: null,
+ },
+ },
+ name: "card_surcharge_rule",
+ statements: [
+ {
+ condition: [
+ {
+ lhs: "payment_method",
+ comparison: "equal",
+ value: {
+ type: "enum_variant",
+ value: "card",
+ },
+ metadata: {},
+ },
+ ],
+ nested: null,
+ },
+ ],
+ },
+ ],
+ metadata: {},
+ },
+ },
+ },
+ },
+ RetrieveWithRules: {
+ Request: {},
+ Response: {
+ status: 200,
+ body: {
+ name: "surcharge_config_rules",
+ merchant_surcharge_configs: { show_surcharge_breakup_screen: null },
+ algorithm: {
+ defaultSelection: {
+ surcharge_details: {
+ surcharge: { type: "rate", value: { percentage: 2.5 } },
+ tax_on_surcharge: null,
+ },
+ },
+ rules: [
+ {
+ connectorSelection: {
+ surcharge_details: {
+ surcharge: { type: "rate", value: { percentage: 3 } },
+ tax_on_surcharge: null,
+ },
+ },
+ name: "card_surcharge_rule",
+ statements: [
+ {
+ condition: [
+ {
+ lhs: "payment_method",
+ comparison: "equal",
+ value: {
+ type: "enum_variant",
+ value: "card",
+ },
+ metadata: {},
+ },
+ ],
+ nested: null,
+ },
+ ],
+ },
+ ],
+ metadata: {},
+ },
+ },
+ },
+ },
+ RetrieveAfterDelete: {
+ Request: {},
+ Response: {
+ status: 404,
+ body: {
+ error: {
+ message: "Resource ID does not exist in our records",
+ code: "HE_02",
},
},
},
diff --git a/cypress-tests/cypress/e2e/spec/Routing/00005-SurchargeDSLConfiguration.cy.js b/cypress-tests/cypress/e2e/spec/Routing/00005-SurchargeDSLConfiguration.cy.js
index 7764b77a57..ba8758e773 100644
--- a/cypress-tests/cypress/e2e/spec/Routing/00005-SurchargeDSLConfiguration.cy.js
+++ b/cypress-tests/cypress/e2e/spec/Routing/00005-SurchargeDSLConfiguration.cy.js
@@ -7,6 +7,19 @@ describe("Surcharge DSL Configuration Test", () => {
before("seed global state", () => {
cy.task("getGlobalState").then((state) => {
globalState = new State(state);
+
+ // Create a fresh user + merchant so we get an active AuthToken.
+ // Env-based credentials don't reliably yield an AuthToken because the
+ // env user may not have an active role on the test merchant.
+ cy.signupUserWithMerchant("CypressSurchargeDSL", globalState);
+
+ // Login sequence used elsewhere in the suite: userLogin sets
+ // totpToken, terminate2Fa exchanges it for userInfoToken, and
+ // userInfo reads merchantId/organizationId/profileId off /user —
+ // retargeting the spec at the merchant we just created.
+ cy.userLogin(globalState);
+ cy.terminate2Fa(globalState);
+ cy.userInfo(globalState);
});
});
@@ -14,6 +27,12 @@ describe("Surcharge DSL Configuration Test", () => {
cy.task("setGlobalState", globalState.data);
});
+ after("cleanup throwaway merchant", () => {
+ if (globalState.get("merchantId")) {
+ cy.merchantDeleteCall(globalState);
+ }
+ });
+
context("Surcharge DSL with rate-based default selection", () => {
it("create-surcharge-dsl-config-rate", () => {
const data =
@@ -24,13 +43,13 @@ describe("Surcharge DSL Configuration Test", () => {
name: "surcharge_config_rate",
merchant_surcharge_configs: {},
algorithm: {
- type: "rate",
- rate: 2.5,
defaultSelection: {
- surcharge_type: "rate",
- rate: 2.5,
+ surcharge_details: {
+ surcharge: { type: "rate", value: { percentage: 2.5 } },
+ },
},
rules: [],
+ metadata: {},
},
};
@@ -58,7 +77,7 @@ describe("Surcharge DSL Configuration Test", () => {
it("verify-delete-by-retrieve-empty", () => {
const data =
utils.getConnectorDetails("common")["SurchargeDecisionManager"][
- "Retrieve"
+ "RetrieveAfterDelete"
];
cy.retrieveSurchargeDSLConfig(data, globalState);
@@ -69,19 +88,19 @@ describe("Surcharge DSL Configuration Test", () => {
it("create-surcharge-dsl-config-fixed", () => {
const data =
utils.getConnectorDetails("common")["SurchargeDecisionManager"][
- "Create"
+ "CreateFixed"
];
const surchargeBody = {
name: "surcharge_config_fixed",
merchant_surcharge_configs: {},
algorithm: {
- type: "fixed",
- amount: 100,
defaultSelection: {
- surcharge_type: "fixed",
- amount: 100,
+ surcharge_details: {
+ surcharge: { type: "fixed", value: { amount: 100 } },
+ },
},
rules: [],
+ metadata: {},
},
};
@@ -91,7 +110,7 @@ describe("Surcharge DSL Configuration Test", () => {
it("retrieve-surcharge-dsl-config-fixed", () => {
const data =
utils.getConnectorDetails("common")["SurchargeDecisionManager"][
- "Retrieve"
+ "RetrieveFixed"
];
cy.retrieveSurchargeDSLConfig(data, globalState);
@@ -111,24 +130,24 @@ describe("Surcharge DSL Configuration Test", () => {
it("create-surcharge-dsl-config-with-rules", () => {
const data =
utils.getConnectorDetails("common")["SurchargeDecisionManager"][
- "Create"
+ "CreateWithRules"
];
const surchargeBody = {
name: "surcharge_config_rules",
merchant_surcharge_configs: {},
algorithm: {
- type: "rate",
- rate: 2.5,
defaultSelection: {
- surcharge_type: "rate",
- rate: 2.5,
+ surcharge_details: {
+ surcharge: { type: "rate", value: { percentage: 2.5 } },
+ },
},
rules: [
{
name: "card_surcharge_rule",
- surcharge_value: {
- surcharge_type: "rate",
- rate: 3.0,
+ connectorSelection: {
+ surcharge_details: {
+ surcharge: { type: "rate", value: { percentage: 3.0 } },
+ },
},
statements: [
{
@@ -147,6 +166,7 @@ describe("Surcharge DSL Configuration Test", () => {
],
},
],
+ metadata: {},
},
};
@@ -156,7 +176,7 @@ describe("Surcharge DSL Configuration Test", () => {
it("retrieve-surcharge-dsl-config-with-rules", () => {
const data =
utils.getConnectorDetails("common")["SurchargeDecisionManager"][
- "Retrieve"
+ "RetrieveWithRules"
];
cy.retrieveSurchargeDSLConfig(data, globalState);
diff --git a/cypress-tests/cypress/support/commands.js b/cypress-tests/cypress/support/commands.js
index c5084dcf91..e360e7ca91 100644
--- a/cypress-tests/cypress/support/commands.js
+++ b/cypress-tests/cypress/support/commands.js
@@ -7425,6 +7425,50 @@ Cypress.Commands.add("retrievePayoutCallTest", (globalState, data) => {
});
// User API calls
+Cypress.Commands.add("signupUserWithMerchant", (namePrefix, globalState) => {
+ const baseUrl = globalState.get("baseUrl");
+ // crypto.randomInt is Node-only; use rejection sampling over getRandomValues
+ // (available in the browser) to avoid modulo bias.
+ const randomBuf = new Uint32Array(1);
+ const maxUnbiased = Math.floor(0xffffffff / 10000) * 10000;
+ let randomWord;
+ do {
+ crypto.getRandomValues(randomBuf);
+ randomWord = randomBuf[0];
+ } while (randomWord >= maxUnbiased);
+ const randomPart = randomWord % 10000;
+ const uniqueSuffix = `${Date.now()}${randomPart}`;
+ const email = `cypress_${namePrefix.toLowerCase()}_${uniqueSuffix}@cypresstest.in`;
+ const password = `Cypress@${uniqueSuffix}`;
+
+ cy.request({
+ method: "POST",
+ url: `${baseUrl}/user/signup_with_merchant_id`,
+ headers: {
+ "Content-Type": "application/json",
+ "api-key": globalState.get("adminApiKey"),
+ },
+ body: {
+ email,
+ password,
+ company_name: `${namePrefix}${uniqueSuffix}`,
+ name: namePrefix,
+ },
+ failOnStatusCode: false,
+ }).then((response) => {
+ logRequestId(response.headers["x-request-id"]);
+
+ cy.wrap(response).then(() => {
+ if (response.status !== 200) {
+ throw new Error(
+ `signup_with_merchant_id failed with status: "${response.status}" and message: "${JSON.stringify(response.body)}"`
+ );
+ }
+ globalState.set("email", email);
+ globalState.set("password", password);
+ });
+ });
+});
// Below 3 commands should be called in sequence to login a user
Cypress.Commands.add("userLogin", (globalState) => {
const baseUrl = globalState.get("baseUrl");
@@ -7824,7 +7868,12 @@ Cypress.Commands.add(
method: "PUT",
url: `${globalState.get("baseUrl")}/routing/decision/surcharge`,
headers: {
- "api-key": globalState.get("apiKey"),
+ ...(globalState.get("userInfoToken")
+ ? { Authorization: `Bearer ${globalState.get("userInfoToken")}` }
+ : {
+ "api-key":
+ globalState.get("apiKey") || globalState.get("adminApiKey"),
+ }),
"Content-Type": "application/json",
},
body: surchargeBody,
@@ -7935,7 +7984,12 @@ Cypress.Commands.add("retrieveSurchargeDSLConfig", (data, globalState) => {
method: "GET",
url: `${globalState.get("baseUrl")}/routing/decision/surcharge`,
headers: {
- "api-key": globalState.get("apiKey"),
+ ...(globalState.get("userInfoToken")
+ ? { Authorization: `Bearer ${globalState.get("userInfoToken")}` }
+ : {
+ "api-key":
+ globalState.get("apiKey") || globalState.get("adminApiKey"),
+ }),
"Content-Type": "application/json",
},
failOnStatusCode: false,
@@ -7963,7 +8017,12 @@ Cypress.Commands.add("deleteSurchargeDSLConfig", (data, globalState) => {
method: "DELETE",
url: `${globalState.get("baseUrl")}/routing/decision/surcharge`,
headers: {
- "api-key": globalState.get("apiKey"),
+ ...(globalState.get("userInfoToken")
+ ? { Authorization: `Bearer ${globalState.get("userInfoToken")}` }
+ : {
+ "api-key":
+ globalState.get("apiKey") || globalState.get("adminApiKey"),
+ }),
"Content-Type": "application/json",
},
failOnStatusCode: false,
@@ -7971,8 +8030,6 @@ Cypress.Commands.add("deleteSurchargeDSLConfig", (data, globalState) => {
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]);