test(project): cover image config checks

This commit is contained in:
2026-03-30 12:24:33 +02:00
parent 732538857b
commit d7c295b51c
@@ -110,6 +110,14 @@ function createProtectedCaller(db: Record<string, unknown>) {
}); });
} }
function createUnauthenticatedCaller(db: Record<string, unknown>) {
return createCaller({
session: null,
db: db as never,
dbUser: null,
});
}
function createProtectedCallerWithOverrides( function createProtectedCallerWithOverrides(
db: Record<string, unknown>, db: Record<string, unknown>,
overrides: { granted?: PermissionKey[]; denied?: PermissionKey[] } | null, overrides: { granted?: PermissionKey[]; denied?: PermissionKey[] } | null,
@@ -157,6 +165,57 @@ describe("project router", () => {
vi.clearAllMocks(); vi.clearAllMocks();
}); });
describe("configuration checks", () => {
it("requires authentication for image generation configuration checks", async () => {
const findUnique = vi.fn();
const caller = createUnauthenticatedCaller({
systemSettings: {
findUnique,
},
});
await expect(caller.isImageGenConfigured()).rejects.toMatchObject({
code: "UNAUTHORIZED",
message: "Authentication required",
});
await expect(caller.isDalleConfigured()).rejects.toMatchObject({
code: "UNAUTHORIZED",
message: "Authentication required",
});
expect(findUnique).not.toHaveBeenCalled();
});
it("returns only narrow readiness data for authenticated callers", async () => {
const findUnique = vi.fn().mockResolvedValue({
id: "singleton",
imageProvider: "dalle",
});
const caller = createProtectedCaller({
systemSettings: {
findUnique,
},
});
const imageGen = await caller.isImageGenConfigured();
const dalle = await caller.isDalleConfigured();
expect(imageGen).toEqual({
configured: false,
provider: "dalle",
});
expect(dalle).toEqual({
configured: false,
});
expect(findUnique).toHaveBeenNthCalledWith(1, {
where: { id: "singleton" },
});
expect(findUnique).toHaveBeenNthCalledWith(2, {
where: { id: "singleton" },
});
});
});
// ─── create ─────────────────────────────────────────────────────────────── // ─── create ───────────────────────────────────────────────────────────────
describe("create", () => { describe("create", () => {