lint: fix biome issues in new test files and helpers
CI / check (push) Failing after 34s
CI / preflight (push) Skipped
CI / deploy (push) Skipped

This commit is contained in:
openhands committed 2026-09-21 18:19:39 +02:00
1 parent 99eb3af17b
commit 93862c2275
41 files changed
+488 -314

No files matched your search

+34 -15
View File
@@ -3,7 +3,12 @@ import { z } from "zod";
const state = vi.hoisted(() => ({
allowed: [] as string[],
watches: [] as { id: number; staffId: number; targetUserId: number; reason: string }[],
watches: [] as {
id: number;
staffId: number;
targetUserId: number;
reason: string;
}[],
insertCall: undefined as unknown,
deleteCall: undefined as unknown,
}));
@@ -19,7 +24,10 @@ const actionErrorClass = vi.hoisted(
);
vi.mock("@/lib/safe-action", () => ({
adminAction: (opts: { permission?: string | readonly string[]; schema?: z.ZodType }, handler: (ctx: any) => unknown) => {
adminAction: (
opts: { permission?: string | readonly string[]; schema?: z.ZodType },
handler: (ctx: any) => unknown,
) => {
return async (input: unknown) => {
const needed = Array.isArray(opts.permission)
? opts.permission
@@ -73,9 +81,11 @@ vi.mock("@/lib/db", async () => {
return [];
});
db.insert = vi.fn((table) => ({
values: (
values: { staffId: number; targetUserId: number; reason: string },
) => {
values: (values: {
staffId: number;
targetUserId: number;
reason: string;
}) => {
state.insertCall = { table, values };
return Promise.resolve([{ insertId: 1n }]);
},
@@ -101,14 +111,19 @@ beforeEach(() => {
describe("toggleUserWatch", () => {
it("creates a watch when none exists and returns watching: true", async () => {
const res = await toggleUserWatch({ targetUserId: 42, reason: "suspicious" });
const res = await toggleUserWatch({
targetUserId: 42,
reason: "suspicious",
});
expect(res).toEqual({ ok: true, data: { watching: true } });
expect(state.insertCall.values).toEqual({
staffId: 100,
targetUserId: 42,
reason: "suspicious",
});
expect(mockRevalidateTag).toHaveBeenCalledWith("user-watch:100", { expire: 0 });
expect(mockRevalidateTag).toHaveBeenCalledWith("user-watch:100", {
expire: 0,
});
});
it("defaults the reason to an empty string", async () => {
@@ -125,7 +140,9 @@ describe("toggleUserWatch", () => {
const res = await toggleUserWatch({ targetUserId: 42 });
expect(res).toEqual({ ok: true, data: { watching: false } });
expect(state.deleteCall.condition).toBeDefined();
expect(mockRevalidateTag).toHaveBeenCalledWith("user-watch:100", { expire: 0 });
expect(mockRevalidateTag).toHaveBeenCalledWith("user-watch:100", {
expire: 0,
});
});
it("requires the users view permission", async () => {
@@ -137,14 +154,16 @@ describe("toggleUserWatch", () => {
});
it("rejects invalid target user ids and oversized reasons", async () => {
expect(
await toggleUserWatch({ targetUserId: -1 }),
).toMatchObject({ ok: false, error: "Validation failed" });
expect(
await toggleUserWatch({ targetUserId: 0 }),
).toMatchObject({ ok: false, error: "Validation failed" });
expect(await toggleUserWatch({ targetUserId: -1 })).toMatchObject({
ok: false,
error: "Validation failed",
});
expect(await toggleUserWatch({ targetUserId: 0 })).toMatchObject({
ok: false,
error: "Validation failed",
});
expect(
await toggleUserWatch({ targetUserId: 1, reason: "x".repeat(256) }),
).toMatchObject({ ok: false, error: "Validation failed" });
});
});
});