mirror of
https://github.com/Chewbaccalakis/rfid-database.git
synced 2026-09-10 00:11:56 -07:00
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:
@@ -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);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user