From d8856c0081162e53653a9e9daa9d6271312526c1 Mon Sep 17 00:00:00 2001 From: Justin Gasper Date: Fri, 28 Nov 2025 18:46:53 +1100 Subject: [PATCH] Better handling of comma-delimited BA IDs --- src/common/validation.util.ts | 16 ++++++++++++++-- src/reports/sfdc/sfdc-reports.controller.spec.ts | 4 ++-- src/reports/sfdc/sfdc-reports.dto.spec.ts | 13 +++++++++++++ 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/common/validation.util.ts b/src/common/validation.util.ts index cf58617..e3ed5e7 100644 --- a/src/common/validation.util.ts +++ b/src/common/validation.util.ts @@ -12,6 +12,18 @@ export function defaultEndDate(): Date { return new Date(); // now } -export function transformArray({ value }: { value: string }) { - return Array.isArray(value) ? value : [value]; +export function transformArray({ value }: { value: unknown }) { + if (value === undefined || value === null) return undefined; + + const splitIfString = (v: unknown) => { + if (typeof v === "string") { + return v + .split(",") + .map((token) => token.trim()) + .filter((token) => token !== ""); + } + return [v]; + }; + + return Array.isArray(value) ? value.flatMap(splitIfString) : splitIfString(value); } diff --git a/src/reports/sfdc/sfdc-reports.controller.spec.ts b/src/reports/sfdc/sfdc-reports.controller.spec.ts index d149f07..8d12ec5 100644 --- a/src/reports/sfdc/sfdc-reports.controller.spec.ts +++ b/src/reports/sfdc/sfdc-reports.controller.spec.ts @@ -166,7 +166,7 @@ describe("SfdcReportsController", () => { mockSfdcReportsService.getPaymentsReport.mockResolvedValue([]); const dto = plainToInstance(PaymentsReportQueryDto, { - billingAccountIds: "80001012", + billingAccountIds: "80001012,80002012", challengeIds: "e74c3e37-73c9-474e-a838-a38dd4738906", handles: "user_01", challengeStatus: "COMPLETED", @@ -176,7 +176,7 @@ describe("SfdcReportsController", () => { expect(mockSfdcReportsService.getPaymentsReport).toHaveBeenCalledWith( expect.objectContaining({ - billingAccountIds: ["80001012"], + billingAccountIds: ["80001012", "80002012"], challengeIds: ["e74c3e37-73c9-474e-a838-a38dd4738906"], handles: ["user_01"], challengeStatus: ["COMPLETED"], diff --git a/src/reports/sfdc/sfdc-reports.dto.spec.ts b/src/reports/sfdc/sfdc-reports.dto.spec.ts index af70548..5e36da2 100644 --- a/src/reports/sfdc/sfdc-reports.dto.spec.ts +++ b/src/reports/sfdc/sfdc-reports.dto.spec.ts @@ -704,6 +704,19 @@ describe("TaasResourceBookingsReportQueryDto validation", () => { expect(dto.billingAccountIds).toEqual(["80001012"]); }); + it("splits comma-delimited billingAccountIds", async () => { + const { dto, errors } = await validateTaasResourceBookingsDto({ + // @ts-expect-error intentional single value for transform check + billingAccountIds: "80001012,80002012 , 80003012", + }); + expect(errors).toHaveLength(0); + expect(dto.billingAccountIds).toEqual([ + "80001012", + "80002012", + "80003012", + ]); + }); + it("accepts ISO date strings for startDate and endDate", async () => { const { errors } = await validateTaasResourceBookingsDto({ startDate: "2023-04-01",