Strengthen CI with Next build + Docker build and expand tests

Add docker-build and next build jobs so Dockerfile/image failures fail
CI. Expand unit coverage for exporters/Zod and integration coverage for
search, MCT import, backup, and token revoke.
This commit is contained in:
Cursor Agent
2026-08-23 23:34:04 +00:00
parent 5aa5fef9af
commit 9f4ec0a9c3
4 changed files with 183 additions and 11 deletions
+90
View File
@@ -0,0 +1,90 @@
import { describe, expect, it } from "vitest";
import { exportTag } from "@/lib/rfid/exporters";
import {
dumpDataSchema,
mifareClassicDumpSchema,
siteCreateSchema,
tagCreateSchema,
} from "@/lib/validation/rfid";
const classicDump = {
size: "1K" as const,
sectors: [
{
index: 0,
blocks: [
"04A1B2C304A1B2C304A1B2C304A1B2C3",
"00000000000000000000000000000000",
"00000000000000000000000000000000",
"FFFFFFFFFFFFFF078069FFFFFFFFFFFF",
],
},
],
};
const sampleTag = {
id: "00000000-0000-4000-8000-000000000001",
label: "Dock fob",
frequency: "HF",
protocol: "MIFARE_CLASSIC_1K",
uid: "04A1B2C3",
dumpData: classicDump,
keys: { A: ["FFFFFFFFFFFF"], B: [] },
notes: null as string | null,
};
describe("exporters", () => {
it("exports canonical JSON", () => {
const out = exportTag(sampleTag, "json");
expect(out.contentType).toBe("application/json");
const parsed = JSON.parse(out.body);
expect(parsed.uid).toBe("04A1B2C3");
expect(parsed.dumpData.size).toBe("1K");
});
it("exports proxmark JSON with blocks", () => {
const out = exportTag(sampleTag, "proxmark");
const parsed = JSON.parse(out.body);
expect(parsed.FileType).toBe("mfcard");
expect(parsed.blocks).toHaveLength(4);
expect(parsed.Card.UID).toBe("04A1B2C3");
});
it("exports MCT text", () => {
const out = exportTag(sampleTag, "mct");
expect(out.body).toContain("+UID: 04A1B2C3");
expect(out.body).toContain("+Sector: 0");
});
it("exports hex listing", () => {
const out = exportTag(sampleTag, "hex");
expect(out.body).toContain("# UID 04A1B2C3");
expect(out.body).toContain("S0B0");
});
});
describe("validation schemas", () => {
it("accepts valid classic dump", () => {
expect(mifareClassicDumpSchema.safeParse(classicDump).success).toBe(true);
expect(dumpDataSchema.safeParse(classicDump).success).toBe(true);
});
it("rejects invalid site codes", () => {
expect(
siteCreateSchema.safeParse({ name: "Lab", code: "bad code!" }).success
).toBe(false);
});
it("accepts valid tag create payload", () => {
const parsed = tagCreateSchema.safeParse({
siteId: "00000000-0000-4000-8000-000000000099",
label: "Dock",
frequency: "HF",
protocol: "MIFARE_CLASSIC_1K",
uid: "04:A1:B2:C3",
dumpData: classicDump,
keys: { A: ["FFFFFFFFFFFF"] },
});
expect(parsed.success).toBe(true);
});
});