diff --git a/cypress-tests/cypress/e2e/PaymentUtils/Utils.js b/cypress-tests/cypress/e2e/PaymentUtils/Utils.js index 5c6c409a4db6..5418fcb78128 100644 --- a/cypress-tests/cypress/e2e/PaymentUtils/Utils.js +++ b/cypress-tests/cypress/e2e/PaymentUtils/Utils.js @@ -63,8 +63,11 @@ export function getConnectorFlowDetails(connectorData, commonData, key) { } function mergeDetails(connectorId) { - const connectorData = getValueByKey(connectorDetails, connectorId); - const fallbackData = getValueByKey(connectorDetails, "commons"); + const connectorData = getValueByKey( + connectorDetails, + connectorId + ).authDetails; + const fallbackData = getValueByKey(connectorDetails, "commons").authDetails; // Merge data, prioritizing connectorData and filling missing data from fallbackData const mergedDetails = mergeConnectorDetails(connectorData, fallbackData); return mergedDetails; @@ -97,6 +100,15 @@ function mergeConnectorDetails(source, fallback) { return merged; } +export function handleMultipleConnectors(keys) { + return { + MULTIPLE_CONNECTORS: { + status: true, + count: keys.length, + }, + }; +} + export function getValueByKey(jsonObject, key, keyNumber = 0) { const data = typeof jsonObject === "string" ? JSON.parse(jsonObject) : jsonObject; @@ -115,15 +127,23 @@ export function getValueByKey(jsonObject, key, keyNumber = 0) { "connector_account_details" ) ) { - // Set MULTIPLE_CONNECTORS state via command - cy.setMultipleConnectorsState(keys); - return currentItem; + // Return state update instead of setting directly + return { + authDetails: currentItem, + stateUpdate: handleMultipleConnectors(keys), + }; } } } - return data[key]; + return { + authDetails: data[key], + stateUpdate: null, + }; } - return null; + return { + authDetails: null, + stateUpdate: null, + }; } export const should_continue_further = (data) => { diff --git a/cypress-tests/cypress/support/commands.js b/cypress-tests/cypress/support/commands.js index 5edd5f3d1fb2..361223df9fd0 100644 --- a/cypress-tests/cypress/support/commands.js +++ b/cypress-tests/cypress/support/commands.js @@ -42,18 +42,6 @@ function logRequestId(xRequestId) { } } -Cypress.Commands.add("setMultipleConnectorsState", (connectorKeys) => { - const MULTIPLE_CONNECTORS = { - status: true, - count: connectorKeys.length, - }; - - cy.then(() => { - // Update global state directly - cy.task("setGlobalState", MULTIPLE_CONNECTORS); - }); -}); - Cypress.Commands.add( "merchantCreateCallTest", (merchantCreateBody, globalState) => { @@ -424,7 +412,7 @@ Cypress.Commands.add( // it is best to use then() to handle the response within the same block of code cy.readFile(globalState.get("connectorAuthFilePath")).then( (jsonContent) => { - const authDetails = getValueByKey( + const { authDetails } = getValueByKey( JSON.stringify(jsonContent), connectorName ); @@ -491,12 +479,20 @@ Cypress.Commands.add( // it is best to use then() to handle the response within the same block of code cy.readFile(globalState.get("connectorAuthFilePath")).then( (jsonContent) => { - const authDetails = getValueByKey( + const { authDetails, stateUpdate } = getValueByKey( JSON.stringify(jsonContent), connector_id, extractIntegerAtEnd(profilePrefix) ); + if (stateUpdate) { + // cy.task("setGlobalState", stateUpdate); + globalState.set( + "MULTIPLE_CONNECTORS", + stateUpdate.MULTIPLE_CONNECTORS + ); + } + createConnectorBody.connector_account_details = authDetails.connector_account_details; @@ -558,7 +554,7 @@ Cypress.Commands.add( // it is best to use then() to handle the response within the same block of code cy.readFile(globalState.get("connectorAuthFilePath")).then( (jsonContent) => { - const authDetails = getValueByKey( + const { authDetails } = getValueByKey( JSON.stringify(jsonContent), `${connectorName}_payout` );