Skip to content

Commit

Permalink
fix: globalState for multiple connectors
Browse files Browse the repository at this point in the history
  • Loading branch information
pixincreate committed Dec 17, 2024
1 parent fb584f0 commit 6c170a6
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 22 deletions.
34 changes: 27 additions & 7 deletions cypress-tests/cypress/e2e/PaymentUtils/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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) => {
Expand Down
26 changes: 11 additions & 15 deletions cypress-tests/cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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
);
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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`
);
Expand Down

0 comments on commit 6c170a6

Please sign in to comment.