mirror of
https://github.com/Chewbaccalakis/rfid-database.git
synced 2026-09-09 16:01:56 -07:00
Strengthen CI (Next + Docker build) and expand tests (#4)
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. Co-authored-by: Cursor Agent <[email protected]>
This commit is contained in:
co-authored by
Cursor Agent
parent
5aa5fef9af
commit
0e50c537ee
@@ -21,6 +21,10 @@ import { GET as getTags, POST as postTag } from "@/app/api/v1/tags/route";
|
||||
import { PUT as putByUid } from "@/app/api/v1/tags/by-uid/[uid]/route";
|
||||
import { GET as getExport } from "@/app/api/v1/tags/[id]/export/route";
|
||||
import { GET as listTokens, POST as createToken } from "@/app/api/v1/tokens/route";
|
||||
import { DELETE as deleteToken } from "@/app/api/v1/tokens/[id]/route";
|
||||
import { GET as search } from "@/app/api/v1/search/route";
|
||||
import { GET as getBackup, POST as postBackup } from "@/app/api/v1/backup/route";
|
||||
import { POST as importTag } from "@/app/api/v1/tags/import/route";
|
||||
import { NextRequest } from "next/server";
|
||||
|
||||
function req(url: string, init?: ConstructorParameters<typeof NextRequest>[1]) {
|
||||
@@ -189,9 +193,81 @@ describe("API v1 integration", () => {
|
||||
true
|
||||
);
|
||||
|
||||
const revoked = await deleteToken(
|
||||
req(`http://localhost/api/v1/tokens/${data.id}`, {
|
||||
method: "DELETE",
|
||||
headers: auth,
|
||||
}),
|
||||
{ params: Promise.resolve({ id: data.id }) }
|
||||
);
|
||||
expect(revoked.status).toBe(200);
|
||||
|
||||
const db = getDb();
|
||||
const user = db.select().from(users).where(eq(users.id, userId)).get();
|
||||
expect(user?.email).toBe("[email protected]");
|
||||
expect(db.select().from(sites).all().length).toBeGreaterThanOrEqual(0);
|
||||
});
|
||||
|
||||
it("searches, imports MCT, and backs up", async () => {
|
||||
const auth = { Authorization: `Bearer ${bearer}` };
|
||||
|
||||
const siteRes = await postSite(
|
||||
req("http://localhost/api/v1/sites", {
|
||||
method: "POST",
|
||||
headers: { ...auth, "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ code: "C", name: "Lab" }),
|
||||
})
|
||||
);
|
||||
const site = await siteRes.json();
|
||||
|
||||
const mct = `+UID: AABBCCDD
|
||||
+Sector: 0
|
||||
AABBCCDD00112233445566778899AABB
|
||||
00000000000000000000000000000000
|
||||
00000000000000000000000000000000
|
||||
FFFFFFFFFFFFFF078069FFFFFFFFFFFF
|
||||
`;
|
||||
|
||||
const imported = await importTag(
|
||||
req("http://localhost/api/v1/tags/import", {
|
||||
method: "POST",
|
||||
headers: { ...auth, "Content-Type": "application/json" },
|
||||
body: JSON.stringify({
|
||||
siteId: site.id,
|
||||
label: "Imported fob",
|
||||
content: mct,
|
||||
filename: "sample.mct",
|
||||
}),
|
||||
})
|
||||
);
|
||||
expect(imported.status).toBe(201);
|
||||
const tag = await imported.json();
|
||||
expect(tag.uid).toBe("AABBCCDD");
|
||||
|
||||
const searchRes = await search(
|
||||
req("http://localhost/api/v1/search?q=Imported", { headers: auth })
|
||||
);
|
||||
expect(searchRes.status).toBe(200);
|
||||
const found = await searchRes.json();
|
||||
expect(found.tags.some((t: { label: string }) => t.label === "Imported fob")).toBe(
|
||||
true
|
||||
);
|
||||
|
||||
const backupRes = await getBackup(
|
||||
req("http://localhost/api/v1/backup", { headers: auth })
|
||||
);
|
||||
expect(backupRes.status).toBe(200);
|
||||
const backup = await backupRes.json();
|
||||
expect(backup.sites.length).toBeGreaterThanOrEqual(1);
|
||||
expect(backup.tags.length).toBeGreaterThanOrEqual(1);
|
||||
|
||||
const restore = await postBackup(
|
||||
req("http://localhost/api/v1/backup", {
|
||||
method: "POST",
|
||||
headers: { ...auth, "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ ...backup, mode: "merge" }),
|
||||
})
|
||||
);
|
||||
expect(restore.status).toBe(200);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user