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
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
fix(cypress): fix user login in routing cypress framework (#5950)
Pa1NarK90949d94cf3c
diff --git a/cypress-tests/cypress/e2e/PaymentUtils/Commons.js b/cypress-tests/cypress/e2e/PaymentUtils/Commons.jsindex eff36cf502..284eff5fd1 100644--- a/cypress-tests/cypress/e2e/PaymentUtils/Commons.js+++ b/cypress-tests/cypress/e2e/PaymentUtils/Commons.js@@ -22,8 +22,18 @@ function normalise(input) {};if (typeof input !== "string") {- const spec_name = Cypress.spec.name.split("-")[1].split(".")[0];- return `${spec_name}`;+ const specName = Cypress.spec.name;++ if (specName.includes("-")) {+ const parts = specName.split("-");++ if (parts.length > 1 && parts[1].includes(".")) {+ return parts[1].split(".")[0];+ }+ }++ // Fallback+ return `${specName}`;}const lowerCaseInput = input.toLowerCase();diff --git a/cypress-tests/cypress/e2e/PaymentUtils/Novalnet.js b/cypress-tests/cypress/e2e/PaymentUtils/Novalnet.jsindex 6fe7dc6392..e0db22b347 100644--- a/cypress-tests/cypress/e2e/PaymentUtils/Novalnet.js+++ b/cypress-tests/cypress/e2e/PaymentUtils/Novalnet.js@@ -34,21 +34,21 @@ export const connectorDetails = {payment_method: "card",billing: {address: {- line1: "1467",- line2: "CA",- line3: "CA",- city: "Musterhausen",- state: "California",- zip: "12345",- country: "DE",- first_name: "Max",- last_name: "Mustermann"+ line1: "1467",+ line2: "CA",+ line3: "CA",+ city: "Musterhausen",+ state: "California",+ zip: "12345",+ country: "DE",+ first_name: "Max",+ last_name: "Mustermann",},email: "[email protected]",phone: {- number: "9123456789",- country_code: "+91"- }+ number: "9123456789",+ country_code: "+91",+ },},payment_method_data: {card: successfulThreeDSTestCardDetails,@@ -68,21 +68,21 @@ export const connectorDetails = {payment_method: "card",billing: {address: {- line1: "1467",- line2: "CA",- line3: "CA",- city: "Musterhausen",- state: "California",- zip: "12345",- country: "DE",- first_name: "Max",- last_name: "Mustermann"+ line1: "1467",+ line2: "CA",+ line3: "CA",+ city: "Musterhausen",+ state: "California",+ zip: "12345",+ country: "DE",+ first_name: "Max",+ last_name: "Mustermann",},email: "[email protected]",phone: {- number: "9123456789",- country_code: "+91"- }+ number: "9123456789",+ country_code: "+91",+ },},payment_method_data: {card: successfulThreeDSTestCardDetails,diff --git a/cypress-tests/cypress/e2e/PayoutUtils/Commons.js b/cypress-tests/cypress/e2e/PayoutUtils/Commons.jsindex 248d0fe2a4..5f8a580731 100644--- a/cypress-tests/cypress/e2e/PayoutUtils/Commons.js+++ b/cypress-tests/cypress/e2e/PayoutUtils/Commons.js@@ -18,6 +18,21 @@ function normalise(input) {// Add more known exceptions here};+ if (typeof input !== "string") {+ const specName = Cypress.spec.name;++ if (specName.includes("-")) {+ const parts = specName.split("-");++ if (parts.length > 1 && parts[1].includes(".")) {+ return parts[1].split(".")[0];+ }+ }++ // Fallback+ return `${specName}`;+ }+if (exceptions[input.toLowerCase()]) {return exceptions[input.toLowerCase()];} else {diff --git a/cypress-tests/cypress/e2e/RoutingTest/00000-PriorityRouting.cy.js b/cypress-tests/cypress/e2e/RoutingTest/00000-PriorityRouting.cy.jsindex 09f237d7d4..3037a6eb99 100644--- a/cypress-tests/cypress/e2e/RoutingTest/00000-PriorityRouting.cy.js+++ b/cypress-tests/cypress/e2e/RoutingTest/00000-PriorityRouting.cy.js@@ -6,7 +6,8 @@ let globalState;describe("Priority Based Routing Test", () => {let should_continue = true;- context("Create Jwt Token", () => {++ context("Login", () => {before("seed global state", () => {cy.task("getGlobalState").then((state) => {globalState = new State(state);@@ -16,14 +17,11 @@ describe("Priority Based Routing Test", () => {after("flush global state", () => {cy.task("setGlobalState", globalState.data);});- it("create-jwt-token", () => {- let data = utils.getConnectorDetails("common")["jwt"];- let req_data = data["Request"];- let res_data = data["Response"];- cy.createJWTToken(req_data, res_data, globalState);- if (should_continue)- should_continue = utils.should_continue_further(res_data);+ it("User login", () => {+ cy.userLogin(globalState);+ cy.terminate2Fa(globalState);+ cy.userInfo(globalState);});it("merchant retrieve call", () => {diff --git a/cypress-tests/cypress/e2e/RoutingTest/00001-VolumeBasedRouting.cy.js b/cypress-tests/cypress/e2e/RoutingTest/00001-VolumeBasedRouting.cy.jsindex e0b1ee589d..665afc9758 100644--- a/cypress-tests/cypress/e2e/RoutingTest/00001-VolumeBasedRouting.cy.js+++ b/cypress-tests/cypress/e2e/RoutingTest/00001-VolumeBasedRouting.cy.js@@ -5,9 +5,7 @@ import * as utils from "../RoutingUtils/Utils";let globalState;describe("Volume Based Routing Test", () => {- let should_continue = true;-- context("Create Jwt Token", () => {+ context("Login", () => {before("seed global state", () => {cy.task("getGlobalState").then((state) => {globalState = new State(state);@@ -17,14 +15,11 @@ describe("Volume Based Routing Test", () => {after("flush global state", () => {cy.task("setGlobalState", globalState.data);});- it("create-jwt-token", () => {- let data = utils.getConnectorDetails("common")["jwt"];- let req_data = data["Request"];- let res_data = data["Response"];- cy.createJWTToken(req_data, res_data, globalState);- if (should_continue)- should_continue = utils.should_continue_further(res_data);+ it("User login", () => {+ cy.userLogin(globalState);+ cy.terminate2Fa(globalState);+ cy.userInfo(globalState);});it("merchant retrieve call", () => {diff --git a/cypress-tests/cypress/e2e/RoutingTest/00002-RuleBasedRouting.cy.js b/cypress-tests/cypress/e2e/RoutingTest/00002-RuleBasedRouting.cy.jsindex 583573ba69..c98f34a55b 100644--- a/cypress-tests/cypress/e2e/RoutingTest/00002-RuleBasedRouting.cy.js+++ b/cypress-tests/cypress/e2e/RoutingTest/00002-RuleBasedRouting.cy.js@@ -5,9 +5,7 @@ import * as utils from "../RoutingUtils/Utils";let globalState;describe("Rule Based Routing Test", () => {- let should_continue = true;-- context("Create Jwt Token", () => {+ context("Login", () => {before("seed global state", () => {cy.task("getGlobalState").then((state) => {globalState = new State(state);@@ -17,12 +15,11 @@ describe("Rule Based Routing Test", () => {after("flush global state", () => {cy.task("setGlobalState", globalState.data);});- it("create-jwt-token", () => {- let data = utils.getConnectorDetails("common")["jwt"];- let req_data = data["Request"];- let res_data = data["Response"];- cy.createJWTToken(req_data, res_data, globalState);+ it("User login", () => {+ cy.userLogin(globalState);+ cy.terminate2Fa(globalState);+ cy.userInfo(globalState);});it("merchant retrieve call", () => {diff --git a/cypress-tests/cypress/e2e/RoutingTest/00003-Retries.cy.js b/cypress-tests/cypress/e2e/RoutingTest/00003-Retries.cy.jsindex 8675821500..2638b18f47 100644--- a/cypress-tests/cypress/e2e/RoutingTest/00003-Retries.cy.js+++ b/cypress-tests/cypress/e2e/RoutingTest/00003-Retries.cy.js@@ -16,12 +16,10 @@ describe("Auto Retries & Step Up 3DS", () => {cy.task("setGlobalState", globalState.data);});- it("Create JWT token", () => {- let data = utils.getConnectorDetails("common")["jwt"];- let req_data = data["Request"];- let res_data = data["Response"];-- cy.createJWTToken(req_data, res_data, globalState);+ it("User login", () => {+ cy.userLogin(globalState);+ cy.terminate2Fa(globalState);+ cy.userInfo(globalState);});it("List MCA", () => {diff --git a/cypress-tests/cypress/support/commands.js b/cypress-tests/cypress/support/commands.jsindex 3c7cbad2f9..396be8e59f 100644--- a/cypress-tests/cypress/support/commands.js+++ b/cypress-tests/cypress/support/commands.js@@ -967,7 +967,6 @@ Cypress.Commands.add((confirmBody, req_data, res_data, confirm, globalState) => {const paymentIntentId = globalState.get("paymentID");const connectorId = globalState.get("connectorId");- console.log("connectorId", connectorId);for (const key in req_data) {confirmBody[key] = req_data[key];}@@ -989,7 +988,6 @@ Cypress.Commands.add(expect(response.headers["content-type"]).to.include("application/json");globalState.set("paymentID", paymentIntentId);globalState.set("connectorId", response.body.connector);- console.log("connectorId", response.body.connector);globalState.set("paymentMethodType", confirmBody.payment_method_type);switch (response.body.authentication_type) {@@ -2063,46 +2061,104 @@ Cypress.Commands.add("retrievePayoutCallTest", (globalState) => {});});-Cypress.Commands.add("createJWTToken", (req_data, res_data, globalState) => {- const jwt_body = {+// 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 url = `${base_url}/user/v2/signin?${query_params}`;cy.request({method: "POST",- url: `${globalState.get("baseUrl")}/user/v2/signin`,+ url: url,headers: {"Content-Type": "application/json",},+ body: signin_body,failOnStatusCode: false,- body: jwt_body,}).then((response) => {logRequestId(response.headers["x-request-id"]);- expect(response.headers["content-type"]).to.include("application/json");if (response.status === 200) {- expect(response.body).to.have.property("token");- //set jwt_token- globalState.set("jwtToken", response.body.token);+ if (response.body.token_type === "totp") {+ expect(response.body).to.have.property("token").and.to.not.be.empty;- //setting merchantId for manual create merchant- globalState.set("merchantId", response.body.merchant_id);+ globalState.set("totpToken", response.body.token);+ cy.task("setGlobalState", globalState.data);+ }+ } else {+ throw new Error(+ `User login call failed to get totp token with status ${response.status} and message ${response.body.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}`;- // set session cookie- const sessionCookie = response.headers["set-cookie"][0];- const sessionValue = sessionCookie.split(";")[0];- globalState.set("cookie", sessionValue);+ cy.request({+ method: "GET",+ url: url,+ headers: {+ Authorization: `Bearer ${api_key}`,+ "Content-Type": "application/json",+ },+ failOnStatusCode: false,+ }).then((response) => {+ logRequestId(response.headers["x-request-id"]);- // set api key- globalState.set("apiKey", globalState.get("routingApiKey"));- globalState.set("merchantId", response.body.merchant_id);+ if (response.status === 200) {+ if (response.body.token_type === "user_info") {+ expect(response.body).to.have.property("token").and.to.not.be.empty;- for (const key in res_data.body) {- expect(res_data.body[key]).to.equal(response.body[key]);+ globalState.set("userInfoToken", response.body.token);+ cy.task("setGlobalState", globalState.data);}} else {- defaultErrorHandler(response, res_data);+ throw new Error(+ `2FA terminate call failed with status ${response.status} and message ${response.body.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`;++ cy.request({+ method: "GET",+ url: url,+ headers: {+ Authorization: `Bearer ${api_key}`,+ "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;++ globalState.set("merchantId", response.body.merchant_id);+ globalState.set("organizationId", response.body.org_id);+ globalState.set("profileId", response.body.profile_id);+ } else {+ throw new Error(+ `User login call failed to fetch user info with status ${response.status} and message ${response.body.message}`+ );}});});@@ -2145,9 +2201,9 @@ Cypress.Commands.add(method: "POST",url: `${globalState.get("baseUrl")}/routing`,headers: {+ Authorization: `Bearer ${globalState.get("userInfoToken")}`,"Content-Type": "application/json",Cookie: `${globalState.get("cookie")}`,- "api-key": `Bearer ${globalState.get("jwtToken")}`,},failOnStatusCode: false,body: routingBody,@@ -2176,9 +2232,9 @@ Cypress.Commands.add(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")}`,- "api-key": globalState.get("apiKey"),},failOnStatusCode: false,}).then((response) => {@@ -2205,9 +2261,9 @@ Cypress.Commands.add(method: "GET",url: `${globalState.get("baseUrl")}/routing/${routing_config_id}`,headers: {+ Authorization: `Bearer ${globalState.get("userInfoToken")}`,"Content-Type": "application/json",Cookie: `${globalState.get("cookie")}`,- "api-key": globalState.get("apiKey"),},failOnStatusCode: false,}).then((response) => {