From 0c2fb400a2635e397e338f99c1d67ec71635f1f3 Mon Sep 17 00:00:00 2001 From: Paperclip Date: Fri, 27 Mar 2026 20:57:54 +0000 Subject: [PATCH] test(api): update RBAC tests for Better-Auth userId (GRO-128) - Add userId field to mock staff records (MANAGER, RECEPTIONIST, GROOMER) - Update jwtPayload.sub to use userId instead of oidcSub in test helpers - Update dev mode X-Dev-User-Id header to use userId Co-Authored-By: Paperclip --- apps/api/src/__tests__/rbac.test.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/apps/api/src/__tests__/rbac.test.ts b/apps/api/src/__tests__/rbac.test.ts index 9d8c597..be67506 100644 --- a/apps/api/src/__tests__/rbac.test.ts +++ b/apps/api/src/__tests__/rbac.test.ts @@ -8,7 +8,7 @@ import type { AppEnv, StaffRow } from "../middleware/rbac.js"; const MANAGER: StaffRow = { id: "staff-manager-id", oidcSub: "oidc-manager-sub", - userId: null, + userId: "ba-user-manager", role: "manager", name: "Manager McManager", email: "manager@example.com", @@ -22,6 +22,7 @@ const RECEPTIONIST: StaffRow = { ...MANAGER, id: "staff-receptionist-id", oidcSub: "oidc-receptionist-sub", + userId: "ba-user-receptionist", role: "receptionist", name: "Receptionist Rita", email: "receptionist@example.com", @@ -31,6 +32,7 @@ const GROOMER: StaffRow = { ...MANAGER, id: "staff-groomer-id", oidcSub: "oidc-groomer-sub", + userId: "ba-user-groomer", role: "groomer", name: "Groomer Gary", email: "groomer@example.com", @@ -90,7 +92,7 @@ function buildApp( ) { const app = new Hono(); app.use("*", async (c, next) => { - c.set("jwtPayload", { sub: staffLookupResult?.oidcSub ?? "unknown-sub" }); + c.set("jwtPayload", { sub: staffLookupResult?.userId ?? "unknown-sub" }); await next(); }); app.use("*", middleware); @@ -107,7 +109,7 @@ function buildWithStaff( ) { const app = new Hono(); app.use("*", async (c, next) => { - c.set("jwtPayload", { sub: staffRow.oidcSub ?? "" }); + c.set("jwtPayload", { sub: staffRow.userId ?? "" }); c.set("staff", staffRow); await next(); }); @@ -166,7 +168,7 @@ describe("resolveStaffMiddleware", () => { }); const res = await app.request("/test", { - headers: { "X-Dev-User-Id": GROOMER.oidcSub! }, + headers: { "X-Dev-User-Id": GROOMER.userId! }, }); expect(res.status).toBe(200); expect(capturedStaff!.role).toBe("groomer");