31 lines
1.3 KiB
TypeScript
31 lines
1.3 KiB
TypeScript
import { readFileSync } from "node:fs";
|
|
import { resolve } from "node:path";
|
|
import { describe, expect, it } from "vitest";
|
|
import { INVOICE_DELETE_ERROR, getSafeInvoiceDeletionError } from "./invoiceDeletionError";
|
|
|
|
const migrationPath = resolve(process.cwd(), "drizzle/0042_deleted_invoices_blacklist.sql");
|
|
const dbPath = resolve(process.cwd(), "server/db.ts");
|
|
|
|
describe("suppression de facture", () => {
|
|
it("ne renvoie jamais les détails SQL au navigateur", () => {
|
|
const error = new Error("Failed query: insert into `deletedInvoices` values (?, ?, ?)");
|
|
|
|
expect(getSafeInvoiceDeletionError(error)).toBe(INVOICE_DELETE_ERROR);
|
|
});
|
|
|
|
it("crée la blacklist de manière additive et idempotente", () => {
|
|
const migration = readFileSync(migrationPath, "utf8");
|
|
|
|
expect(migration).toContain("CREATE TABLE IF NOT EXISTS `deletedInvoices`");
|
|
expect(migration).toContain("CONSTRAINT `deletedInvoices_id` PRIMARY KEY(`id`)");
|
|
});
|
|
|
|
it("met à jour une entrée existante sans exiger de contrainte unique historique", () => {
|
|
const source = readFileSync(dbPath, "utf8");
|
|
|
|
expect(source).toContain("const blacklistEntry = await db.select");
|
|
expect(source).toContain("await db.update(deletedInvoices)");
|
|
expect(source).not.toContain("}).onDuplicateKeyUpdate({ set: { deletedAt: new Date() } });");
|
|
});
|
|
});
|