38 lines
1.8 KiB
TypeScript
38 lines
1.8 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { opsToCsv } from "@/server/csv";
|
|
import { op } from "./fixtures";
|
|
|
|
const users = [
|
|
{ id: "H", firstName: "H" },
|
|
{ id: "C", firstName: "C" },
|
|
];
|
|
const categories = { courses: { name: "Courses" }, salaire: { name: "Salaire" } };
|
|
|
|
describe("opsToCsv", () => {
|
|
const groceries = op({ kind: "EXPENSE", amount: 8640, accountUserId: "C", label: "Carrefour; Bio", categoryId: "courses", date: "2026-10-27" });
|
|
|
|
it("starts with a BOM and a French header", () => {
|
|
const csv = opsToCsv([groceries], users, categories, {});
|
|
expect(csv.startsWith("\uFEFFDate;Type;Libellé;Catégorie;Montant;Payé par;Statut;Part H %;Part C %;Affecté à;Note\r\n")).toBe(true);
|
|
});
|
|
|
|
it("quotes fields with separators and uses comma decimals", () => {
|
|
const lines = opsToCsv([groceries], users, categories, {}).split("\r\n");
|
|
expect(lines[1]).toBe('27/10/2026;Dépense;"Carrefour; Bio";Courses;-86,40;C;Réel;50;50;;');
|
|
});
|
|
|
|
it("writes incomes positive, planned status, allocation label and escaped notes", () => {
|
|
const refund = {
|
|
...op({ kind: "INCOME" as const, amount: 20000, accountUserId: "H", label: "Employeur", categoryId: "salaire", status: "PLANNED" as const, allocatedToRecurringId: "rent", date: "2026-10-05" }),
|
|
note: 'part "loyer"',
|
|
};
|
|
const lines = opsToCsv([refund], users, categories, { rent: "Loyer" }).split("\r\n");
|
|
expect(lines[1]).toBe('05/10/2026;Entrée;Employeur;Salaire;200,00;H;Prévu;50;50;Loyer;"part ""loyer"""');
|
|
});
|
|
|
|
it("excludes skipped operations", () => {
|
|
const skipped = op({ kind: "EXPENSE", amount: 100, accountUserId: "H", status: "SKIPPED" });
|
|
expect(opsToCsv([skipped], users, categories, {}).split("\r\n").filter(Boolean)).toHaveLength(1);
|
|
});
|
|
});
|