Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cypress): backup and restore sessions when using user apis #6978

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
});
Expand All @@ -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);
});
Expand Down Expand Up @@ -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);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
});
Expand Down
17 changes: 10 additions & 7 deletions cypress-tests/cypress/e2e/RoutingTest/00003-Retries.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
});
Expand Down
71 changes: 37 additions & 34 deletions cypress-tests/cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -2970,52 +2970,52 @@ 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",
url: url,
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,
Expand All @@ -3024,46 +3024,52 @@ 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,
}).then((response) => {
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}"`
);
}
});
Expand Down Expand Up @@ -3111,7 +3117,6 @@ Cypress.Commands.add(
headers: {
Authorization: `Bearer ${globalState.get("userInfoToken")}`,
"Content-Type": "application/json",
Cookie: `${globalState.get("cookie")}`,
},
failOnStatusCode: false,
body: routingBody,
Expand All @@ -3134,15 +3139,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) => {
Expand All @@ -3162,15 +3166,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) => {
Expand Down
Loading