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(customer_list): Add new API tests for customer list with count, pagination, and limit validation (#10183)
Venu Madhav Bandarupalli5e54cdc53368
diff --git a/cypress-tests/cypress/e2e/spec/Payment/00033-CustomerListTests.cy.js b/cypress-tests/cypress/e2e/spec/Payment/00033-CustomerListTests.cy.jsnew file mode 100644index 0000000000..127a753b50--- /dev/null+++ b/cypress-tests/cypress/e2e/spec/Payment/00033-CustomerListTests.cy.js@@ -0,0 +1,36 @@+import State from "../../../utils/State";++let globalState;++describe("Customer List API Tests", () => {+ before("seed global state", () => {+ cy.task("getGlobalState").then((state) => {+ globalState = new State(state);+ });+ });++ after("flush global state", () => {+ cy.task("setGlobalState", globalState.data);+ });++ context("Customer List With Count - Various Limits", () => {+ it("should work with default limit (20)", () => {+ cy.customerListWithCountCallTest(globalState); // default 20, 0+ });++ it("should work with small limit (5)", () => {+ cy.customerListWithCountCallTest(globalState, 5, 0);+ });++ it("should work with limit 1 (edge case)", () => {+ cy.customerListWithCountCallTest(globalState, 1, 0);+ });++ it("should work with large limit (100)", () => {+ cy.customerListWithCountCallTest(globalState, 100, 0);+ });+ it("should handle offset beyond total_count", () => {+ cy.customerListWithCountCallTest(globalState, 10, 9999);+ });+ });+});diff --git a/cypress-tests/cypress/support/commands.js b/cypress-tests/cypress/support/commands.jsindex eec11d067a..334df1f292 100644--- a/cypress-tests/cypress/support/commands.js+++ b/cypress-tests/cypress/support/commands.js@@ -947,6 +947,15 @@ Cypress.Commands.add(});+// NOTE: The following `customerListCall` command tests the OLD `/customers/list` endpoint.+// A new API `/api/customers/list_with_count` has been introduced to include pagination+// and total count in the response.+//+// Once the new endpoint is stable and fully rolled out in production,+// this old endpoint and related test (`customerListCall`) will be deprecated and removed.++// OLD customer list (to be deprecated later)+Cypress.Commands.add("customerListCall", (globalState) => {cy.request({method: "GET",@@ -967,6 +976,59 @@ Cypress.Commands.add("customerListCall", (globalState) => {});});+// NEW customer list (with count and pagination)++Cypress.Commands.add(+ "customerListWithCountCallTest",+ (globalState, limit = 20, offset = 0) => {+ cy.request({+ method: "GET",+ url: `${globalState.get("baseUrl")}/customers/list_with_count?limit=${limit}&offset=${offset}`,+ 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.status).to.eq(200);+ expect(response.body).to.have.property("data");+ expect(response.body).to.have.property("total_count");++ const actualDataLength = response.body.data.length;+ const totalCount = response.body.total_count;++ // Validate total_count is a number+ expect(totalCount).to.be.a("number");++ // Data length should never exceed the requested limit+ expect(actualDataLength).to.be.at.most(+ limit,+ `Data length (${actualDataLength}) should not exceed limit (${limit})`+ );++ // If offset is within range, validate data length expectations+ if (offset < totalCount) {+ const remainingRecords = totalCount - offset;+ const expectedDataLength = Math.min(limit, remainingRecords);+ expect(actualDataLength).to.equal(+ expectedDataLength,+ `Expected ${expectedDataLength} records but got ${actualDataLength} (total: ${totalCount}, offset: ${offset}, limit: ${limit})`+ );+ } else {+ // If offset >= total_count, data should be empty+ expect(actualDataLength).to.equal(+ 0,+ `When offset (${offset}) >= total_count (${totalCount}), data should be empty`+ );+ }+ });+ });+ }+);+Cypress.Commands.add("customerRetrieveCall", (globalState) => {const customer_id = globalState.get("customerId");