fix: require BAP before original PDF exports

This commit is contained in:
Manus
2026-10-09 08:44:02 +00:00
parent e402233120
commit 939dddd1d8
6 changed files with 157 additions and 6 deletions

View File

@@ -0,0 +1,40 @@
import { describe, expect, it } from "vitest";
import { readFileSync } from "node:fs";
import { join } from "node:path";
import { requiresBapBeforeOriginalPdfExport } from "../shared/bapExportGuard";
describe("garde-fou d’export avant BAP", () => {
it("bloque l’export PDF original d’une facture hors abonnement non validée BAP", () => {
expect(requiresBapBeforeOriginalPdfExport({ isSubscription: 0, bapValidated: 0 })).toBe(true);
});
it("autorise les abonnements et les factures déjà validées BAP", () => {
expect(requiresBapBeforeOriginalPdfExport({ isSubscription: 1, bapValidated: 0 })).toBe(false);
expect(requiresBapBeforeOriginalPdfExport({ isSubscription: 0, bapValidated: 1 })).toBe(false);
});
it("applique le garde-fou aux deux exports PDF métier côté serveur", () => {
const routerSource = readFileSync(join(process.cwd(), "server", "routers.ts"), "utf8");
const exportPdfSection = routerSource.slice(
routerSource.indexOf("exportToPdf: protectedProcedure"),
routerSource.indexOf("exportInvoices: protectedProcedure"),
);
const exportInvoicesSection = routerSource.slice(
routerSource.indexOf("exportInvoices: protectedProcedure"),
routerSource.indexOf("// ============= IMPORT LOGS ROUTES"),
);
expect(exportPdfSection).toContain("requiresBapBeforeOriginalPdfExport");
expect(exportInvoicesSection).toContain("requiresBapBeforeOriginalPdfExport");
});
it("clarifie les exports historiques et autorise leur régularisation BAP dans l’interface", () => {
const invoicesPage = readFileSync(join(process.cwd(), "client", "src", "pages", "Invoices.tsx"), "utf8");
const bapPage = readFileSync(join(process.cwd(), "client", "src", "pages", "InvoicesBAP.tsx"), "utf8");
expect(invoicesPage).toContain("requiresBapBeforeOriginalPdfExport");
expect(bapPage).toContain("Exporté avant BAP");
expect(bapPage).toContain("wasExportedBeforeBap");
expect(bapPage).not.toContain('invoice.exportStatus !== "exported"');
});
});