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
feat(platform): add cypress tests for platform (#11405)
Ankit Kumar Guptaf07518ff9d10
diff --git a/cypress-tests/cypress/e2e/spec/Platform/00001-PlatformSetup.cy.js b/cypress-tests/cypress/e2e/spec/Platform/00001-PlatformSetup.cy.jsnew file mode 100644index 0000000000..797ad98577--- /dev/null+++ b/cypress-tests/cypress/e2e/spec/Platform/00001-PlatformSetup.cy.js@@ -0,0 +1,204 @@+import * as fixtures from "../../../fixtures/imports";+import State from "../../../utils/State";++let globalState;++describe("Platform Setup & Connected Merchant Onboarding", () => {+ before("seed global state", () => {+ cy.task("getGlobalState").then((state) => {+ globalState = new State(state);+ });+ });++ after("flush global state", () => {+ cy.task("setGlobalState", globalState.data);+ });++ context("Create Platform Merchant", () => {+ it("create-platform-merchant", () => {+ const merchantCreateBody = {+ ...fixtures.merchantCreateBody,+ merchant_account_type: "platform",+ };++ cy.merchantCreateCallTest(merchantCreateBody, globalState, {+ expectedMerchantAccountType: "platform",+ });+ cy.then(() => {+ globalState.set("platformMerchantId", globalState.get("merchantId"));+ });+ });++ it("retrieve-platform-merchant", () => {+ cy.merchantRetrieveCall(globalState);+ });++ it("create-api-key-for-platform-merchant", () => {+ cy.apiKeyCreateTest(fixtures.apiKeyCreateBody, globalState);+ });+ });++ context("Create Connected Merchant 1", () => {+ it("create-connected-merchant-1", () => {+ const merchantCreateBody = {+ ...fixtures.merchantCreateBody,+ merchant_account_type: "connected",+ merchant_id: `cypress_connected_merchant_1_${Date.now()}`,+ merchant_name: "Connected Merchant 1",+ organization_id: globalState.get("organizationId"),+ };++ cy.merchantCreateCallTest(merchantCreateBody, globalState, {+ expectedMerchantAccountType: "connected",+ merchantIdStateKey: "connectedMerchantId1",+ profileIdStateKey: "profileIdCm1",+ });+ });++ it("create-api-key-for-connected-merchant-1", () => {+ const savedMerchantId = globalState.get("merchantId");+ const savedApiKey = globalState.get("apiKey");+ globalState.set("merchantId", globalState.get("connectedMerchantId1"));++ cy.apiKeyCreateTest(fixtures.apiKeyCreateBody, globalState);++ cy.then(() => {+ globalState.set("apiKeyCm1", globalState.get("apiKey"));+ globalState.set("merchantId", savedMerchantId);+ globalState.set("apiKey", savedApiKey);+ });+ });+ });++ context("Create Connected Merchant 2 using Platform API Key", () => {+ it("create-connected-merchant-2-using-platform-api-key", () => {+ const savedAdminApiKey = globalState.get("adminApiKey");+ globalState.set("adminApiKey", globalState.get("apiKey"));++ const merchantCreateBody = {+ ...fixtures.merchantCreateBody,+ merchant_account_type: "connected",+ merchant_id: `cypress_connected_merchant_2_${Date.now()}`,+ merchant_name: "Connected Merchant 2",+ organization_id: globalState.get("organizationId"),+ };++ cy.merchantCreateCallTest(merchantCreateBody, globalState, {+ expectedMerchantAccountType: "connected",+ merchantIdStateKey: "connectedMerchantId2",+ profileIdStateKey: "profileIdCm2",+ });++ cy.then(() => {+ globalState.set("adminApiKey", savedAdminApiKey);+ });+ });++ it("create-api-key-for-connected-merchant-2-platform-key", () => {+ const savedMerchantId = globalState.get("merchantId");+ const savedApiKey = globalState.get("apiKey");+ const savedAdminApiKey = globalState.get("adminApiKey");+ globalState.set("merchantId", globalState.get("connectedMerchantId2"));+ globalState.set("adminApiKey", savedApiKey);++ cy.apiKeyCreateTest(fixtures.apiKeyCreateBody, globalState);++ cy.then(() => {+ globalState.set("apiKeyCm2", globalState.get("apiKey"));+ globalState.set("merchantId", savedMerchantId);+ globalState.set("apiKey", savedApiKey);+ globalState.set("adminApiKey", savedAdminApiKey);+ });+ });+ });++ context("Create Standard Merchant", () => {+ it("create-standard-merchant", () => {+ const merchantCreateBody = {+ ...fixtures.merchantCreateBody,+ merchant_id: `cypress_standard_merchant_${Date.now()}`,+ merchant_name: "Standard Merchant",+ organization_id: globalState.get("organizationId"),+ };++ cy.merchantCreateCallTest(merchantCreateBody, globalState, {+ expectedMerchantAccountType: "standard",+ merchantIdStateKey: "standardMerchantId",+ profileIdStateKey: "profileIdSm",+ });+ });++ it("create-api-key-for-standard-merchant", () => {+ const savedMerchantId = globalState.get("merchantId");+ const savedApiKey = globalState.get("apiKey");+ globalState.set("merchantId", globalState.get("standardMerchantId"));++ cy.apiKeyCreateTest(fixtures.apiKeyCreateBody, globalState);++ cy.then(() => {+ globalState.set("apiKeySm", globalState.get("apiKey"));+ globalState.set("merchantId", savedMerchantId);+ globalState.set("apiKey", savedApiKey);+ });+ });+ });++ context("Create Standard Merchant using Platform API Key", () => {+ it("create-standard-merchant-using-platform-api-key", () => {+ const savedAdminApiKey = globalState.get("adminApiKey");+ globalState.set("adminApiKey", globalState.get("apiKey"));++ const merchantCreateBody = {+ ...fixtures.merchantCreateBody,+ merchant_id: `cypress_standard_merchant_platform_${Date.now()}`,+ merchant_name: "Standard Merchant (Platform Key)",+ organization_id: globalState.get("organizationId"),+ };++ cy.merchantCreateCallTest(merchantCreateBody, globalState, {+ expectedMerchantAccountType: "standard",+ merchantIdStateKey: "standardMerchantIdPlatformKey",+ profileIdStateKey: "profileIdSmPlatformKey",+ });++ cy.then(() => {+ globalState.set("adminApiKey", savedAdminApiKey);+ });+ });++ it("create-api-key-for-standard-merchant-platform-key", () => {+ const savedMerchantId = globalState.get("merchantId");+ const savedApiKey = globalState.get("apiKey");+ const savedAdminApiKey = globalState.get("adminApiKey");+ globalState.set(+ "merchantId",+ globalState.get("standardMerchantIdPlatformKey")+ );+ globalState.set("adminApiKey", savedApiKey);++ cy.apiKeyCreateTest(fixtures.apiKeyCreateBody, globalState);++ cy.then(() => {+ globalState.set("apiKeySmPlatformKey", globalState.get("apiKey"));+ globalState.set("merchantId", savedMerchantId);+ globalState.set("apiKey", savedApiKey);+ globalState.set("adminApiKey", savedAdminApiKey);+ });+ });+ });++ context("Verify Merchants in Organization", () => {+ it("list-merchants-includes-all-merchants", () => {+ cy.merchantListByOrgCall(globalState, [+ { merchantIdKey: "platformMerchantId", expectedType: "platform" },+ { merchantIdKey: "connectedMerchantId1", expectedType: "connected" },+ { merchantIdKey: "connectedMerchantId2", expectedType: "connected" },+ { merchantIdKey: "standardMerchantId", expectedType: "standard" },+ {+ merchantIdKey: "standardMerchantIdPlatformKey",+ expectedType: "standard",+ },+ ]);+ });+ });+});diff --git a/cypress-tests/cypress/e2e/spec/Platform/00002-ProfileSetup.cy.js b/cypress-tests/cypress/e2e/spec/Platform/00002-ProfileSetup.cy.jsnew file mode 100644index 0000000000..690a4f5039--- /dev/null+++ b/cypress-tests/cypress/e2e/spec/Platform/00002-ProfileSetup.cy.js@@ -0,0 +1,114 @@+import * as fixtures from "../../../fixtures/imports";+import State from "../../../utils/State";++let globalState;++describe("Profile Setup for Merchants", () => {+ before("seed global state", () => {+ cy.task("getGlobalState").then((state) => {+ globalState = new State(state);+ });+ });++ after("flush global state", () => {+ cy.task("setGlobalState", globalState.data);+ });++ context("Platform Merchant Cannot Create Profile For Self", () => {+ it("platform-merchant-cannot-create-profile-for-self", () => {+ const savedMerchantId = globalState.get("merchantId");+ globalState.set("merchantId", globalState.get("platformMerchantId"));++ cy.createBusinessProfileTest(+ fixtures.businessProfile.bpCreate,+ globalState,+ "profile", // profilePrefix+ 400 // expectedStatus+ );++ cy.then(() => {+ globalState.set("merchantId", savedMerchantId);+ });+ });+ });++ context("Connected Merchant 1 Creates Profile", () => {+ it("cm1-creates-profile", () => {+ const savedMerchantId = globalState.get("merchantId");+ const savedApiKey = globalState.get("apiKey");++ globalState.set("merchantId", globalState.get("connectedMerchantId1"));+ globalState.set("apiKey", globalState.get("apiKeyCm1"));++ cy.createBusinessProfileTest(+ fixtures.businessProfile.bpCreate,+ globalState+ );++ cy.then(() => {+ globalState.set("profileIdCm1New", globalState.get("profileId"));+ globalState.set("merchantId", savedMerchantId);+ globalState.set("apiKey", savedApiKey);+ });+ });+ });++ context("Platform Creates Profile For Connected Merchant 2", () => {+ it("platform-creates-profile-for-cm2", () => {+ const savedMerchantId = globalState.get("merchantId");+ globalState.set("merchantId", globalState.get("connectedMerchantId2"));++ cy.createBusinessProfileWithHeaderCall(+ fixtures.businessProfile.bpCreate,+ globalState.get("apiKey"),+ globalState.get("connectedMerchantId2"),+ globalState,+ 200,+ "profileIdCm2New"+ );++ cy.then(() => {+ globalState.set("merchantId", savedMerchantId);+ });+ });+ });++ context("Platform Cannot Create Profile For Standard Merchant", () => {+ it("platform-cannot-create-profile-for-standard-merchant", () => {+ const savedMerchantId = globalState.get("merchantId");+ globalState.set("merchantId", globalState.get("standardMerchantId"));++ cy.createBusinessProfileTest(+ fixtures.businessProfile.bpCreate,+ globalState,+ "profile", // profilePrefix+ 400 // expectedStatus+ );++ cy.then(() => {+ globalState.set("merchantId", savedMerchantId);+ });+ });+ });++ context("Standard Merchant Creates Profile", () => {+ it("standard-merchant-creates-profile", () => {+ const savedMerchantId = globalState.get("merchantId");+ const savedApiKey = globalState.get("apiKey");++ globalState.set("merchantId", globalState.get("standardMerchantId"));+ globalState.set("apiKey", globalState.get("apiKeySm"));++ cy.createBusinessProfileTest(+ fixtures.businessProfile.bpCreate,+ globalState+ );++ cy.then(() => {+ globalState.set("profileIdSmNew", globalState.get("profileId"));+ globalState.set("merchantId", savedMerchantId);+ globalState.set("apiKey", savedApiKey);+ });+ });+ });+});diff --git a/cypress-tests/cypress/e2e/spec/Platform/00003-ConnectorSetup.cy.js b/cypress-tests/cypress/e2e/spec/Platform/00003-ConnectorSetup.cy.jsnew file mode 100644index 0000000000..f2d5be9d6b--- /dev/null+++ b/cypress-tests/cypress/e2e/spec/Platform/00003-ConnectorSetup.cy.js@@ -0,0 +1,257 @@+import * as fixtures from "../../../fixtures/imports";+import State from "../../../utils/State";+import { payment_methods_enabled } from "../../configs/Payment/Commons";++let globalState;++describe("Connector Setup for Connected Merchants", () => {+ before("seed global state", () => {+ cy.task("getGlobalState").then((state) => {+ globalState = new State(state);+ });+ });++ after("flush global state", () => {+ cy.task("setGlobalState", globalState.data);+ });++ context("Create Connector for Connected Merchant 1", () => {+ it("create-connector-for-cm1", () => {+ const savedMerchantId = globalState.get("merchantId");+ const savedApiKey = globalState.get("apiKey");+ const savedProfileId = globalState.get("profileId");++ globalState.set("merchantId", globalState.get("connectedMerchantId1"));+ globalState.set("apiKey", globalState.get("apiKeyCm1"));+ globalState.set("profileId", globalState.get("profileIdCm1"));++ cy.createConnectorCallTest(+ "payment_processor",+ fixtures.createConnectorBody,+ payment_methods_enabled,+ globalState+ );++ cy.then(() => {+ globalState.set(+ "connectorIdCm1",+ globalState.get("merchantConnectorId")+ );+ globalState.set("merchantId", savedMerchantId);+ globalState.set("apiKey", savedApiKey);+ globalState.set("profileId", savedProfileId);+ });+ });++ it("retrieve-connector-for-cm1", () => {+ const savedMerchantId = globalState.get("merchantId");+ const savedApiKey = globalState.get("apiKey");+ const savedMerchantConnectorId = globalState.get("merchantConnectorId");++ globalState.set("merchantId", globalState.get("connectedMerchantId1"));+ globalState.set("apiKey", globalState.get("apiKeyCm1"));+ globalState.set("merchantConnectorId", globalState.get("connectorIdCm1"));++ cy.connectorRetrieveCall(globalState);++ cy.then(() => {+ globalState.set("merchantId", savedMerchantId);+ globalState.set("apiKey", savedApiKey);+ globalState.set("merchantConnectorId", savedMerchantConnectorId);+ });+ });+ });++ context("Create Connector for Connected Merchant 2", () => {+ it("create-connector-for-cm2", () => {+ const savedMerchantId = globalState.get("merchantId");+ const savedApiKey = globalState.get("apiKey");+ const savedProfileId = globalState.get("profileId");++ globalState.set("merchantId", globalState.get("connectedMerchantId2"));+ globalState.set("apiKey", globalState.get("apiKeyCm2"));+ globalState.set("profileId", globalState.get("profileIdCm2"));++ cy.createConnectorCallTest(+ "payment_processor",+ fixtures.createConnectorBody,+ payment_methods_enabled,+ globalState+ );++ cy.then(() => {+ globalState.set(+ "connectorIdCm2",+ globalState.get("merchantConnectorId")+ );+ globalState.set("merchantId", savedMerchantId);+ globalState.set("apiKey", savedApiKey);+ globalState.set("profileId", savedProfileId);+ });+ });++ it("retrieve-connector-for-cm2", () => {+ const savedMerchantId = globalState.get("merchantId");+ const savedApiKey = globalState.get("apiKey");+ const savedMerchantConnectorId = globalState.get("merchantConnectorId");++ globalState.set("merchantId", globalState.get("connectedMerchantId2"));+ globalState.set("apiKey", globalState.get("apiKeyCm2"));+ globalState.set("merchantConnectorId", globalState.get("connectorIdCm2"));++ cy.connectorRetrieveCall(globalState);++ cy.then(() => {+ globalState.set("merchantId", savedMerchantId);+ globalState.set("apiKey", savedApiKey);+ globalState.set("merchantConnectorId", savedMerchantConnectorId);+ });+ });+ });++ context("Create Connector for Standard Merchant", () => {+ it("create-connector-for-standard-merchant", () => {+ const savedMerchantId = globalState.get("merchantId");+ const savedApiKey = globalState.get("apiKey");+ const savedProfileId = globalState.get("profileId");++ globalState.set("merchantId", globalState.get("standardMerchantId"));+ globalState.set("apiKey", globalState.get("apiKeySm"));+ globalState.set("profileId", globalState.get("profileIdSm"));++ cy.createConnectorCallTest(+ "payment_processor",+ fixtures.createConnectorBody,+ payment_methods_enabled,+ globalState+ );++ cy.then(() => {+ globalState.set(+ "connectorIdSm",+ globalState.get("merchantConnectorId")+ );+ globalState.set("merchantId", savedMerchantId);+ globalState.set("apiKey", savedApiKey);+ globalState.set("profileId", savedProfileId);+ });+ });++ it("retrieve-connector-for-standard-merchant", () => {+ const savedMerchantId = globalState.get("merchantId");+ const savedApiKey = globalState.get("apiKey");+ const savedMerchantConnectorId = globalState.get("merchantConnectorId");++ globalState.set("merchantId", globalState.get("standardMerchantId"));+ globalState.set("apiKey", globalState.get("apiKeySm"));+ globalState.set("merchantConnectorId", globalState.get("connectorIdSm"));++ cy.connectorRetrieveCall(globalState);++ cy.then(() => {+ globalState.set("merchantId", savedMerchantId);+ globalState.set("apiKey", savedApiKey);+ globalState.set("merchantConnectorId", savedMerchantConnectorId);+ });+ });+ });++ context("Platform Creates Connector for Connected Merchant 1", () => {+ it("platform-create-connector-for-cm1", () => {+ const savedMerchantId = globalState.get("merchantId");++ globalState.set("merchantId", globalState.get("connectedMerchantId1"));++ const connectorId = globalState.get("connectorId");++ cy.createConnectorWithHeaderCall(+ {+ connector_type: "payment_processor",+ connector_name: connectorId,+ connector_label: `${connectorId}_platform_for_cm1`,+ ...fixtures.createConnectorBody,+ payment_methods_enabled,+ profile_id: globalState.get("profileIdCm1"),+ },+ globalState.get("apiKey"),+ globalState.get("connectedMerchantId1"),+ globalState,+ 200+ );++ cy.then(() => {+ globalState.set("merchantId", savedMerchantId);+ });+ });+ });++ context("Verify Connectors Are Separate", () => {+ it("verify-cm1-and-cm2-have-different-connectors", () => {+ const connectorIdCm1 = globalState.get("connectorIdCm1");+ const connectorIdCm2 = globalState.get("connectorIdCm2");++ expect(connectorIdCm1).to.not.equal(connectorIdCm2);+ });+ });++ context("Platform Cannot Create Connector for Standard Merchant", () => {+ it("platform-cannot-create-connector-for-standard-merchant", () => {+ const savedMerchantId = globalState.get("merchantId");++ globalState.set("merchantId", globalState.get("standardMerchantId"));++ const connectorId = globalState.get("connectorId");++ cy.createConnectorWithHeaderCall(+ {+ connector_type: "payment_processor",+ connector_name: connectorId,+ connector_label: `${connectorId}_platform_for_sm`,+ ...fixtures.createConnectorBody,+ payment_methods_enabled,+ profile_id: globalState.get("profileIdSm"),+ },+ globalState.get("apiKey"),+ globalState.get("standardMerchantId"),+ globalState,+ 401+ );++ cy.then(() => {+ globalState.set("merchantId", savedMerchantId);+ });+ });+ });++ context("Platform Merchant Cannot Create Connector", () => {+ it("platform-merchant-cannot-create-connector", () => {+ const savedMerchantId = globalState.get("merchantId");+ const savedProfileId = globalState.get("profileId");++ globalState.set("merchantId", globalState.get("platformMerchantId"));+ globalState.set("profileId", globalState.get("profileId"));++ const connectorId = globalState.get("connectorId");++ cy.createConnectorCallTest(+ "payment_processor",+ {+ connector_name: connectorId,+ connector_label: `${connectorId}_platform_test`,+ ...fixtures.createConnectorBody,+ payment_methods_enabled,+ }, // createConnectorBody+ payment_methods_enabled,+ globalState,+ "profile", // profilePrefix+ "merchantConnector", // mcaPrefix+ 400 // expectedStatus+ );++ cy.then(() => {+ globalState.set("merchantId", savedMerchantId);+ globalState.set("profileId", savedProfileId);+ });+ });+ });+});diff --git a/cypress-tests/cypress/e2e/spec/Platform/00004-CustomerFlows.cy.js b/cypress-tests/cypress/e2e/spec/Platform/00004-CustomerFlows.cy.jsnew file mode 100644index 0000000000..98d8421870--- /dev/null+++ b/cypress-tests/cypress/e2e/spec/Platform/00004-CustomerFlows.cy.js@@ -0,0 +1,177 @@+import * as fixtures from "../../../fixtures/imports";+import State from "../../../utils/State";++let globalState;++describe("Platform Customer Flows", () => {+ before("seed global state", () => {+ cy.task("getGlobalState").then((state) => {+ globalState = new State(state);+ });+ });++ after("flush global state", () => {+ globalState.set("customerId", globalState.get("customerIdCm1Created"));+ cy.task("setGlobalState", globalState.data);+ });++ context("Shared Customer Across Connected Merchants", () => {+ it("create-shared-customer-using-platform-merchant", () => {+ cy.createCustomerCallTest(fixtures.customerCreateBody, globalState);+ });++ it("verify-connected-merchant-1-can-access-shared-customer", () => {+ const savedApiKey = globalState.get("apiKey");+ globalState.set("apiKey", globalState.get("apiKeyCm1"));++ cy.customerRetrieveCall(globalState);++ cy.then(() => {+ globalState.set("apiKey", savedApiKey);+ });+ });++ it("verify-connected-merchant-2-can-access-shared-customer", () => {+ const savedApiKey = globalState.get("apiKey");+ globalState.set("apiKey", globalState.get("apiKeyCm2"));++ cy.customerRetrieveCall(globalState);++ cy.then(() => {+ globalState.set("apiKey", savedApiKey);+ });+ });+ });++ context("CM1 Creates Customer - Accessible by CM2 and Platform", () => {+ it("cm1-creates-customer", () => {+ const savedApiKey = globalState.get("apiKey");+ const savedMerchantId = globalState.get("merchantId");+ globalState.set("apiKey", globalState.get("apiKeyCm1"));+ globalState.set("merchantId", globalState.get("connectedMerchantId1"));++ cy.createCustomerCallTest(fixtures.customerCreateBody, globalState);++ cy.then(() => {+ globalState.set("customerIdCm1Created", globalState.get("customerId"));+ globalState.set("apiKey", savedApiKey);+ globalState.set("merchantId", savedMerchantId);+ });+ });++ it("verify-connected-merchant-2-can-access-cm1-customer", () => {+ const savedApiKey = globalState.get("apiKey");+ const savedCustomerId = globalState.get("customerId");+ globalState.set("apiKey", globalState.get("apiKeyCm2"));+ globalState.set("customerId", globalState.get("customerIdCm1Created"));++ cy.customerRetrieveCall(globalState);++ cy.then(() => {+ globalState.set("apiKey", savedApiKey);+ globalState.set("customerId", savedCustomerId);+ });+ });++ it("verify-platform-merchant-can-access-cm1-customer", () => {+ const savedApiKey = globalState.get("apiKey");+ const savedCustomerId = globalState.get("customerId");+ globalState.set("customerId", globalState.get("customerIdCm1Created"));++ cy.customerRetrieveCall(globalState);++ cy.then(() => {+ globalState.set("apiKey", savedApiKey);+ globalState.set("customerId", savedCustomerId);+ });+ });+ });++ context("Standard Merchant Cannot Access Shared Customer", () => {+ it("standard-merchant-cannot-retrieve-shared-customer", () => {+ const savedApiKey = globalState.get("apiKey");+ globalState.set("apiKey", globalState.get("apiKeySm"));++ cy.customerRetrieveCall(globalState, 404);++ cy.then(() => {+ globalState.set("apiKey", savedApiKey);+ });+ });+ });++ context(+ "Standard Merchant Creates Customer - Only Accessible by Standard",+ () => {+ it("standard-merchant-creates-customer", () => {+ const savedApiKey = globalState.get("apiKey");+ const savedMerchantId = globalState.get("merchantId");+ globalState.set("apiKey", globalState.get("apiKeySm"));+ globalState.set("merchantId", globalState.get("standardMerchantId"));++ cy.createCustomerCallTest(fixtures.customerCreateBody, globalState);++ cy.then(() => {+ globalState.set("customerIdSmCreated", globalState.get("customerId"));+ globalState.set("apiKey", savedApiKey);+ globalState.set("merchantId", savedMerchantId);+ });+ });++ it("verify-platform-merchant-cannot-access-standard-customer", () => {+ const savedApiKey = globalState.get("apiKey");+ const savedCustomerId = globalState.get("customerId");+ globalState.set("customerId", globalState.get("customerIdSmCreated"));++ cy.customerRetrieveCall(globalState, 404);++ cy.then(() => {+ globalState.set("apiKey", savedApiKey);+ globalState.set("customerId", savedCustomerId);+ });+ });++ it("verify-connected-merchant-1-cannot-access-standard-customer", () => {+ const savedApiKey = globalState.get("apiKey");+ const savedCustomerId = globalState.get("customerId");+ globalState.set("apiKey", globalState.get("apiKeyCm1"));+ globalState.set("customerId", globalState.get("customerIdSmCreated"));++ cy.customerRetrieveCall(globalState, 404);++ cy.then(() => {+ globalState.set("apiKey", savedApiKey);+ globalState.set("customerId", savedCustomerId);+ });+ });++ it("verify-connected-merchant-2-cannot-access-standard-customer", () => {+ const savedApiKey = globalState.get("apiKey");+ const savedCustomerId = globalState.get("customerId");+ globalState.set("apiKey", globalState.get("apiKeyCm2"));+ globalState.set("customerId", globalState.get("customerIdSmCreated"));++ cy.customerRetrieveCall(globalState, 404);++ cy.then(() => {+ globalState.set("apiKey", savedApiKey);+ globalState.set("customerId", savedCustomerId);+ });+ });++ it("verify-standard-merchant-can-access-its-own-customer", () => {+ const savedApiKey = globalState.get("apiKey");+ const savedCustomerId = globalState.get("customerId");+ globalState.set("apiKey", globalState.get("apiKeySm"));+ globalState.set("customerId", globalState.get("customerIdSmCreated"));++ cy.customerRetrieveCall(globalState);++ cy.then(() => {+ globalState.set("apiKey", savedApiKey);+ globalState.set("customerId", savedCustomerId);+ });+ });+ }+ );+});diff --git a/cypress-tests/cypress/e2e/spec/Platform/00005-PaymentFlows.cy.js b/cypress-tests/cypress/e2e/spec/Platform/00005-PaymentFlows.cy.jsnew file mode 100644index 0000000000..711b93c978--- /dev/null+++ b/cypress-tests/cypress/e2e/spec/Platform/00005-PaymentFlows.cy.js@@ -0,0 +1,145 @@+import * as fixtures from "../../../fixtures/imports";+import State from "../../../utils/State";+import getConnectorDetails from "../../configs/Payment/Utils";++let globalState;++describe("Platform Payment Flows", () => {+ before("seed global state", () => {+ cy.task("getGlobalState").then((state) => {+ globalState = new State(state);+ });+ });++ after("flush global state", () => {+ cy.task("setGlobalState", globalState.data);+ });++ context("Platform Acts On Behalf Of Connected Merchants", () => {+ it("platform-creates-payment-for-cm1-using-header", () => {+ const paymentRequestBody = {+ ...fixtures.createConfirmPaymentBody,+ profile_id: globalState.get("profileIdCm1"),+ customer_id: globalState.get("customerIdCm1Created"),+ };++ cy.createPaymentWithHeaderCall(+ paymentRequestBody,+ globalState.get("apiKey"),+ globalState.get("connectedMerchantId1"),+ globalState,+ 200,+ "platformPaymentIdCm1"+ );+ });++ it("platform-creates-payment-for-cm2-using-header", () => {+ const paymentRequestBody = {+ ...fixtures.createConfirmPaymentBody,+ profile_id: globalState.get("profileIdCm2"),+ customer_id: globalState.get("customerIdCm1Created"),+ };++ cy.createPaymentWithHeaderCall(+ paymentRequestBody,+ globalState.get("apiKey"),+ globalState.get("connectedMerchantId2"),+ globalState,+ 200,+ "platformPaymentIdCm2"+ );+ });+ });++ context("Platform Cannot Create Payment For Standard Merchant", () => {+ it("platform-cannot-create-payment-for-standard-merchant", () => {+ const paymentRequestBody = {+ ...fixtures.createConfirmPaymentBody,+ profile_id: globalState.get("profileIdSm"),+ };++ cy.createPaymentWithHeaderCall(+ paymentRequestBody,+ globalState.get("apiKey"),+ globalState.get("standardMerchantId"),+ globalState,+ 401+ );+ });+ });++ context("Connected Merchants Create Own Payments", () => {+ it("cm1-creates-payment-for-shared-customer", () => {+ globalState.set("apiKey", globalState.get("apiKeyCm1"));+ globalState.set("customerId", globalState.get("customerIdCm1Created"));+ globalState.set("profileId", globalState.get("profileIdCm1"));+ globalState.set("merchantConnectorId", globalState.get("connectorIdCm1"));++ const data = getConnectorDetails(globalState.get("connectorId"))[+ "card_pm"+ ]["No3DSAutoCapture"];++ cy.createConfirmPaymentTest(+ fixtures.createConfirmPaymentBody,+ data,+ "no_three_ds",+ "automatic",+ globalState+ );+ });++ it("cm2-creates-payment-for-same-shared-customer", () => {+ globalState.set("apiKey", globalState.get("apiKeyCm2"));+ globalState.set("customerId", globalState.get("customerIdCm1Created"));+ globalState.set("profileId", globalState.get("profileIdCm2"));+ globalState.set("merchantConnectorId", globalState.get("connectorIdCm2"));++ const data = getConnectorDetails(globalState.get("connectorId"))[+ "card_pm"+ ]["No3DSAutoCapture"];++ cy.createConfirmPaymentTest(+ fixtures.createConfirmPaymentBody,+ data,+ "no_three_ds",+ "automatic",+ globalState+ );+ });+ });++ context("Connected Merchant Cannot Act On Behalf Of Another Merchant", () => {+ it("connected-merchant-cannot-act-on-behalf-of-another-merchant", () => {+ const paymentRequestBody = {+ ...fixtures.createConfirmPaymentBody,+ customer_id: globalState.get("customerIdCm1Created"),+ };++ cy.createPaymentWithHeaderCall(+ paymentRequestBody,+ globalState.get("apiKeyCm1"),+ globalState.get("connectedMerchantId2"),+ globalState,+ 401+ );+ });+ });++ context("Payment List Isolation", () => {+ it("cm1-lists-only-own-payments", () => {+ cy.listPaymentsWithApiKeyCall(+ globalState.get("apiKeyCm1"),+ globalState,+ "cm2PaymentId"+ );+ });++ it("cm2-lists-only-own-payments", () => {+ cy.listPaymentsWithApiKeyCall(+ globalState.get("apiKeyCm2"),+ globalState,+ "cm1PaymentId"+ );+ });+ });+});diff --git a/cypress-tests/cypress/support/commands.js b/cypress-tests/cypress/support/commands.jsindex 8efe6adcd7..a1bbbca32e 100644--- a/cypress-tests/cypress/support/commands.js+++ b/cypress-tests/cypress/support/commands.js@@ -458,10 +458,16 @@ Cypress.Commands.add("healthCheck", (globalState) => {Cypress.Commands.add("merchantCreateCallTest",- (merchantCreateBody, globalState) => {- const randomMerchantId = RequestBodyUtils.generateRandomString();- RequestBodyUtils.setMerchantId(merchantCreateBody, randomMerchantId);- globalState.set("merchantId", randomMerchantId);+ (merchantCreateBody, globalState, options = {}) => {+ const {+ expectedMerchantAccountType = null,+ merchantIdStateKey = "merchantId",+ profileIdStateKey = "profileId",+ } = options;++ const merchantId = RequestBodyUtils.generateRandomString();+ RequestBodyUtils.setMerchantId(merchantCreateBody, merchantId);+ globalState.set(merchantIdStateKey, merchantId);cy.request({method: "POST",@@ -476,8 +482,14 @@ Cypress.Commands.add(logRequestId(response.headers["x-request-id"]);cy.wrap(response).then(() => {- // Handle the response as needed- globalState.set("profileId", response.body.default_profile);+ if (expectedMerchantAccountType) {+ expect(response.body).to.have.property(+ "merchant_account_type",+ expectedMerchantAccountType+ );+ }++ globalState.set(profileIdStateKey, response.body.default_profile);globalState.set("publishableKey", response.body.publishable_key);globalState.set("merchantDetails", response.body.merchant_details);globalState.set("organizationId", response.body.organization_id);@@ -630,15 +642,22 @@ Cypress.Commands.add(Cypress.Commands.add("createBusinessProfileTest",- (createBusinessProfile, globalState, profilePrefix = "profile") => {+ (+ createBusinessProfile,+ globalState,+ profilePrefix = "profile",+ expectedStatus = 200+ ) => {const apiKey = globalState.get("apiKey");const baseUrl = globalState.get("baseUrl");const connectorId = globalState.get("connectorId");const merchantId = globalState.get("merchantId");- const profileName = `${profilePrefix}_${RequestBodyUtils.generateRandomString(connectorId)}`;const url = `${baseUrl}/account/${merchantId}/business_profile`;- createBusinessProfile.profile_name = profileName;+ if (expectedStatus === 200) {+ const profileName = `${profilePrefix}_${RequestBodyUtils.generateRandomString(connectorId)}`;+ createBusinessProfile.profile_name = profileName;+ }cy.request({method: "POST",@@ -654,13 +673,18 @@ Cypress.Commands.add(logRequestId(response.headers["x-request-id"]);cy.wrap(response).then(() => {- globalState.set(`${profilePrefix}Id`, response.body.profile_id);- if (response.status === 200) {- expect(response.body.profile_id).to.not.to.be.null;+ // Validate response when success is expected otherwise assert the expected status+ if (expectedStatus === 200) {+ if (response.status === 200) {+ globalState.set(`${profilePrefix}Id`, response.body.profile_id);+ expect(response.body.profile_id).to.not.to.be.null;+ } else {+ throw new Error(+ `Business Profile call failed ${response.body.error.message}`+ );+ }} else {- throw new Error(- `Business Profile call failed ${response.body.error.message}`- );+ expect(response.status).to.equal(expectedStatus);}});});@@ -982,9 +1006,10 @@ Cypress.Commands.add(payment_methods_enabled,globalState,profilePrefix = "profile",- mcaPrefix = "merchantConnector"+ mcaPrefix = "merchantConnector",+ expectedStatus = 200) => {- const api_key = globalState.get("apiKey");+ const apiKey = globalState.get("apiKey");const base_url = globalState.get("baseUrl");const connector_id = globalState.get("connectorId");const merchant_id = globalState.get("merchantId");@@ -1029,7 +1054,7 @@ Cypress.Commands.add(headers: {Accept: "application/json","Content-Type": "application/json",- "api-key": api_key,+ "api-key": apiKey,},body: createConnectorBody,failOnStatusCode: false,@@ -1037,23 +1062,28 @@ Cypress.Commands.add(logRequestId(response.headers["x-request-id"]);cy.wrap(response).then(() => {- if (response.status === 200) {- expect(globalState.get("connectorId")).to.equal(- response.body.connector_name- );- globalState.set(- `${mcaPrefix}Id`,- response.body.merchant_connector_id- );- } else {- cy.task(- "cli_log",- "response status -> " + JSON.stringify(response.status)- );+ // Validate response when success is expected otherwise assert the expected status+ if (expectedStatus === 200) {+ if (response.status === 200) {+ expect(globalState.get("connectorId")).to.equal(+ response.body.connector_name+ );+ globalState.set(+ `${mcaPrefix}Id`,+ response.body.merchant_connector_id+ );+ } else {+ cy.task(+ "cli_log",+ "response status -> " + JSON.stringify(response.status)+ );- throw new Error(- `Connector Create Call Failed ${response.body.error.message}`- );+ throw new Error(+ `Connector Create Call Failed ${response.body.error.message}`+ );+ }+ } else {+ expect(response.status).to.equal(expectedStatus);}});});@@ -1405,25 +1435,33 @@ Cypress.Commands.add(});-Cypress.Commands.add("customerRetrieveCall", (globalState) => {- const customer_id = globalState.get("customerId");+Cypress.Commands.add(+ "customerRetrieveCall",+ (globalState, expectedStatus = 200) => {+ const customer_id = globalState.get("customerId");- cy.request({- method: "GET",- url: `${globalState.get("baseUrl")}/customers/${customer_id}`,- headers: {- "Content-Type": "application/json",- "api-key": globalState.get("apiKey"),- },- failOnStatusCode: false,- }).then((response) => {- logRequestId(response.headers["x-request-id"]);+ cy.request({+ method: "GET",+ url: `${globalState.get("baseUrl")}/customers/${customer_id}`,+ headers: {+ "Content-Type": "application/json",+ "api-key": globalState.get("apiKey"),+ },+ failOnStatusCode: false,+ }).then((response) => {+ logRequestId(response.headers["x-request-id"]);- cy.wrap(response).then(() => {- expect(response.body.customer_id).to.equal(customer_id).and.not.be.empty;+ cy.wrap(response).then(() => {+ expect(response.status).to.equal(expectedStatus);++ if (expectedStatus === 200) {+ expect(response.body.customer_id).to.equal(customer_id).and.not.be+ .empty;+ }+ });});- });-});+ }+);Cypress.Commands.add("customerUpdateCall",@@ -5620,3 +5658,202 @@ Cypress.Commands.add("step", (stepName, fn) => {Cypress.log({ groupEnd: true, emitOnly: true });});});++Cypress.Commands.add(+ "merchantListByOrgCall",+ (globalState, expectedMerchants = []) => {+ const baseUrl = globalState.get("baseUrl");+ const adminApiKey = globalState.get("adminApiKey");+ const organizationId = globalState.get("organizationId");+ const url = `${baseUrl}/accounts/list?organization_id=${organizationId}`;++ return cy+ .request({+ method: "GET",+ url,+ headers: {+ Accept: "application/json",+ "Content-Type": "application/json",+ "api-key": adminApiKey,+ },+ failOnStatusCode: false,+ })+ .then((response) => {+ logRequestId(response.headers["x-request-id"]);++ if (response.status === 200) {+ expect(response.body).to.be.an("array");+ expect(response.body.length).to.be.at.least(expectedMerchants.length);++ expectedMerchants.forEach(({ merchantIdKey, expectedType }) => {+ const merchant = response.body.find(+ (m) => m.merchant_id === globalState.get(merchantIdKey)+ );+ expect(merchant).to.exist;+ expect(merchant.merchant_account_type).to.equal(expectedType);+ });+ } else {+ throw new Error(+ `Merchant list call failed with status: ${response.status} and body: ${JSON.stringify(response.body)}`+ );+ }+ });+ }+);++Cypress.Commands.add(+ "createPaymentWithHeaderCall",+ (+ paymentBody,+ apiKey,+ connectedMerchantId,+ globalState,+ expectedStatus,+ stateKey+ ) => {+ const baseUrl = globalState.get("baseUrl");+ const url = `${baseUrl}/payments`;++ return cy+ .request({+ method: "POST",+ url,+ headers: {+ Accept: "application/json",+ "Content-Type": "application/json",+ "api-key": apiKey,+ "x-connected-merchant-id": connectedMerchantId,+ },+ body: paymentBody,+ failOnStatusCode: false,+ })+ .then((response) => {+ logRequestId(response.headers["x-request-id"]);++ expect(response.status).to.equal(expectedStatus);++ if (response.status === 200) {+ expect(response.body).to.have.property("payment_id");++ if (stateKey) {+ globalState.set(stateKey, response.body.payment_id);+ }+ }+ });+ }+);++Cypress.Commands.add(+ "createBusinessProfileWithHeaderCall",+ (+ businessProfileBody,+ apiKey,+ connectedMerchantId,+ globalState,+ expectedStatus,+ stateKey+ ) => {+ const baseUrl = globalState.get("baseUrl");+ const merchantId = globalState.get("merchantId");+ const url = `${baseUrl}/account/${merchantId}/business_profile`;++ return cy+ .request({+ method: "POST",+ url,+ headers: {+ Accept: "application/json",+ "Content-Type": "application/json",+ "api-key": apiKey,+ "x-connected-merchant-id": connectedMerchantId,+ },+ body: businessProfileBody,+ failOnStatusCode: false,+ })+ .then((response) => {+ logRequestId(response.headers["x-request-id"]);++ expect(response.status).to.equal(expectedStatus);++ if (response.status === 200) {+ expect(response.body).to.have.property("profile_id");++ if (stateKey) {+ globalState.set(stateKey, response.body.profile_id);+ }+ }+ });+ }+);++Cypress.Commands.add(+ "listPaymentsWithApiKeyCall",+ (apiKey, globalState, excludedPaymentIdKey) => {+ const baseUrl = globalState.get("baseUrl");+ const url = `${baseUrl}/payments/list`;++ return cy+ .request({+ method: "GET",+ url,+ headers: {+ Accept: "application/json",+ "Content-Type": "application/json",+ "api-key": apiKey,+ },+ failOnStatusCode: false,+ })+ .then((response) => {+ logRequestId(response.headers["x-request-id"]);++ if (response.status === 200) {+ expect(response.body).to.have.property("data");+ expect(response.body.data).to.be.an("array");++ if (excludedPaymentIdKey) {+ const excludedPaymentId = globalState.get(excludedPaymentIdKey);+ const hasExcludedPayment = response.body.data.some(+ (payment) => payment.payment_id === excludedPaymentId+ );+ expect(hasExcludedPayment).to.be.false;+ }+ } else {+ throw new Error(+ `List payments call failed with status: ${response.status} and body: ${JSON.stringify(response.body)}`+ );+ }+ });+ }+);++Cypress.Commands.add(+ "createConnectorWithHeaderCall",+ (connectorBody, apiKey, connectedMerchantId, globalState, expectedStatus) => {+ const baseUrl = globalState.get("baseUrl");+ const merchantId = globalState.get("merchantId");+ const url = `${baseUrl}/account/${merchantId}/connectors`;++ return cy+ .request({+ method: "POST",+ url,+ headers: {+ Accept: "application/json",+ "Content-Type": "application/json",+ "api-key": apiKey,+ "x-connected-merchant-id": connectedMerchantId,+ },+ body: connectorBody,+ failOnStatusCode: false,+ })+ .then((response) => {+ logRequestId(response.headers["x-request-id"]);++ expect(response.status).to.equal(expectedStatus);++ if (response.status === 200) {+ expect(response.body).to.have.property("connector_name");+ }+ });+ }+);