Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions src/handlers/list-xero-profit-and-loss.handler.test.ts
Original file line number Diff line number Diff line change
@@ -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" },
);
});
});
3 changes: 2 additions & 1 deletion src/handlers/list-xero-profit-and-loss.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export async function listXeroProfitAndLoss(
toDate,
periods,
timeframe,
standardLayout,
paymentsOnly,
);

Expand All @@ -88,4 +89,4 @@ export async function listXeroProfitAndLoss(
error: formatError(error),
};
}
}
}