Skip to content

Commit 7e77c1c

Browse files
committed
refactor: add validations around login
1 parent 968d6ff commit 7e77c1c

File tree

5 files changed

+110
-19
lines changed

5 files changed

+110
-19
lines changed

cypress-tests/cypress/e2e/spec/Routing/00000-PriorityRouting.cy.js

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,29 @@ describe("Priority Based Routing Test", () => {
88
let shouldContinue = true;
99

1010
beforeEach(() => {
11-
// Restore the session if it exists
1211
cy.session("login", () => {
13-
cy.userLogin(globalState);
14-
cy.terminate2Fa(globalState);
15-
cy.userInfo(globalState);
12+
// Make sure we have credentials
13+
if (!globalState.get("email") || !globalState.get("password")) {
14+
throw new Error("Missing login credentials in global state");
15+
}
16+
17+
cy.userLogin(globalState)
18+
.then(() => cy.terminate2Fa(globalState))
19+
.then(() => cy.userInfo(globalState))
20+
.then(() => {
21+
// Verify we have all necessary tokens and IDs
22+
const requiredKeys = [
23+
"userInfoToken",
24+
"merchantId",
25+
"organizationId",
26+
"profileId",
27+
];
28+
requiredKeys.forEach((key) => {
29+
if (!globalState.get(key)) {
30+
throw new Error(`Missing required key after login: ${key}`);
31+
}
32+
});
33+
});
1634
});
1735
});
1836

cypress-tests/cypress/e2e/spec/Routing/00001-VolumeBasedRouting.cy.js

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,31 @@ let globalState;
77
describe("Volume Based Routing Test", () => {
88
beforeEach(() => {
99
// Restore the session if it exists
10-
cy.session("login", () => {
11-
cy.userLogin(globalState);
12-
cy.terminate2Fa(globalState);
13-
cy.userInfo(globalState);
10+
beforeEach(() => {
11+
cy.session("login", () => {
12+
// Make sure we have credentials
13+
if (!globalState.get("email") || !globalState.get("password")) {
14+
throw new Error("Missing login credentials in global state");
15+
}
16+
17+
cy.userLogin(globalState)
18+
.then(() => cy.terminate2Fa(globalState))
19+
.then(() => cy.userInfo(globalState))
20+
.then(() => {
21+
// Verify we have all necessary tokens and IDs
22+
const requiredKeys = [
23+
"userInfoToken",
24+
"merchantId",
25+
"organizationId",
26+
"profileId",
27+
];
28+
requiredKeys.forEach((key) => {
29+
if (!globalState.get(key)) {
30+
throw new Error(`Missing required key after login: ${key}`);
31+
}
32+
});
33+
});
34+
});
1435
});
1536
});
1637

cypress-tests/cypress/e2e/spec/Routing/00002-RuleBasedRouting.cy.js

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,31 @@ let globalState;
77
describe("Rule Based Routing Test", () => {
88
beforeEach(() => {
99
// Restore the session if it exists
10-
cy.session("login", () => {
11-
cy.userLogin(globalState);
12-
cy.terminate2Fa(globalState);
13-
cy.userInfo(globalState);
10+
beforeEach(() => {
11+
cy.session("login", () => {
12+
// Make sure we have credentials
13+
if (!globalState.get("email") || !globalState.get("password")) {
14+
throw new Error("Missing login credentials in global state");
15+
}
16+
17+
cy.userLogin(globalState)
18+
.then(() => cy.terminate2Fa(globalState))
19+
.then(() => cy.userInfo(globalState))
20+
.then(() => {
21+
// Verify we have all necessary tokens and IDs
22+
const requiredKeys = [
23+
"userInfoToken",
24+
"merchantId",
25+
"organizationId",
26+
"profileId",
27+
];
28+
requiredKeys.forEach((key) => {
29+
if (!globalState.get(key)) {
30+
throw new Error(`Missing required key after login: ${key}`);
31+
}
32+
});
33+
});
34+
});
1435
});
1536
});
1637

cypress-tests/cypress/e2e/spec/Routing/00003-Retries.cy.js

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,31 @@ let globalState;
77
describe("Auto Retries & Step Up 3DS", () => {
88
beforeEach(() => {
99
// Restore the session if it exists
10-
cy.session("login", () => {
11-
cy.userLogin(globalState);
12-
cy.terminate2Fa(globalState);
13-
cy.userInfo(globalState);
10+
beforeEach(() => {
11+
cy.session("login", () => {
12+
// Make sure we have credentials
13+
if (!globalState.get("email") || !globalState.get("password")) {
14+
throw new Error("Missing login credentials in global state");
15+
}
16+
17+
cy.userLogin(globalState)
18+
.then(() => cy.terminate2Fa(globalState))
19+
.then(() => cy.userInfo(globalState))
20+
.then(() => {
21+
// Verify we have all necessary tokens and IDs
22+
const requiredKeys = [
23+
"userInfoToken",
24+
"merchantId",
25+
"organizationId",
26+
"profileId",
27+
];
28+
requiredKeys.forEach((key) => {
29+
if (!globalState.get(key)) {
30+
throw new Error(`Missing required key after login: ${key}`);
31+
}
32+
});
33+
});
34+
});
1435
});
1536
});
1637

cypress-tests/cypress/support/commands.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3098,6 +3098,9 @@ Cypress.Commands.add("userLogin", (globalState) => {
30983098
.be.empty;
30993099

31003100
const totpToken = response.body.token;
3101+
if (!totpToken) {
3102+
throw new Error("No token received from login");
3103+
}
31013104
globalState.set("totpToken", totpToken);
31023105
}
31033106
} else {
@@ -3131,6 +3134,9 @@ Cypress.Commands.add("terminate2Fa", (globalState) => {
31313134
.to.not.be.empty;
31323135

31333136
const userInfoToken = response.body.token;
3137+
if (!userInfoToken) {
3138+
throw new Error("No user info token received");
3139+
}
31343140
globalState.set("userInfoToken", userInfoToken);
31353141
}
31363142
} else {
@@ -3143,14 +3149,18 @@ Cypress.Commands.add("terminate2Fa", (globalState) => {
31433149
Cypress.Commands.add("userInfo", (globalState) => {
31443150
// Define the necessary variables and constant
31453151
const baseUrl = globalState.get("baseUrl");
3146-
const apiKey = globalState.get("userInfoToken");
3152+
const userInfoToken = globalState.get("userInfoToken");
31473153
const url = `${baseUrl}/user`;
31483154

3155+
if (!userInfoToken) {
3156+
throw new Error("No user info token available");
3157+
}
3158+
31493159
cy.request({
31503160
method: "GET",
31513161
url: url,
31523162
headers: {
3153-
Authorization: `Bearer ${apiKey}`,
3163+
Authorization: `Bearer ${userInfoToken}`,
31543164
"Content-Type": "application/json",
31553165
},
31563166
failOnStatusCode: false,
@@ -3169,7 +3179,7 @@ Cypress.Commands.add("userInfo", (globalState) => {
31693179
globalState.set("organizationId", response.body.org_id);
31703180
globalState.set("profileId", response.body.profile_id);
31713181

3172-
globalState.set("userInfoToken", apiKey);
3182+
globalState.set("userInfoToken", userInfoToken);
31733183
} else {
31743184
throw new Error(
31753185
`User login call failed to fetch user info with status: "${response.status}" and message: "${response.body.error.message}"`

0 commit comments

Comments
 (0)