feat: settings and CSV export
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
9cb7fe8c81
commit
8201496bb6
8 files changed
+528
No files matched your search
@@ -0,0 +1,37 @@
|
||||
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);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user