diff --git a/src/handlers/list-xero-profit-and-loss.handler.test.ts b/src/handlers/list-xero-profit-and-loss.handler.test.ts new file mode 100644 index 00000000..68504a24 --- /dev/null +++ b/src/handlers/list-xero-profit-and-loss.handler.test.ts @@ -0,0 +1,68 @@ +import { beforeEach, describe, expect, it, vi } from "vitest"; + +const authenticateMock = vi.fn(); +const getReportProfitAndLossMock = vi.fn(); +const getClientHeadersMock = vi.fn(() => ({ "x-test": "header" })); + +vi.mock("../clients/xero-client.js", () => ({ + xeroClient: { + tenantId: "tenant-123", + authenticate: authenticateMock, + accountingApi: { + getReportProfitAndLoss: getReportProfitAndLossMock, + }, + }, +})); + +vi.mock("../helpers/get-client-headers.js", () => ({ + getClientHeaders: getClientHeadersMock, +})); + +describe("listXeroProfitAndLoss", () => { + beforeEach(() => { + vi.clearAllMocks(); + }); + + it("forwards standardLayout and paymentsOnly to the SDK in the correct positions", async () => { + const report = { + reportName: "Profit and Loss", + reportDate: "2026-06-12", + rows: [], + }; + + getReportProfitAndLossMock.mockResolvedValue({ + body: { reports: [report] }, + }); + + const { listXeroProfitAndLoss } = await import( + "./list-xero-profit-and-loss.handler.js" + ); + + const result = await listXeroProfitAndLoss( + "2026-01-01", + "2026-01-31", + 1, + "MONTH", + true, + true, + ); + + expect(result.isError).toBe(false); + expect(result.result).toBe(report); + expect(authenticateMock).toHaveBeenCalledTimes(1); + expect(getReportProfitAndLossMock).toHaveBeenCalledWith( + "tenant-123", + "2026-01-01", + "2026-01-31", + 1, + "MONTH", + undefined, + undefined, + undefined, + undefined, + true, + true, + { "x-test": "header" }, + ); + }); +}); diff --git a/src/handlers/list-xero-profit-and-loss.handler.ts b/src/handlers/list-xero-profit-and-loss.handler.ts index e19a7bfc..9fc0c1bf 100644 --- a/src/handlers/list-xero-profit-and-loss.handler.ts +++ b/src/handlers/list-xero-profit-and-loss.handler.ts @@ -65,6 +65,7 @@ export async function listXeroProfitAndLoss( toDate, periods, timeframe, + standardLayout, paymentsOnly, ); @@ -88,4 +89,4 @@ export async function listXeroProfitAndLoss( error: formatError(error), }; } -} \ No newline at end of file +}