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): backup and restore sessions when using user apis (#6978)

Pa1NarK0b54b375ef42
diff --git a/cypress-tests/cypress/e2e/RoutingTest/00000-PriorityRouting.cy.js b/cypress-tests/cypress/e2e/RoutingTest/00000-PriorityRouting.cy.js
index 22e4b3783a..5699712ec2 100644
--- a/cypress-tests/cypress/e2e/RoutingTest/00000-PriorityRouting.cy.js
+++ b/cypress-tests/cypress/e2e/RoutingTest/00000-PriorityRouting.cy.js
@@ -7,7 +7,16 @@ let globalState;
describe("Priority Based Routing Test", () => {
let shouldContinue = true;
- context("Login", () => {
+ beforeEach(() => {
+ // Restore the session if it exists
+ cy.session("login", () => {
+ cy.userLogin(globalState);
+ cy.terminate2Fa(globalState);
+ cy.userInfo(globalState);
+ });
+ });
+
+ context("Get merchant info", () => {
before("seed global state", () => {
cy.task("getGlobalState").then((state) => {
globalState = new State(state);
@@ -18,12 +27,6 @@ describe("Priority Based Routing Test", () => {
cy.task("setGlobalState", globalState.data);
});
- it("User login", () => {
- cy.userLogin(globalState);
- cy.terminate2Fa(globalState);
- cy.userInfo(globalState);
- });
-
it("merchant retrieve call", () => {
cy.merchantRetrieveCall(globalState);
});
@@ -39,6 +42,7 @@ describe("Priority Based Routing Test", () => {
after("flush global state", () => {
cy.task("setGlobalState", globalState.data);
});
+
it("list-mca-by-mid", () => {
cy.ListMcaByMid(globalState);
});
@@ -117,6 +121,7 @@ describe("Priority Based Routing Test", () => {
after("flush global state", () => {
cy.task("setGlobalState", globalState.data);
});
+
it("list-mca-by-mid", () => {
cy.ListMcaByMid(globalState);
});
diff --git a/cypress-tests/cypress/e2e/RoutingTest/00001-VolumeBasedRouting.cy.js b/cypress-tests/cypress/e2e/RoutingTest/00001-VolumeBasedRouting.cy.js
index 7d7f75e351..16b640bc03 100644
--- a/cypress-tests/cypress/e2e/RoutingTest/00001-VolumeBasedRouting.cy.js
+++ b/cypress-tests/cypress/e2e/RoutingTest/00001-VolumeBasedRouting.cy.js
@@ -5,7 +5,16 @@ import * as utils from "../RoutingUtils/Utils";
let globalState;
describe("Volume Based Routing Test", () => {
- context("Login", () => {
+ beforeEach(() => {
+ // Restore the session if it exists
+ cy.session("login", () => {
+ cy.userLogin(globalState);
+ cy.terminate2Fa(globalState);
+ cy.userInfo(globalState);
+ });
+ });
+
+ context("Get merchant info", () => {
before("seed global state", () => {
cy.task("getGlobalState").then((state) => {
globalState = new State(state);
@@ -16,12 +25,6 @@ describe("Volume Based Routing Test", () => {
cy.task("setGlobalState", globalState.data);
});
- it("User login", () => {
- cy.userLogin(globalState);
- cy.terminate2Fa(globalState);
- cy.userInfo(globalState);
- });
-
it("merchant retrieve call", () => {
cy.merchantRetrieveCall(globalState);
});
diff --git a/cypress-tests/cypress/e2e/RoutingTest/00002-RuleBasedRouting.cy.js b/cypress-tests/cypress/e2e/RoutingTest/00002-RuleBasedRouting.cy.js
index 304668752c..a1621a530a 100644
--- a/cypress-tests/cypress/e2e/RoutingTest/00002-RuleBasedRouting.cy.js
+++ b/cypress-tests/cypress/e2e/RoutingTest/00002-RuleBasedRouting.cy.js
@@ -5,7 +5,16 @@ import * as utils from "../RoutingUtils/Utils";
let globalState;
describe("Rule Based Routing Test", () => {
- context("Login", () => {
+ beforeEach(() => {
+ // Restore the session if it exists
+ cy.session("login", () => {
+ cy.userLogin(globalState);
+ cy.terminate2Fa(globalState);
+ cy.userInfo(globalState);
+ });
+ });
+
+ context("Get merchant info", () => {
before("seed global state", () => {
cy.task("getGlobalState").then((state) => {
globalState = new State(state);
@@ -16,12 +25,6 @@ describe("Rule Based Routing Test", () => {
cy.task("setGlobalState", globalState.data);
});
- it("User login", () => {
- cy.userLogin(globalState);
- cy.terminate2Fa(globalState);
- cy.userInfo(globalState);
- });
-
it("merchant retrieve call", () => {
cy.merchantRetrieveCall(globalState);
});
diff --git a/cypress-tests/cypress/e2e/RoutingTest/00003-Retries.cy.js b/cypress-tests/cypress/e2e/RoutingTest/00003-Retries.cy.js
index 74c02d7ac9..94fcaed104 100644
--- a/cypress-tests/cypress/e2e/RoutingTest/00003-Retries.cy.js
+++ b/cypress-tests/cypress/e2e/RoutingTest/00003-Retries.cy.js
@@ -5,7 +5,16 @@ import * as utils from "../RoutingUtils/Utils";
let globalState;
describe("Auto Retries & Step Up 3DS", () => {
- context("Login", () => {
+ beforeEach(() => {
+ // Restore the session if it exists
+ cy.session("login", () => {
+ cy.userLogin(globalState);
+ cy.terminate2Fa(globalState);
+ cy.userInfo(globalState);
+ });
+ });
+
+ context("Get merchant info", () => {
before("seed global state", () => {
cy.task("getGlobalState").then((state) => {
globalState = new State(state);
@@ -16,12 +25,6 @@ describe("Auto Retries & Step Up 3DS", () => {
cy.task("setGlobalState", globalState.data);
});
- it("User login", () => {
- cy.userLogin(globalState);
- cy.terminate2Fa(globalState);
- cy.userInfo(globalState);
- });
-
it("List MCA", () => {
cy.ListMcaByMid(globalState);
});
diff --git a/cypress-tests/cypress/support/commands.js b/cypress-tests/cypress/support/commands.js
index bcbe64512f..e2e83edaf0 100644
--- a/cypress-tests/cypress/support/commands.js
+++ b/cypress-tests/cypress/support/commands.js
@@ -3005,14 +3005,13 @@ Cypress.Commands.add("retrievePayoutCallTest", (globalState) => {
// User API calls
// Below 3 commands should be called in sequence to login a user
Cypress.Commands.add("userLogin", (globalState) => {
- // Define the necessary variables and constant
- const base_url = globalState.get("baseUrl");
- const query_params = `token_only=true`;
- const signin_body = {
- email: `${globalState.get("email")}`,
- password: `${globalState.get("password")}`,
+ const baseUrl = globalState.get("baseUrl");
+ const queryParams = `token_only=true`;
+ const signinBody = {
+ email: globalState.get("email"),
+ password: globalState.get("password"),
};
- const url = `${base_url}/user/v2/signin?${query_params}`;
+ const url = `${baseUrl}/user/v2/signin?${queryParams}`;
cy.request({
method: "POST",
@@ -3020,37 +3019,38 @@ Cypress.Commands.add("userLogin", (globalState) => {
headers: {
"Content-Type": "application/json",
},
- body: signin_body,
+ body: signinBody,
failOnStatusCode: false,
}).then((response) => {
logRequestId(response.headers["x-request-id"]);
if (response.status === 200) {
if (response.body.token_type === "totp") {
- expect(response.body).to.have.property("token").and.to.not.be.empty;
+ expect(response.body, "totp_token").to.have.property("token").and.to.not
+ .be.empty;
- globalState.set("totpToken", response.body.token);
- cy.task("setGlobalState", globalState.data);
+ const totpToken = response.body.token;
+ globalState.set("totpToken", totpToken);
}
} else {
throw new Error(
- `User login call failed to get totp token with status ${response.status} and message ${response.body.message}`
+ `User login call failed to get totp token with status: "${response.status}" and message: "${response.body.error.message}"`
);
}
});
});
Cypress.Commands.add("terminate2Fa", (globalState) => {
// Define the necessary variables and constant
- const base_url = globalState.get("baseUrl");
- const query_params = `skip_two_factor_auth=true`;
- const api_key = globalState.get("totpToken");
- const url = `${base_url}/user/2fa/terminate?${query_params}`;
+ const baseUrl = globalState.get("baseUrl");
+ const queryParams = `skip_two_factor_auth=true`;
+ const apiKey = globalState.get("totpToken");
+ const url = `${baseUrl}/user/2fa/terminate?${queryParams}`;
cy.request({
method: "GET",
url: url,
headers: {
- Authorization: `Bearer ${api_key}`,
+ Authorization: `Bearer ${apiKey}`,
"Content-Type": "application/json",
},
failOnStatusCode: false,
@@ -3059,29 +3059,30 @@ Cypress.Commands.add("terminate2Fa", (globalState) => {
if (response.status === 200) {
if (response.body.token_type === "user_info") {
- expect(response.body).to.have.property("token").and.to.not.be.empty;
+ expect(response.body, "user_info_token").to.have.property("token").and
+ .to.not.be.empty;
- globalState.set("userInfoToken", response.body.token);
- cy.task("setGlobalState", globalState.data);
+ const userInfoToken = response.body.token;
+ globalState.set("userInfoToken", userInfoToken);
}
} else {
throw new Error(
- `2FA terminate call failed with status ${response.status} and message ${response.body.message}`
+ `2FA terminate call failed with status: "${response.status}" and message: "${response.body.error.message}"`
);
}
});
});
Cypress.Commands.add("userInfo", (globalState) => {
// Define the necessary variables and constant
- const base_url = globalState.get("baseUrl");
- const api_key = globalState.get("userInfoToken");
- const url = `${base_url}/user`;
+ const baseUrl = globalState.get("baseUrl");
+ const apiKey = globalState.get("userInfoToken");
+ const url = `${baseUrl}/user`;
cy.request({
method: "GET",
url: url,
headers: {
- Authorization: `Bearer ${api_key}`,
+ Authorization: `Bearer ${apiKey}`,
"Content-Type": "application/json",
},
failOnStatusCode: false,
@@ -3089,16 +3090,21 @@ Cypress.Commands.add("userInfo", (globalState) => {
logRequestId(response.headers["x-request-id"]);
if (response.status === 200) {
- expect(response.body).to.have.property("merchant_id").and.to.not.be.empty;
- expect(response.body).to.have.property("org_id").and.to.not.be.empty;
- expect(response.body).to.have.property("profile_id").and.to.not.be.empty;
+ expect(response.body, "merchant_id").to.have.property("merchant_id").and
+ .to.not.be.empty;
+ expect(response.body, "organization_id").to.have.property("org_id").and.to
+ .not.be.empty;
+ expect(response.body, "profile_id").to.have.property("profile_id").and.to
+ .not.be.empty;
globalState.set("merchantId", response.body.merchant_id);
globalState.set("organizationId", response.body.org_id);
globalState.set("profileId", response.body.profile_id);
+
+ globalState.set("userInfoToken", apiKey);
} else {
throw new Error(
- `User login call failed to fetch user info with status ${response.status} and message ${response.body.message}`
+ `User login call failed to fetch user info with status: "${response.status}" and message: "${response.body.error.message}"`
);
}
});
@@ -3146,7 +3152,6 @@ Cypress.Commands.add(
headers: {
Authorization: `Bearer ${globalState.get("userInfoToken")}`,
"Content-Type": "application/json",
- Cookie: `${globalState.get("cookie")}`,
},
failOnStatusCode: false,
body: routingBody,
@@ -3169,15 +3174,14 @@ Cypress.Commands.add(
Cypress.Commands.add("activateRoutingConfig", (data, globalState) => {
const { Response: resData } = data || {};
-
const routing_config_id = globalState.get("routingConfigId");
+
cy.request({
method: "POST",
url: `${globalState.get("baseUrl")}/routing/${routing_config_id}/activate`,
headers: {
Authorization: `Bearer ${globalState.get("userInfoToken")}`,
"Content-Type": "application/json",
- Cookie: `${globalState.get("cookie")}`,
},
failOnStatusCode: false,
}).then((response) => {
@@ -3197,15 +3201,14 @@ Cypress.Commands.add("activateRoutingConfig", (data, globalState) => {
Cypress.Commands.add("retrieveRoutingConfig", (data, globalState) => {
const { Response: resData } = data || {};
-
const routing_config_id = globalState.get("routingConfigId");
+
cy.request({
method: "GET",
url: `${globalState.get("baseUrl")}/routing/${routing_config_id}`,
headers: {
Authorization: `Bearer ${globalState.get("userInfoToken")}`,
"Content-Type": "application/json",
- Cookie: `${globalState.get("cookie")}`,
},
failOnStatusCode: false,
}).then((response) => {