41 lines
2.0 KiB
TypeScript
41 lines
2.0 KiB
TypeScript
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"');
|
||
});
|
||
});
|