Skip to content

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

test(cypress): fix flaky VolumeBasedRouting and RuleBasedRouting tests (#12097)

HS-QUALIBOTdacc03a8b61b
diff --git a/cypress-tests/cypress/e2e/spec/Routing/00003-VolumeBasedRouting.cy.js b/cypress-tests/cypress/e2e/spec/Routing/00003-VolumeBasedRouting.cy.js
index 1f478ee187..d3b0d61896 100644
--- a/cypress-tests/cypress/e2e/spec/Routing/00003-VolumeBasedRouting.cy.js
+++ b/cypress-tests/cypress/e2e/spec/Routing/00003-VolumeBasedRouting.cy.js
@@ -301,15 +301,11 @@ describe("Volume Based Routing Test", () => {
});
it("payment-routing-test-2", () => {
- globalState.set("connectorId", "adyen");
- globalState.set("merchantConnectorId", globalState.get("adyenMcaId"));
- const data =
- utils.getConnectorDetails("adyen")["card_pm"]["No3DSAutoCapture"];
- cy.createConfirmPaymentTest(
+ // For 50/50 routing, the connector is probabilistic.
+ // We capture the actual routed connector from the response, then use it for subsequent assertions.
+ cy.createPaymentAndCaptureConnector(
fixtures.createConfirmPaymentBody,
- data,
- "no_three_ds",
- "automatic",
+ ["stripe", "adyen"],
globalState
);
});
diff --git a/cypress-tests/cypress/e2e/spec/Routing/00004-RuleBasedRouting.cy.js b/cypress-tests/cypress/e2e/spec/Routing/00004-RuleBasedRouting.cy.js
index 65f8b3ec5d..59b73211ec 100644
--- a/cypress-tests/cypress/e2e/spec/Routing/00004-RuleBasedRouting.cy.js
+++ b/cypress-tests/cypress/e2e/spec/Routing/00004-RuleBasedRouting.cy.js
@@ -162,6 +162,10 @@ describe("Rule Based Routing Test", () => {
// return_url is a static url (https://example.com) taken from confirm-body fixture and is not updated
const expected_redirection = fixtures.confirmBody["return_url"];
const payment_method_type = globalState.get("paymentMethodType");
+ // confirmBankRedirectCallTest overwrites connectorId via updateConnectorState; restore it
+ // to "adyen" here because the routing rule guarantees adyen for bank_redirect payments.
+ globalState.set("connectorId", "adyen");
+ globalState.set("merchantConnectorId", globalState.get("adyenMcaId"));
cy.handleBankRedirectRedirection(
globalState,
payment_method_type,
diff --git a/cypress-tests/cypress/support/commands.js b/cypress-tests/cypress/support/commands.js
index 7a70defeb5..27b1b87264 100644
--- a/cypress-tests/cypress/support/commands.js
+++ b/cypress-tests/cypress/support/commands.js
@@ -7239,6 +7239,46 @@ Cypress.Commands.add(
}
);
+Cypress.Commands.add(
+ "createPaymentAndCaptureConnector",
+ (createConfirmPaymentBody, allowedConnectors, globalState) => {
+ const baseUrl = globalState.get("baseUrl");
+ const apiKey = globalState.get("apiKey");
+ const profileId = globalState.get("profileId");
+ const customerId = globalState.get("customerId");
+
+ cy.request({
+ method: "POST",
+ url: `${baseUrl}/payments`,
+ headers: {
+ "Content-Type": "application/json",
+ "api-key": apiKey,
+ },
+ failOnStatusCode: false,
+ body: {
+ ...createConfirmPaymentBody,
+ profile_id: profileId,
+ customer_id: customerId,
+ },
+ }).then((response) => {
+ logRequestId(response.headers["x-request-id"]);
+ storeRequestId(response.headers["x-request-id"], globalState);
+
+ cy.wrap(response).then(() => {
+ expect(response.status).to.eq(200);
+ const actualConnector = response.body.connector;
+ expect(actualConnector).to.be.oneOf(allowedConnectors);
+
+ globalState.set("connectorId", actualConnector);
+ const mcaKey = `${actualConnector}McaId`;
+ globalState.set("merchantConnectorId", globalState.get(mcaKey));
+ globalState.set("paymentID", response.body.payment_id);
+ globalState.set("paymentAmount", response.body.amount);
+ });
+ });
+ }
+);
+
Cypress.Commands.add(
"assertNetworkTransactionId",
(globalState, shouldExist = true) => {