Release Label Tools 0.1.0
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { augmentRecords, parseMergeData } from "../../src/labels/data";
|
||||
|
||||
describe("label merge data", () => {
|
||||
it("parses quoted CSV and bounded JSON records", () => {
|
||||
expect(
|
||||
parseMergeData('name,address\n"Ada, A.","Line 1\nLine 2"', "csv"),
|
||||
).toEqual([{ name: "Ada, A.", address: "Line 1\nLine 2" }]);
|
||||
expect(
|
||||
parseMergeData('[{"name":"Grace","meta":{"team":"Compiler"}}]', "json"),
|
||||
).toEqual([{ name: "Grace", "meta.team": "Compiler" }]);
|
||||
});
|
||||
|
||||
it("rejects duplicate CSV headers and dangerous JSON keys", () => {
|
||||
expect(() => parseMergeData("name,name\na,b", "csv")).toThrow(/unique/iu);
|
||||
expect(() => parseMergeData('[{"__proto__":{"x":1}}]', "json")).toThrow(
|
||||
/Dangerous JSON/iu,
|
||||
);
|
||||
});
|
||||
|
||||
it("adds deterministic serials and injected secure random bytes", () => {
|
||||
const records = augmentRecords(
|
||||
[{ name: "Ada" }],
|
||||
{
|
||||
count: 2,
|
||||
serialPrefix: "A-",
|
||||
serialStart: 7,
|
||||
serialPadding: 3,
|
||||
randomLength: 4,
|
||||
},
|
||||
(length) => new Uint8Array(length).fill(0),
|
||||
);
|
||||
expect(records).toEqual([
|
||||
{ name: "Ada", __row: "1", __serial: "A-007", __random: "AAAA" },
|
||||
{ __row: "2", __serial: "A-008", __random: "AAAA" },
|
||||
]);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user