Skip to content

Commit

Permalink
refactor: multiple connector to support ntid stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
pixincreate committed Dec 7, 2024
1 parent b286a88 commit 9290469
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 241 deletions.
29 changes: 24 additions & 5 deletions cypress-tests/cypress/e2e/PaymentTest/00003-ConnectorCreate.cy.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as fixtures from "../../fixtures/imports";
import State from "../../utils/State";
import { payment_methods_enabled } from "../PaymentUtils/Commons";
import { createProfileAndConnector } from "../PaymentUtils/Utils";
import * as utils from "../PaymentUtils/Utils";

let globalState;
describe("Connector Account Create flow test", () => {
Expand All @@ -15,7 +15,7 @@ describe("Connector Account Create flow test", () => {
cy.task("setGlobalState", globalState.data);
});

it("connector-create-call-test", () => {
it("Create merchant connector account", () => {
cy.createConnectorCallTest(
"payment_processor",
fixtures.createConnectorBody,
Expand All @@ -25,7 +25,26 @@ describe("Connector Account Create flow test", () => {
});

// subsequent profile and mca ids should check for the existence of multiple connectors
it("check and create multiple connectors", () => {
createProfileAndConnector(fixtures, globalState, payment_methods_enabled);
});
context(
"Create another business profile and merchant connector account if MULTIPLE_CONNECTORS flag is true",
() => {
it("Create business profile", () => {
utils.createBusinessProfile(
fixtures.businessProfile.bpCreate,
globalState,
{ nextConnector: true }
);
});

it("Create merchant connector account", () => {
utils.createMerchantConnectorAccount(
"payment_processor",
fixtures.createConnectorBody,
globalState,
payment_methods_enabled,
{ nextConnector: true }
);
});
}
);
});
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,6 @@ describe("Connector Agnostic Tests", () => {
}
});

// it("Create Business Profile and Merchant connector account", () => {
// utils.createProfileAndConnector(
// fixtures,
// globalState,
// payment_methods_enabled
// );
// });

it("Create business profile", () => {
utils.createBusinessProfile(
fixtures.businessProfile.bpCreate,
Expand Down Expand Up @@ -112,28 +104,13 @@ describe("Connector Agnostic Tests", () => {
cy.listCustomerPMByClientSecret(globalState);
});

// it("Create Business Profile and Merchant connector account", () => {
// utils.createProfileAndConnector(
// fixtures,
// globalState,
// payment_methods_enabled,
// {
// flag: true,
// is_connector_agnostic_enabled: true,
// collect_billing_address_from_wallet_connector: false,
// collect_shipping_address_from_wallet_connector: false,
// always_collect_billing_address_from_wallet_connector: false,
// always_collect_shipping_address_from_wallet_connector: false,
// }
// );
// });

it("Create business profile", () => {
utils.createBusinessProfile(
fixtures.businessProfile.bpCreate,
globalState
);
});

it("Create merchant connector account", () => {
utils.createMerchantConnectorAccount(
"payment_processor",
Expand Down Expand Up @@ -214,28 +191,13 @@ describe("Connector Agnostic Tests", () => {
}
});

it("Create Business Profile and Merchant connector account", () => {
utils.createProfileAndConnector(
fixtures,
globalState,
payment_methods_enabled,
{
flag: true,
is_connector_agnostic_enabled: true,
collect_billing_address_from_wallet_connector: false,
collect_shipping_address_from_wallet_connector: false,
always_collect_billing_address_from_wallet_connector: false,
always_collect_shipping_address_from_wallet_connector: false,
}
);
});

it("Create business profile", () => {
utils.createBusinessProfile(
fixtures.businessProfile.bpCreate,
globalState
);
});

it("Create merchant connector account", () => {
utils.createMerchantConnectorAccount(
"payment_processor",
Expand Down Expand Up @@ -291,22 +253,6 @@ describe("Connector Agnostic Tests", () => {
cy.listCustomerPMByClientSecret(globalState);
});

it("Create Business Profile and Merchant connector account", () => {
utils.createProfileAndConnector(
fixtures,
globalState,
payment_methods_enabled,
{
flag: true,
is_connector_agnostic_enabled: true,
collect_billing_address_from_wallet_connector: false,
collect_shipping_address_from_wallet_connector: false,
always_collect_billing_address_from_wallet_connector: false,
always_collect_shipping_address_from_wallet_connector: false,
}
);
});

it("Create business profile", () => {
utils.createBusinessProfile(
fixtures.businessProfile.bpCreate,
Expand Down
131 changes: 26 additions & 105 deletions cypress-tests/cypress/e2e/PaymentUtils/Utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { validateConfig } from "../../utils/featureFlags.js";
import { execConfig, validateConfig } from "../../utils/featureFlags.js";

import { connectorDetails as adyenConnectorDetails } from "./Adyen.js";
import { connectorDetails as bankOfAmericaConnectorDetails } from "./BankOfAmerica.js";
Expand Down Expand Up @@ -193,101 +193,23 @@ export function extractIntegerAtEnd(str) {
return match ? parseInt(match[0], 10) : 0;
}

export function createProfileAndConnector(
fixtures,
export function createBusinessProfile(
createBusinessProfileBody,
globalState,
paymentMethodsEnabled,
businessProfileUpdate = { flag: false }
multipleConnector = { nextConnector: false }
) {
const connectorConfigs = getConnectorDetails(globalState.get("connectorId"))[
"multi_credential_config"
] || { value: "connector_1" };

// Map connector names to their config
const connectorMap = {
connector_1: { index: 0, iterations: 1 },
connector_2: { index: 1, iterations: 1 },
};

const currentConnector = connectorMap[connectorConfigs.value];

cy.task("getSharedState").then((state) => {
const multipleConnectors = state.MULTIPLE_CONNECTORS;
cy.log(`MULTIPLE_CONNECTORS: ${JSON.stringify(multipleConnectors)}`);

// If multiple connectors are enabled
if (multipleConnectors?.status) {
// Create profiles and connectors for additional connectors
// Skip index 0 since default profile/connector already exists

const i = currentConnector.index;
const profilePrefix = i === 0 ? "profile" : `profile${i}`;
const connectorPrefix =
i === 0 ? "merchantConnector" : `merchantConnector${i}`;

// Create business profile with indexed prefix
cy.createBusinessProfileTest(
fixtures.businessProfile.bpCreate,
globalState,
profilePrefix
);

// Create connector with indexed prefix
cy.createConnectorCallTest(
"payment_processor",
fixtures.createConnectorBody,
paymentMethodsEnabled,
globalState,
profilePrefix,
connectorPrefix
);

// Update business profile if needed
if (businessProfileUpdate?.flag) {
cy.UpdateBusinessProfileTest(
fixtures.businessProfile.bpUpdate,
businessProfileUpdate.is_connector_agnostic_enabled,
businessProfileUpdate.collect_billing_address_from_wallet_connector,
businessProfileUpdate.collect_shipping_address_from_wallet_connector,
businessProfileUpdate.always_collect_billing_address_from_wallet_connector,
businessProfileUpdate.always_collect_shipping_address_from_wallet_connector,
globalState,
profilePrefix
);
}
} else {
cy.log(
"Multiple connectors disabled - using default profile and connector only"
);
}
});
}

// Helper function to get connector configuration
function getConnectorConfig(globalState) {
const connectorConfigs = getConnectorDetails(globalState.get("connectorId"))[
"multi_credential_config"
] || { value: "connector_1" };

const connectorMap = {
connector_1: { index: 0, iterations: 1 },
connector_2: { index: 1, iterations: 1 },
};

return connectorMap[connectorConfigs.value];
}

export function createBusinessProfile(createBusinessProfileBody, globalState) {
cy.task("getSharedState").then((state) => {
const multipleConnectors = state.MULTIPLE_CONNECTORS;
cy.log(`MULTIPLE_CONNECTORS: ${JSON.stringify(multipleConnectors)}`);

if (multipleConnectors?.status) {
const currentConnector = getConnectorConfig(globalState);
const profilePrefix =
currentConnector.index === 0
? "profile"
: `profile${currentConnector.index}`;
// Get MCA config and determine profile prefix
const mcaConfig = getConnectorDetails(globalState.get("connectorId"));
const { profilePrefix } = execConfig({
CONNECTOR_CREDENTIAL: multipleConnector?.nextConnector
? multipleConnector
: mcaConfig?.multi_credential_config || multipleConnector,
});

cy.createBusinessProfileTest(
createBusinessProfileBody,
Expand All @@ -302,30 +224,29 @@ export function createMerchantConnectorAccount(
paymentType,
createMerchantConnectorAccountBody,
globalState,
paymentMethodsEnabled
paymentMethodsEnabled,
multipleConnector = { nextConnector: false }
) {
cy.task("getSharedState").then((state) => {
const multipleConnectors = state.MULTIPLE_CONNECTORS;
cy.log(`MULTIPLE_CONNECTORS: ${JSON.stringify(multipleConnectors)}`);

if (multipleConnectors?.status) {
const currentConnector = getConnectorConfig(globalState);
const profilePrefix =
currentConnector.index === 0
? "profile"
: `profile${currentConnector.index}`;
const connectorPrefix =
currentConnector.index === 0
? "merchantConnector"
: `merchantConnector${currentConnector.index}`;
// Get MCA config
const mcaConfig = getConnectorDetails(globalState.get("connectorId"));
const { profilePrefix, merchantConnectorPrefix } = execConfig({
CONNECTOR_CREDENTIAL: multipleConnector?.nextConnector
? multipleConnector
: mcaConfig?.multi_credential_config || multipleConnector,
});

cy.createConnectorCallTest(
paymentType,
createMerchantConnectorAccountBody,
paymentMethodsEnabled,
globalState,
profilePrefix,
connectorPrefix
merchantConnectorPrefix
);
}
});
Expand All @@ -345,11 +266,11 @@ export function updateBusinessProfile(
cy.log(`MULTIPLE_CONNECTORS: ${JSON.stringify(multipleConnectors)}`);

if (multipleConnectors?.status) {
const currentConnector = getConnectorConfig(globalState);
const profilePrefix =
currentConnector.index === 0
? "profile"
: `profile${currentConnector.index}`;
// Get MCA config and determine profile prefix
const mcaConfig = getConnectorDetails(globalState.get("connectorId"));
const { profilePrefix } = execConfig({
CONNECTOR_CREDENTIAL: mcaConfig?.multi_credential_config,
});

cy.UpdateBusinessProfileTest(
updateBusinessProfileBody,
Expand Down
Loading

0 comments on commit 9290469

Please sign in to comment.