Initial release of Barcode Tools 0.1.0
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
createBarcodeZip,
|
||||
parseBatch,
|
||||
renderBarcodeSvg,
|
||||
} from "../../src/barcode/generate";
|
||||
import {
|
||||
buildStructuredPayload,
|
||||
gtinCheckDigit,
|
||||
validateGtin,
|
||||
} from "../../src/barcode/payloads";
|
||||
|
||||
describe("barcode generation", () => {
|
||||
it("renders inert scalable QR output", () => {
|
||||
const result = renderBarcodeSvg({
|
||||
format: "qrcode",
|
||||
text: "https://example.com",
|
||||
scale: 3,
|
||||
padding: 8,
|
||||
includeText: false,
|
||||
});
|
||||
expect(result.svg).toMatch(/^<svg/u);
|
||||
expect(result.svg).not.toMatch(/<script|\bon\w+=|href=/iu);
|
||||
expect(result.width).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it("creates deterministic named batch archives", () => {
|
||||
const rows = parseBatch('first,hello\n"second",world');
|
||||
const first = createBarcodeZip(rows, {
|
||||
format: "qrcode",
|
||||
scale: 2,
|
||||
padding: 8,
|
||||
includeText: false,
|
||||
});
|
||||
const second = createBarcodeZip(rows, {
|
||||
format: "qrcode",
|
||||
scale: 2,
|
||||
padding: 8,
|
||||
includeText: false,
|
||||
});
|
||||
expect(first).toEqual(second);
|
||||
});
|
||||
});
|
||||
|
||||
describe("structured payloads", () => {
|
||||
it("escapes Wi-Fi delimiter characters", () =>
|
||||
expect(
|
||||
buildStructuredPayload("wifi", {
|
||||
primary: "lab;guest",
|
||||
secondary: "p:a\\ss",
|
||||
tertiary: "WPA",
|
||||
hidden: true,
|
||||
}),
|
||||
).toBe("WIFI:T:WPA;S:lab\\;guest;P:p\\:a\\\\ss;H:true;;"));
|
||||
it("rejects injected or unsupported Wi-Fi security fields", () => {
|
||||
expect(() =>
|
||||
buildStructuredPayload("wifi", {
|
||||
primary: "lab",
|
||||
tertiary: "WPA;S:other",
|
||||
}),
|
||||
).toThrow(/WPA, WEP, or nopass/u);
|
||||
});
|
||||
it("calculates and validates GTIN check digits", () => {
|
||||
expect(gtinCheckDigit("400638133393")).toBe(1);
|
||||
expect(validateGtin("4006381333931")).toEqual({
|
||||
valid: true,
|
||||
expected: "1",
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user