This commit is contained in:
Ankit Kumar Gupta
2026-03-12 20:29:52 +05:30
parent 6a2a936390
commit 55caba5d0a
6 changed files with 516 additions and 127 deletions

View File

@@ -80,8 +80,8 @@ describe("Platform Setup & Connected Merchant Onboarding", () => {
});
});
context("Create Connected Merchant 2", () => {
it("create-connected-merchant-2", () => {
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"));
@@ -110,7 +110,7 @@ describe("Platform Setup & Connected Merchant Onboarding", () => {
});
});
it("create-api-key-for-connected-merchant-2", () => {
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");
@@ -165,12 +165,59 @@ describe("Platform Setup & Connected Merchant Onboarding", () => {
});
});
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.createConnectedMerchantCallTest(merchantCreateBody, globalState).then(
(response) => {
expect(response.status).to.equal(200);
expect(response.body).to.have.property(
"merchant_account_type",
"standard"
);
globalState.set("standardMerchantId_PlatformKey", response.body.merchant_id);
globalState.set("profileId_SM_PlatformKey", response.body.default_profile);
}
);
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("standardMerchantId_PlatformKey"));
globalState.set("adminApiKey", savedApiKey);
cy.apiKeyCreateTest(fixtures.apiKeyCreateBody, globalState);
cy.then(() => {
globalState.set("apiKey_SM_PlatformKey", 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.merchantListByOrgCallTest(globalState).then((response) => {
expect(response.status).to.equal(200);
expect(response.body).to.be.an("array");
expect(response.body.length).to.be.at.least(4);
expect(response.body.length).to.be.at.least(5);
const platformMerchant = response.body.find(
(m) => m.merchant_id === globalState.get("platformMerchantId")
@@ -195,6 +242,12 @@ describe("Platform Setup & Connected Merchant Onboarding", () => {
);
expect(sm).to.exist;
expect(sm.merchant_account_type).to.equal("standard");
const smPlatformKey = response.body.find(
(m) => m.merchant_id === globalState.get("standardMerchantId_PlatformKey")
);
expect(smPlatformKey).to.exist;
expect(smPlatformKey.merchant_account_type).to.equal("standard");
});
});
});

View File

@@ -1,116 +0,0 @@
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", () => {
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("apiKey_CM1"));
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("apiKey_CM2"));
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("apiKey_CM1"));
globalState.set("merchantId", globalState.get("connectedMerchantId_1"));
cy.createCustomerCallTest(fixtures.customerCreateBody, globalState);
cy.then(() => {
globalState.set(
"customerId_CM1_Created",
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("apiKey_CM2"));
globalState.set("customerId", globalState.get("customerId_CM1_Created"));
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("customerId_CM1_Created"));
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("apiKey_SM"));
const customerId = globalState.get("customerId");
cy.request({
method: "GET",
url: `${globalState.get("baseUrl")}/customers/${customerId}`,
headers: {
"Content-Type": "application/json",
"api-key": globalState.get("apiKey"),
},
failOnStatusCode: false,
}).then((response) => {
expect(response.status).to.equal(404);
});
cy.then(() => {
globalState.set("apiKey", savedApiKey);
});
});
});
});

View File

@@ -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 baseUrl = globalState.get("baseUrl");
const merchantId = globalState.get("platformMerchantId");
cy.request({
method: "POST",
url: `${baseUrl}/account/${merchantId}/business_profile`,
headers: {
"Content-Type": "application/json",
"api-key": globalState.get("apiKey"),
},
body: fixtures.businessProfile.bpCreate,
failOnStatusCode: false,
}).then((response) => {
expect(response.status).to.be.oneOf([400, 403, 422]);
});
});
});
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("connectedMerchantId_1"));
globalState.set("apiKey", globalState.get("apiKey_CM1"));
cy.createBusinessProfileTest(fixtures.businessProfile.bpCreate, globalState);
cy.then(() => {
globalState.set("profileId_CM1_New", 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 baseUrl = globalState.get("baseUrl");
const merchantId = globalState.get("connectedMerchantId_2");
cy.request({
method: "POST",
url: `${baseUrl}/account/${merchantId}/business_profile`,
headers: {
"Content-Type": "application/json",
"api-key": globalState.get("apiKey"),
"x-connected-merchant-id": merchantId,
},
body: fixtures.businessProfile.bpCreate,
failOnStatusCode: false,
}).then((response) => {
expect(response.status).to.equal(200);
globalState.set("profileId_CM2_New", response.body.profile_id);
});
});
});
context("Platform Cannot Create Profile For Standard Merchant", () => {
it("platform-cannot-create-profile-for-standard-merchant", () => {
const baseUrl = globalState.get("baseUrl");
const merchantId = globalState.get("standardMerchantId");
cy.request({
method: "POST",
url: `${baseUrl}/account/${merchantId}/business_profile`,
headers: {
"Content-Type": "application/json",
"api-key": globalState.get("apiKey"),
},
body: fixtures.businessProfile.bpCreate,
failOnStatusCode: false,
}).then((response) => {
expect(response.status).to.be.oneOf([400, 403, 422]);
});
});
});
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("apiKey_SM"));
cy.createBusinessProfileTest(fixtures.businessProfile.bpCreate, globalState);
cy.then(() => {
globalState.set("profileId_SM_New", globalState.get("profileId"));
globalState.set("merchantId", savedMerchantId);
globalState.set("apiKey", savedApiKey);
});
});
});
});

View File

@@ -127,6 +127,62 @@ describe("Connector Setup for Connected Merchants", () => {
});
});
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");
const savedConnectorId = globalState.get("connectorId");
globalState.set("merchantId", globalState.get("standardMerchantId"));
globalState.set("apiKey", globalState.get("apiKey_SM"));
globalState.set("profileId", globalState.get("profileId_SM"));
globalState.set("connectorId", "stripe");
cy.createConnectorCallTest(
"payment_processor",
fixtures.createConnectorBody,
payment_methods_enabled,
globalState
);
cy.then(() => {
globalState.set(
"connectorId_SM",
globalState.get("merchantConnectorId")
);
globalState.set("merchantId", savedMerchantId);
globalState.set("apiKey", savedApiKey);
globalState.set("profileId", savedProfileId);
globalState.set("connectorId", savedConnectorId);
});
});
it("retrieve-connector-for-standard-merchant", () => {
const savedMerchantId = globalState.get("merchantId");
const savedApiKey = globalState.get("apiKey");
const savedMerchantConnectorId = globalState.get("merchantConnectorId");
const savedConnectorId = globalState.get("connectorId");
globalState.set("merchantId", globalState.get("standardMerchantId"));
globalState.set("apiKey", globalState.get("apiKey_SM"));
globalState.set(
"merchantConnectorId",
globalState.get("connectorId_SM")
);
globalState.set("connectorId", "stripe");
cy.connectorRetrieveCall(globalState);
cy.then(() => {
globalState.set("merchantId", savedMerchantId);
globalState.set("apiKey", savedApiKey);
globalState.set("merchantConnectorId", savedMerchantConnectorId);
globalState.set("connectorId", savedConnectorId);
});
});
});
context("Verify Connectors Are Separate", () => {
it("verify-cm1-and-cm2-have-different-connectors", () => {
const connectorIdCM1 = globalState.get("connectorId_CM1");
@@ -134,5 +190,44 @@ describe("Connector Setup for Connected Merchants", () => {
expect(connectorIdCM1).to.not.equal(connectorIdCM2);
});
});
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 baseUrl = globalState.get("baseUrl");
const merchantId = globalState.get("merchantId");
const profileId = globalState.get("profileId");
cy.request({
method: "POST",
url: `${baseUrl}/account/${merchantId}/profiles/${profileId}/connectors`,
headers: {
"Content-Type": "application/json",
"api-key": globalState.get("apiKey"),
},
body: {
connector_type: "payment_processor",
connector_name: "stripe",
connector_label: "stripe_platform_test",
...fixtures.createConnectorBody,
payment_methods_enabled,
},
failOnStatusCode: false,
}).then((response) => {
expect(response.status).to.be.oneOf([400, 403, 404, 422]);
});
cy.then(() => {
globalState.set("merchantId", savedMerchantId);
globalState.set("profileId", savedProfileId);
});
});
});
});

View File

@@ -0,0 +1,221 @@
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", () => {
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("apiKey_CM1"));
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("apiKey_CM2"));
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("apiKey_CM1"));
globalState.set("merchantId", globalState.get("connectedMerchantId_1"));
cy.createCustomerCallTest(fixtures.customerCreateBody, globalState);
cy.then(() => {
globalState.set(
"customerId_CM1_Created",
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("apiKey_CM2"));
globalState.set("customerId", globalState.get("customerId_CM1_Created"));
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("customerId_CM1_Created"));
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("apiKey_SM"));
const customerId = globalState.get("customerId");
cy.request({
method: "GET",
url: `${globalState.get("baseUrl")}/customers/${customerId}`,
headers: {
"Content-Type": "application/json",
"api-key": globalState.get("apiKey"),
},
failOnStatusCode: false,
}).then((response) => {
expect(response.status).to.equal(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("apiKey_SM"));
globalState.set("merchantId", globalState.get("standardMerchantId"));
cy.createCustomerCallTest(fixtures.customerCreateBody, globalState);
cy.then(() => {
globalState.set(
"customerId_SM_Created",
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("customerId_SM_Created"));
cy.request({
method: "GET",
url: `${globalState.get("baseUrl")}/customers/${globalState.get("customerId")}`,
headers: {
"Content-Type": "application/json",
"api-key": globalState.get("apiKey"),
},
failOnStatusCode: false,
}).then((response) => {
expect(response.status).to.equal(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("apiKey_CM1"));
globalState.set("customerId", globalState.get("customerId_SM_Created"));
cy.request({
method: "GET",
url: `${globalState.get("baseUrl")}/customers/${globalState.get("customerId")}`,
headers: {
"Content-Type": "application/json",
"api-key": globalState.get("apiKey"),
},
failOnStatusCode: false,
}).then((response) => {
expect(response.status).to.equal(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("apiKey_CM2"));
globalState.set("customerId", globalState.get("customerId_SM_Created"));
cy.request({
method: "GET",
url: `${globalState.get("baseUrl")}/customers/${globalState.get("customerId")}`,
headers: {
"Content-Type": "application/json",
"api-key": globalState.get("apiKey"),
},
failOnStatusCode: false,
}).then((response) => {
expect(response.status).to.equal(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("apiKey_SM"));
globalState.set("customerId", globalState.get("customerId_SM_Created"));
cy.customerRetrieveCall(globalState);
cy.then(() => {
globalState.set("apiKey", savedApiKey);
globalState.set("customerId", savedCustomerId);
});
});
});
});

View File

@@ -18,8 +18,8 @@ describe("Platform Payment Flows", () => {
it("platform-creates-payment-for-cm1-using-header", () => {
const paymentRequestBody = {
...fixtures.createConfirmPaymentBody,
customer_id: globalState.get("customerId"),
profile_id: globalState.get("profileId_CM1"),
customer_id: globalState.get("customerId_CM1_Created"),
};
cy.createPaymentWithHeaderCallTest(
@@ -43,8 +43,8 @@ describe("Platform Payment Flows", () => {
it("platform-creates-payment-for-cm2-using-header", () => {
const paymentRequestBody = {
...fixtures.createConfirmPaymentBody,
customer_id: globalState.get("customerId"),
profile_id: globalState.get("profileId_CM2"),
customer_id: globalState.get("customerId_CM1_Created"),
};
cy.createPaymentWithHeaderCallTest(
@@ -58,7 +58,9 @@ describe("Platform Payment Flows", () => {
globalState.set("platformPaymentId_CM2", response.body.payment_id);
});
});
});
context("Platform Cannot Create Payment Without On-Behalf-Of Header", () => {
it("platform-cannot-create-payment-without-header", () => {
const paymentRequestBody = {
...fixtures.createConfirmPaymentBody,
@@ -70,7 +72,25 @@ describe("Platform Payment Flows", () => {
globalState.get("apiKey"),
globalState
).then((response) => {
expect(response.status).to.be.oneOf([400, 403, 422]);
expect(response.status).to.be.oneOf([400, 401, 403, 404, 422]);
});
});
});
context("Platform Cannot Create Payment For Standard Merchant", () => {
it("platform-cannot-create-payment-for-standard-merchant", () => {
const paymentRequestBody = {
...fixtures.createConfirmPaymentBody,
profile_id: globalState.get("profileId_SM"),
};
cy.createPaymentWithHeaderCallTest(
paymentRequestBody,
globalState.get("apiKey"),
globalState.get("standardMerchantId"),
globalState
).then((response) => {
expect(response.status).to.be.oneOf([400, 401, 403, 404, 422]);
});
});
});
@@ -79,7 +99,8 @@ describe("Platform Payment Flows", () => {
it("cm1-creates-payment-for-shared-customer", () => {
const paymentRequestBody = {
...fixtures.createConfirmPaymentBody,
customer_id: globalState.get("customerId"),
customer_id: globalState.get("customerId_CM1_Created"),
profile_id: globalState.get("profileId_CM1"),
};
cy.createPaymentWithApiKeyCallTest(
@@ -96,7 +117,8 @@ describe("Platform Payment Flows", () => {
it("cm2-creates-payment-for-same-shared-customer", () => {
const paymentRequestBody = {
...fixtures.createConfirmPaymentBody,
customer_id: globalState.get("customerId"),
customer_id: globalState.get("customerId_CM1_Created"),
profile_id: globalState.get("profileId_CM2"),
};
cy.createPaymentWithApiKeyCallTest(
@@ -115,7 +137,7 @@ describe("Platform Payment Flows", () => {
it("connected-merchant-cannot-act-on-behalf-of-another-merchant", () => {
const paymentRequestBody = {
...fixtures.createConfirmPaymentBody,
customer_id: globalState.get("customerId"),
customer_id: globalState.get("customerId_CM1_Created"),
};
cy.createPaymentWithHeaderCallTest(
@@ -129,7 +151,7 @@ describe("Platform Payment Flows", () => {
});
});
context("Payment Isolation", () => {
context("Payment List Isolation", () => {
it("cm1-lists-only-own-payments", () => {
cy.listPaymentsWithApiKeyCallTest(
globalState.get("apiKey_CM1"),