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

refactor(cypress): reuse config update command (#6197)

Ankesh Guptada194f34c686
diff --git a/cypress-tests/cypress/e2e/RoutingTest/00003-Retries.cy.js b/cypress-tests/cypress/e2e/RoutingTest/00003-Retries.cy.js
index 2638b18f47..79b3d3cba7 100644
--- a/cypress-tests/cypress/e2e/RoutingTest/00003-Retries.cy.js
+++ b/cypress-tests/cypress/e2e/RoutingTest/00003-Retries.cy.js
@@ -42,7 +42,7 @@ describe("Auto Retries & Step Up 3DS", () => {
context("Auto Retries", () => {
context("[Config: enable] Auto retries", () => {
it("Enable auto retries", () => {
- cy.autoRetryConfig(fixtures.configs.gsm, globalState, "true");
+ cy.updateConfig('autoRetry', fixtures.configs.gsm, globalState, "true");
});
context("Max auto retries", () => {
@@ -98,7 +98,8 @@ describe("Auto Retries & Step Up 3DS", () => {
context("Max auto retries = 2", () => {
const max_auto_retries = 2;
it("Update max auto retries", () => {
- cy.setMaxAutoRetries(
+ cy.updateConfig(
+ 'maxRetries',
fixtures.configs.max_auto_retries,
globalState,
`${max_auto_retries}`
@@ -152,7 +153,8 @@ describe("Auto Retries & Step Up 3DS", () => {
context("Max auto retries = 1", () => {
const max_auto_retries = 1;
it("Update max auto retries", () => {
- cy.setMaxAutoRetries(
+ cy.updateConfig(
+ 'maxRetries',
fixtures.configs.max_auto_retries,
globalState,
`${max_auto_retries}`
@@ -205,7 +207,8 @@ describe("Auto Retries & Step Up 3DS", () => {
context("Max auto retries = 0", () => {
const max_auto_retries = 0;
it("Update max auto retries", () => {
- cy.setMaxAutoRetries(
+ cy.updateConfig(
+ 'maxRetries',
fixtures.configs.max_auto_retries,
globalState,
`${max_auto_retries}`
@@ -309,7 +312,8 @@ describe("Auto Retries & Step Up 3DS", () => {
context("Max auto retries = 2", () => {
const max_auto_retries = 2;
it("Update max auto retries", () => {
- cy.setMaxAutoRetries(
+ cy.updateConfig(
+ 'maxRetries',
fixtures.configs.max_auto_retries,
globalState,
`${max_auto_retries}`
@@ -363,7 +367,8 @@ describe("Auto Retries & Step Up 3DS", () => {
context("Max auto retries = 1", () => {
const max_auto_retries = 1;
it("Update max auto retries", () => {
- cy.setMaxAutoRetries(
+ cy.updateConfig(
+ 'maxRetries',
fixtures.configs.max_auto_retries,
globalState,
`${max_auto_retries}`
@@ -417,7 +422,8 @@ describe("Auto Retries & Step Up 3DS", () => {
context("Max auto retries = 0", () => {
const max_auto_retries = 0;
it("Update max auto retries", () => {
- cy.setMaxAutoRetries(
+ cy.updateConfig(
+ 'maxRetries',
fixtures.configs.max_auto_retries,
globalState,
`${max_auto_retries}`
@@ -477,14 +483,15 @@ describe("Auto Retries & Step Up 3DS", () => {
});
it("[Config: enable] Step up for Stripe", () => {
- cy.stepUp(fixtures.configs.step_up, globalState, '["stripe"]');
+ cy.updateConfig('stepUp',fixtures.configs.step_up, globalState, '["stripe"]');
});
});
context("Make Payment", () => {
const max_auto_retries = 1;
it("Update max auto retries", () => {
- cy.setMaxAutoRetries(
+ cy.updateConfig(
+ 'maxRetries',
fixtures.configs.max_auto_retries,
globalState,
`${max_auto_retries}`
@@ -533,8 +540,8 @@ describe("Auto Retries & Step Up 3DS", () => {
context("[Config: disable] Auto retries", () => {
it("[Config: disable] Auto retries", () => {
- cy.autoRetryConfig(fixtures.configs.gsm, globalState, "false");
- });
+ cy.updateConfig('autoRetry', fixtures.configs.gsm, globalState, "false");
+ });
it("[Config: disable] Step up GSM", () => {
cy.updateGsmConfig(fixtures.gsmBody.gsm_update, globalState, false);
diff --git a/cypress-tests/cypress/support/commands.js b/cypress-tests/cypress/support/commands.js
index 17d3d2e972..a6436e7f67 100644
--- a/cypress-tests/cypress/support/commands.js
+++ b/cypress-tests/cypress/support/commands.js
@@ -2418,61 +2418,6 @@ Cypress.Commands.add(
}
);
-Cypress.Commands.add(
- "autoRetryConfig",
- (autoRetryGsmBody, globalState, value) => {
- const key = `should_call_gsm_${globalState.get("merchantId")}`;
- autoRetryGsmBody.key = key;
- autoRetryGsmBody.value = value;
-
- cy.request({
- method: "POST",
- url: `${globalState.get("baseUrl")}/configs/${key}`,
- headers: {
- Accept: "application/json",
- "Content-Type": "application/json",
- "api-key": globalState.get("adminApiKey"),
- },
- body: autoRetryGsmBody,
- failOnStatusCode: false,
- }).then((response) => {
- logRequestId(response.headers["x-request-id"]);
-
- if (response.status === 200) {
- expect(response.body).to.have.property("key").to.equal(key);
- expect(response.body).to.have.property("value").to.equal(value);
- }
- });
- }
-);
-
-Cypress.Commands.add(
- "setMaxAutoRetries",
- (maxAutoRetryBody, globalState, value) => {
- const key = `max_auto_retries_enabled_${globalState.get("merchantId")}`;
- maxAutoRetryBody.key = key;
- maxAutoRetryBody.value = value;
-
- cy.request({
- method: "POST",
- url: `${globalState.get("baseUrl")}/configs/${key}`,
- headers: {
- Accept: "application/json",
- "Content-Type": "application/json",
- "api-key": globalState.get("adminApiKey"),
- },
- body: maxAutoRetryBody,
- failOnStatusCode: false,
- }).then((response) => {
- logRequestId(response.headers["x-request-id"]);
- if (response.status === 200) {
- expect(response.body).to.have.property("key").to.equal(key);
- expect(response.body).to.have.property("value").to.equal(value);
- }
- });
- }
-);
-
Cypress.Commands.add(
"updateGsmConfig",
(gsmBody, globalState, step_up_possible) => {
@@ -2501,26 +2446,51 @@ Cypress.Commands.add(
}
);
-Cypress.Commands.add("stepUp", (stepUpBody, globalState, value) => {
- const key = `step_up_enabled_${globalState.get("merchantId")}`;
- stepUpBody.key = key;
- stepUpBody.value = value;
+Cypress.Commands.add("updateConfig", (configType, configData, globalState, value) => {
+ const base_url = globalState.get("baseUrl");
+ const merchant_id = globalState.get("merchantId");
+ const api_key = globalState.get("adminApiKey");
+
+ let key;
+ let url;
+ let body;
+
+ switch (configType) {
+ case 'autoRetry':
+ key = `should_call_gsm_${merchant_id}`;
+ url = `${base_url}/configs/${key}`;
+ body = { key: key, value: value };
+ break;
+ case 'maxRetries':
+ key = `max_auto_retries_enabled_${merchant_id}`;
+ url = `${base_url}/configs/${key}`;
+ body = { key: key, value: value };
+ break;
+ case 'stepUp':
+ key = `step_up_enabled_${merchant_id}`;
+ url = `${base_url}/configs/${key}`;
+ body = { key: key, value: value };
+ break;
+ default:
+ throw new Error(`Invalid config type passed into the configs: "${api_key}: ${value}"`);
+ }
cy.request({
- method: "POST",
- url: `${globalState.get("baseUrl")}/configs/${key}`,
+ method: 'POST',
+ url: url,
headers: {
"Content-Type": "application/json",
- "api-key": globalState.get("adminApiKey"),
+ "api-key": api_key,
},
- body: stepUpBody,
+ body: body,
failOnStatusCode: false,
}).then((response) => {
logRequestId(response.headers["x-request-id"]);
-
+
if (response.status === 200) {
expect(response.body).to.have.property("key").to.equal(key);
expect(response.body).to.have.property("value").to.equal(value);
}
});
});
+