import { jest } from "@jest/globals"; const query = jest.fn(); const release = jest.fn(async () => {}); jest.unstable_mockModule("../../db/index.js", () => ({ getPool: async () => ({ query, release }) })); const { getSeries } = await import("./series.js"); beforeEach(() => { query.mockReset(); release.mockClear(); }); describe("getSeries (combined usage + storage, one query)", () => { it("splits one result set into usage counts and storage byte totals with computed totals", async () => { query.mockResolvedValue({ rows: [ { date: "2026-06-01", core: 3, audit: 5, core_disk: "100", audit_disk: "50" }, { date: "2026-06-02", core: 0, audit: 0, core_disk: "100", audit_disk: "50" }, ], }); const out = await getSeries(7, { from: "2026-06-01", to: "2026-06-02" }); expect(query).toHaveBeenCalledTimes(1); // single round-trip expect(query.mock.calls[0][1]).toEqual([7, "2026-06-01", "2026-06-02"]); expect(out.usage).toEqual([ { date: "2026-06-01", core: 3, audit: 5, total: 8 }, { date: "2026-06-02", core: 0, audit: 0, total: 0 }, ]); expect(out.storage).toEqual([ { date: "2026-06-01", coreDisk: 100, auditDisk: 50, totalDisk: 150 }, { date: "2026-06-02", coreDisk: 100, auditDisk: 50, totalDisk: 150 }, ]); expect(release).toHaveBeenCalledTimes(1); }); });