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 managerFallbackResult: StaffRow | null = MANAGER;
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", () => {
const makeTableProxy = (name: string) =>
@@ -65,13 +65,17 @@ vi.mock("../db", () => {
const user = makeTableProxy("user");
const buildQuery = (result: unknown, fallback: unknown) => ({
limit: () => ({
[Symbol.iterator]: function* () {
if (result) yield result;
},
0: result,
length: result ? 1 : 0,
}),
[Symbol.iterator]: function* () {
if (result) yield result;
},
limit: (_n: number) => {
const item = result ?? fallback;
return {
[Symbol.iterator]: function* () { if (item) yield item; },
0: item,
length: item ? 1 : 0,
};
},
});
return {
@@ -84,7 +88,7 @@ vi.mock("../db", () => {
),
}),
}),
insert: (table: unknown) => ({
insert: (_table: unknown) => ({
values: (vals: Record<string, unknown>) => ({
returning: () => {
const newStaff: StaffRow = {
@@ -100,7 +104,7 @@ vi.mock("../db", () => {
createdAt: new Date(),
updatedAt: new Date(),
};
insertedStaff = newStaff;
_insertedStaff = newStaff;
return [newStaff];
},
}),
@@ -120,7 +124,7 @@ function resetMocks() {
staffLookupResult = null;
managerFallbackResult = MANAGER;
userLookupResult = null;
insertedStaff = null;
_insertedStaff = null;
}
/** Build a minimal Hono app with jwtPayload pre-set, then apply a middleware. */
@@ -130,7 +134,7 @@ function buildApp(
) {
const app = new Hono<AppEnv>();
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();
});
app.use("*", middleware);
+3
View File
@@ -130,6 +130,9 @@ export const resolveStaffMiddleware: MiddlewareHandler<AppEnv> = async (
active: true,
})
.returning();
if (!newStaff) {
return c.json({ error: "Internal error: staff record creation failed" }, 500);
}
c.set("staff", newStaff);
await next();
return;