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
test(cypress): add product type coverage for merchant account (#12029)
HS-QUALIBOTa3d90ff90428
diff --git a/cypress-tests/cypress/e2e/spec/Misc/00003-ProductType.cy.js b/cypress-tests/cypress/e2e/spec/Misc/00003-ProductType.cy.jsnew file mode 100644index 0000000000..2268b727c1--- /dev/null+++ b/cypress-tests/cypress/e2e/spec/Misc/00003-ProductType.cy.js@@ -0,0 +1,188 @@+import * as fixtures from "../../../fixtures/imports";+import State from "../../../utils/State";++let globalState;++describe("Merchant Account Product Type Tests", () => {+ before("seed global state", () => {+ cy.task("getGlobalState").then((state) => {+ globalState = new State(state);+ });+ });++ after("flush global state", () => {+ cy.task("setGlobalState", globalState.data);+ });++ afterEach("cleanup merchant after each test", () => {+ const merchantId = globalState.get("merchantId");+ if (merchantId) {+ cy.merchantDeleteCall(globalState);+ }+ });++ context("Create merchant with product_type=vault", () => {+ it("should create merchant with vault product type", () => {+ const baseBody = { ...fixtures.merchantCreateBody };+ delete baseBody.merchant_id;+ const merchantCreateBody = {+ ...baseBody,+ product_type: "vault",+ };++ cy.merchantCreateCallTest(merchantCreateBody, globalState, {+ expectedProductType: "vault",+ });+ });++ it("should verify vault product_type persists on retrieve", function () {+ const merchantId = globalState.get("merchantId");+ if (!merchantId) {+ this.skip();+ }+ cy.merchantRetrieveCall(globalState, {+ expectedProductType: "vault",+ });+ });+ });++ context("Create merchant with product_type=recon", () => {+ it("should create merchant with recon product type", () => {+ const baseBody = { ...fixtures.merchantCreateBody };+ delete baseBody.merchant_id;+ const merchantCreateBody = {+ ...baseBody,+ product_type: "recon",+ };++ cy.merchantCreateCallTest(merchantCreateBody, globalState, {+ expectedProductType: "recon",+ });+ });++ it("should verify recon product_type persists on retrieve", function () {+ const merchantId = globalState.get("merchantId");+ if (!merchantId) {+ this.skip();+ }+ cy.merchantRetrieveCall(globalState, {+ expectedProductType: "recon",+ });+ });+ });++ context("Create merchant with product_type=recovery", () => {+ it("should create merchant with recovery product type", () => {+ const baseBody = { ...fixtures.merchantCreateBody };+ delete baseBody.merchant_id;+ const merchantCreateBody = {+ ...baseBody,+ product_type: "recovery",+ };++ cy.merchantCreateCallTest(merchantCreateBody, globalState, {+ expectedProductType: "recovery",+ });+ });++ it("should verify recovery product_type persists on retrieve", function () {+ const merchantId = globalState.get("merchantId");+ if (!merchantId) {+ this.skip();+ }+ cy.merchantRetrieveCall(globalState, {+ expectedProductType: "recovery",+ });+ });+ });++ context("Create merchant with product_type=cost_observability", () => {+ it("should create merchant with cost_observability product type", () => {+ const baseBody = { ...fixtures.merchantCreateBody };+ delete baseBody.merchant_id;+ const merchantCreateBody = {+ ...baseBody,+ product_type: "cost_observability",+ };++ cy.merchantCreateCallTest(merchantCreateBody, globalState, {+ expectedProductType: "cost_observability",+ });+ });++ it("should verify cost_observability product_type persists on retrieve", function () {+ const merchantId = globalState.get("merchantId");+ if (!merchantId) {+ this.skip();+ }+ cy.merchantRetrieveCall(globalState, {+ expectedProductType: "cost_observability",+ });+ });+ });++ context("Create merchant with product_type=dynamic_routing", () => {+ it("should create merchant with dynamic_routing product type", () => {+ const baseBody = { ...fixtures.merchantCreateBody };+ delete baseBody.merchant_id;+ const merchantCreateBody = {+ ...baseBody,+ product_type: "dynamic_routing",+ };++ cy.merchantCreateCallTest(merchantCreateBody, globalState, {+ expectedProductType: "dynamic_routing",+ });+ });++ it("should verify dynamic_routing product_type persists on retrieve", function () {+ const merchantId = globalState.get("merchantId");+ if (!merchantId) {+ this.skip();+ }+ cy.merchantRetrieveCall(globalState, {+ expectedProductType: "dynamic_routing",+ });+ });+ });++ context(+ "Create merchant without product_type (default to orchestration)",+ () => {+ it("should create merchant without product_type and default to orchestration", () => {+ const merchantCreateBody = { ...fixtures.merchantCreateBody };+ delete merchantCreateBody.merchant_id;++ cy.merchantCreateCallTest(merchantCreateBody, globalState, {+ expectedProductType: "orchestration",+ });+ });++ it("should verify orchestration product_type persists on retrieve", function () {+ const merchantId = globalState.get("merchantId");+ if (!merchantId) {+ this.skip();+ }+ cy.merchantRetrieveCall(globalState, {+ expectedProductType: "orchestration",+ });+ });+ }+ );++ context("Create merchant with invalid product_type (negative test)", () => {+ it("should return 400 error for invalid product_type value", () => {+ const baseBody = { ...fixtures.merchantCreateBody };+ delete baseBody.merchant_id;+ const merchantCreateBody = {+ ...baseBody,+ product_type: "invalid_product_type",+ };++ cy.merchantCreateCallTest(merchantCreateBody, globalState, {+ expectedStatus: 400,+ expectedErrorCode: "IR_06",+ });+ });+ });+});diff --git a/cypress-tests/cypress/support/commands.js b/cypress-tests/cypress/support/commands.jsindex 75059fd225..e8109d83a9 100644--- a/cypress-tests/cypress/support/commands.js+++ b/cypress-tests/cypress/support/commands.js@@ -518,11 +518,27 @@ Cypress.Commands.add("healthCheck", (globalState) => {});});+/**+ * Creates a merchant account and optionally validates response fields.+ * @param {Object} merchantCreateBody - The merchant creation request body+ * @param {Object} globalState - The global state object+ * @param {Object} options - Options for merchant creation+ * @param {string|null} [options.expectedMerchantAccountType=null] - Expected merchant_account_type to validate (optional)+ * @param {string} [options.expectedProductType="orchestration"] - Expected product_type to validate. Pass a string value like "vault", "recon", "recovery", etc. to validate the response contains this product_type. Defaults to "orchestration".+ * @param {number} [options.expectedStatus=200] - Expected HTTP status code. Use 400 for negative test cases.+ * @param {string} [options.expectedErrorCode=null] - Expected error code in response body (for negative test cases, e.g. "IR_06")+ * @param {string} [options.merchantIdStateKey="merchantId"] - Key to store merchant ID in global state+ * @param {string} [options.profileIdStateKey="profileId"] - Key to store profile ID in global state+ * @param {string} [options.publishableKeyStateKey="publishableKey"] - Key to store publishable key in global state+ */Cypress.Commands.add("merchantCreateCallTest",(merchantCreateBody, globalState, options = {}) => {const {expectedMerchantAccountType = null,+ expectedProductType = "orchestration",+ expectedStatus = 200,+ expectedErrorCode = null,merchantIdStateKey = "merchantId",profileIdStateKey = "profileId",publishableKeyStateKey = "publishableKey",@@ -530,7 +546,6 @@ Cypress.Commands.add(const merchantId = RequestBodyUtils.generateRandomString();RequestBodyUtils.setMerchantId(merchantCreateBody, merchantId);- globalState.set(merchantIdStateKey, merchantId);cy.request({method: "POST",@@ -541,10 +556,23 @@ Cypress.Commands.add("api-key": globalState.get("adminApiKey"),},body: merchantCreateBody,+ failOnStatusCode: false,}).then((response) => {logRequestId(response.headers["x-request-id"]);cy.wrap(response).then(() => {+ expect(response.status).to.equal(expectedStatus);++ if (expectedStatus !== 200) {+ if (expectedErrorCode) {+ expect(response.body).to.have.property("error");+ expect(response.body.error.code).to.equal(expectedErrorCode);+ }+ return;+ }++ globalState.set(merchantIdStateKey, merchantId);+if (expectedMerchantAccountType) {expect(response.body).to.have.property("merchant_account_type",@@ -552,6 +580,13 @@ Cypress.Commands.add();}+ if (expectedProductType) {+ expect(response.body).to.have.property(+ "product_type",+ expectedProductType+ );+ }+globalState.set(profileIdStateKey, response.body.default_profile);globalState.set(publishableKeyStateKey, response.body.publishable_key);globalState.set("merchantDetails", response.body.merchant_details);@@ -561,7 +596,8 @@ Cypress.Commands.add(});-Cypress.Commands.add("merchantRetrieveCall", (globalState) => {+Cypress.Commands.add("merchantRetrieveCall", (globalState, options = {}) => {+ const { expectedProductType = null } = options;const merchant_id = globalState.get("merchantId");cy.request({method: "GET",@@ -593,6 +629,13 @@ Cypress.Commands.add("merchantRetrieveCall", (globalState) => {if (globalState.get("publishableKey") === undefined) {globalState.set("publishableKey", response.body.publishable_key);}++ if (expectedProductType) {+ expect(response.body).to.have.property(+ "product_type",+ expectedProductType+ );+ }});});});