40 lines
1.4 KiB
TypeScript
40 lines
1.4 KiB
TypeScript
import { ExportsService } from "../src/exports/exports.service";
|
|
import { createPrismaMock } from "./utils/mock-prisma";
|
|
|
|
describe("ExportsService", () => {
|
|
it("returns missing_user when user id is absent", async () => {
|
|
const prisma = createPrismaMock();
|
|
const service = new ExportsService(prisma as any);
|
|
|
|
const result = await service.exportCsv(undefined);
|
|
expect(result.status).toBe("missing_user");
|
|
expect(prisma.exportLog.create).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("exports csv with headers and rows", async () => {
|
|
const prisma = createPrismaMock();
|
|
prisma.transactionRaw.findMany.mockResolvedValue([
|
|
{
|
|
id: "tx_1",
|
|
date: new Date("2025-01-10"),
|
|
description: "Lunch",
|
|
amount: 20,
|
|
source: "manual",
|
|
derived: { userCategory: "Meals", userNotes: "Team lunch", isHidden: false }
|
|
}
|
|
]);
|
|
prisma.exportLog.create.mockResolvedValue({ id: "log_1" });
|
|
const service = new ExportsService(prisma as any);
|
|
|
|
const result = await service.exportCsv("user_1", { category: "Meals" });
|
|
expect(result.status).toBe("ready");
|
|
expect(result.rowCount).toBe(1);
|
|
expect(result.csv).toContain("id,date,description,amount,category,notes,hidden,source");
|
|
expect(prisma.exportLog.create).toHaveBeenCalledWith(
|
|
expect.objectContaining({
|
|
data: expect.objectContaining({ userId: "user_1", rowCount: 1 })
|
|
})
|
|
);
|
|
});
|
|
});
|