All checks were successful
Validation applicative / TypeScript, tests et build (push) Successful in 3m6s
40 lines
1.9 KiB
TypeScript
40 lines
1.9 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
||
import { readFileSync } from "node:fs";
|
||
import { join } from "node:path";
|
||
import { findMatchingExportRule } from "../shared/exportAutomation";
|
||
|
||
const rules = [
|
||
{ isActive: 1, priority: 2, conditionField: "recipientName" as const, conditionValue: "Direction générale" },
|
||
{ isActive: 1, priority: 1, conditionField: "ventilationComptable" as const, conditionValue: "615200" },
|
||
{ isActive: 0, priority: 0, conditionField: "recipientName" as const, conditionValue: "Direction générale" },
|
||
];
|
||
|
||
describe("règles de destination d’export", () => {
|
||
it("sélectionne une règle de ventilation active", () => {
|
||
expect(findMatchingExportRule(rules, { recipientName: "Direction générale", ventilationComptable: "615200" })).toBe(rules[1]);
|
||
});
|
||
|
||
it("compare les destinataires sans tenir compte de la casse et des espaces", () => {
|
||
expect(findMatchingExportRule(rules, { recipientName: " direction GÉNÉRALE " })).toBe(rules[0]);
|
||
});
|
||
|
||
it("ignore les règles inactives", () => {
|
||
expect(findMatchingExportRule([rules[2]], { recipientName: "Direction générale" })).toBeUndefined();
|
||
});
|
||
|
||
it("ne retourne aucune règle si la facture ne correspond à aucun critère", () => {
|
||
expect(findMatchingExportRule(rules, { recipientName: "Service achats", ventilationComptable: "606000" })).toBeUndefined();
|
||
});
|
||
|
||
it("applique aussi le résolveur de destination aux exports PDF de factures sélectionnées", () => {
|
||
const routerSource = readFileSync(join(process.cwd(), "server", "routers.ts"), "utf8");
|
||
const exportPdfSection = routerSource.slice(
|
||
routerSource.indexOf("exportToPdf: protectedProcedure"),
|
||
routerSource.indexOf("exportInvoices: protectedProcedure"),
|
||
);
|
||
|
||
expect(exportPdfSection).toContain("resolveBapExportDestination(ctx.user.id, invoice, settings)");
|
||
expect(exportPdfSection).toContain("isMicrosoftDestination");
|
||
});
|
||
});
|