Files
demat-facturation/server/databaseBackup.test.ts

22 lines
857 B
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { describe, expect, it } from "vitest";
import { toSqlLiteral } from "./databaseBackup";
describe("toSqlLiteral", () => {
it("sérialise les valeurs primitives de manière importable", () => {
expect(toSqlLiteral(null)).toBe("NULL");
expect(toSqlLiteral(undefined)).toBe("NULL");
expect(toSqlLiteral(42.5)).toBe("42.5");
expect(toSqlLiteral(true)).toBe("1");
expect(toSqlLiteral(false)).toBe("0");
});
it("échappe les caractères sensibles dune chaîne SQL", () => {
expect(toSqlLiteral("O'Hara\\facture\nligne")).toBe("'O\\'Hara\\\\facture\\nligne'");
});
it("conserve les données binaires et dates sans conversion ambiguë", () => {
expect(toSqlLiteral(Buffer.from([0, 255]))).toBe("X'00ff'");
expect(toSqlLiteral(new Date("2026-08-17T12:34:56.000Z"))).toBe("'2026-08-17 12:34:56.000'");
});
});