Compare commits

...

2 Commits

Author SHA1 Message Date
Chris Farhood 746b0fb9c6 fix(GRO-1272): address QA review items for rbac.test.ts
CI / Lint & Typecheck (pull_request) Failing after 15s
CI / Test (pull_request) Failing after 20s
CI / Build (pull_request) Has been skipped
CI / Build & Push Docker Images (pull_request) Has been skipped
CI / Update Infra Image Tags (pull_request) Has been skipped
- Rename insertedStaff to _insertedStaff (ESLint unused var, line 49)
- Rename table param to _table in insert mock (ESLint unused param, line 91)
- Fix buildApp jwtPayload to prefer userLookupResult.id over staffLookupResult.userId
  (corrects auto-provision test failures where sub was 'unknown-sub' instead of 'ba-user-new')

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-20 13:37:49 +00:00
Chris Farhood 5bbbcceabf fix(GRO-1272): fix TS2769 and test mock iterable issues
CI / Lint & Typecheck (pull_request) Failing after 14s
CI / Test (pull_request) Failing after 20s
CI / Build (pull_request) Has been skipped
CI / Build & Push Docker Images (pull_request) Has been skipped
CI / Update Infra Image Tags (pull_request) Has been skipped
- Add null guard for newStaff after .returning() in auto-provision block
- Make buildQuery() iterable without .limit() call (for WHERE-only queries)
- Use fallback in .limit() for manager-fallback dev-mode tests

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-20 13:19:23 +00:00
2 changed files with 19 additions and 12 deletions
+16 -12
View File
@@ -46,7 +46,7 @@ const GROOMER: StaffRow = {
let staffLookupResult: StaffRow | null = null; let staffLookupResult: StaffRow | null = null;
let managerFallbackResult: StaffRow | null = MANAGER; let managerFallbackResult: StaffRow | null = MANAGER;
let userLookupResult: { id: string; name: string | null; email: string | null } | null = null; let userLookupResult: { id: string; name: string | null; email: string | null } | null = null;
let insertedStaff: StaffRow | null = null; let _insertedStaff: StaffRow | null = null;
vi.mock("../db", () => { vi.mock("../db", () => {
const makeTableProxy = (name: string) => const makeTableProxy = (name: string) =>
@@ -65,13 +65,17 @@ vi.mock("../db", () => {
const user = makeTableProxy("user"); const user = makeTableProxy("user");
const buildQuery = (result: unknown, fallback: unknown) => ({ const buildQuery = (result: unknown, fallback: unknown) => ({
limit: () => ({ [Symbol.iterator]: function* () {
[Symbol.iterator]: function* () { if (result) yield result;
if (result) yield result; },
}, limit: (_n: number) => {
0: result, const item = result ?? fallback;
length: result ? 1 : 0, return {
}), [Symbol.iterator]: function* () { if (item) yield item; },
0: item,
length: item ? 1 : 0,
};
},
}); });
return { return {
@@ -84,7 +88,7 @@ vi.mock("../db", () => {
), ),
}), }),
}), }),
insert: (table: unknown) => ({ insert: (_table: unknown) => ({
values: (vals: Record<string, unknown>) => ({ values: (vals: Record<string, unknown>) => ({
returning: () => { returning: () => {
const newStaff: StaffRow = { const newStaff: StaffRow = {
@@ -100,7 +104,7 @@ vi.mock("../db", () => {
createdAt: new Date(), createdAt: new Date(),
updatedAt: new Date(), updatedAt: new Date(),
}; };
insertedStaff = newStaff; _insertedStaff = newStaff;
return [newStaff]; return [newStaff];
}, },
}), }),
@@ -120,7 +124,7 @@ function resetMocks() {
staffLookupResult = null; staffLookupResult = null;
managerFallbackResult = MANAGER; managerFallbackResult = MANAGER;
userLookupResult = null; userLookupResult = null;
insertedStaff = null; _insertedStaff = null;
} }
/** Build a minimal Hono app with jwtPayload pre-set, then apply a middleware. */ /** Build a minimal Hono app with jwtPayload pre-set, then apply a middleware. */
@@ -130,7 +134,7 @@ function buildApp(
) { ) {
const app = new Hono<AppEnv>(); const app = new Hono<AppEnv>();
app.use("*", async (c, next) => { app.use("*", async (c, next) => {
c.set("jwtPayload", { sub: staffLookupResult?.userId ?? "unknown-sub" }); c.set("jwtPayload", { sub: userLookupResult?.id ?? staffLookupResult?.userId ?? "unknown-sub" });
await next(); await next();
}); });
app.use("*", middleware); app.use("*", middleware);
+3
View File
@@ -130,6 +130,9 @@ export const resolveStaffMiddleware: MiddlewareHandler<AppEnv> = async (
active: true, active: true,
}) })
.returning(); .returning();
if (!newStaff) {
return c.json({ error: "Internal error: staff record creation failed" }, 500);
}
c.set("staff", newStaff); c.set("staff", newStaff);
await next(); await next();
return; return;