From 6f13926edc0df1e019e35bbbcf0aae308c554b52 Mon Sep 17 00:00:00 2001 From: Karl Ludwig Weise Date: Wed, 3 Jun 2026 21:10:47 +0200 Subject: [PATCH] Fix some issues from vitest update --- .../services/__tests__/agent-service.test.ts | 129 ++++++++++++++++++ .../__tests__/notification-service.test.ts | 22 +-- src/routes/api/admin/tenant/server.test.ts | 12 +- .../api/auth/session/__tests__/server.test.ts | 12 +- vite.config.ts | 2 +- 5 files changed, 156 insertions(+), 21 deletions(-) diff --git a/src/lib/server/services/__tests__/agent-service.test.ts b/src/lib/server/services/__tests__/agent-service.test.ts index 3a18f00..724c190 100644 --- a/src/lib/server/services/__tests__/agent-service.test.ts +++ b/src/lib/server/services/__tests__/agent-service.test.ts @@ -174,6 +174,7 @@ describe("AgentService", () => { const insertChain = { values: vi.fn(() => ({ returning: vi.fn().mockResolvedValue([mockAgent]), + onConflictDoNothing: vi.fn(), })), }; mockDb.insert.mockReturnValue(insertChain); @@ -209,6 +210,7 @@ describe("AgentService", () => { const insertChain = { values: vi.fn(() => ({ returning: vi.fn().mockRejectedValue(new Error("DB error")), + onConflictDoNothing: vi.fn(), })), }; mockDb.insert.mockReturnValue(insertChain); @@ -233,6 +235,13 @@ describe("AgentService", () => { from: vi.fn(() => ({ where: vi.fn(() => ({ limit: vi.fn().mockResolvedValue([mockAgent]), + orderBy: vi.fn(), + })), + orderBy: vi.fn(), + innerJoin: vi.fn(() => ({ + where: vi.fn(() => ({ + orderBy: vi.fn(), + })), })), })), }; @@ -249,6 +258,13 @@ describe("AgentService", () => { from: vi.fn(() => ({ where: vi.fn(() => ({ limit: vi.fn().mockResolvedValue([]), + orderBy: vi.fn(), + })), + orderBy: vi.fn(), + innerJoin: vi.fn(() => ({ + where: vi.fn(() => ({ + orderBy: vi.fn(), + })), })), })), }; @@ -264,6 +280,13 @@ describe("AgentService", () => { from: vi.fn(() => ({ where: vi.fn(() => ({ limit: vi.fn().mockRejectedValue(new Error("DB error")), + orderBy: vi.fn(), + })), + orderBy: vi.fn(), + innerJoin: vi.fn(() => ({ + where: vi.fn(() => ({ + orderBy: vi.fn(), + })), })), })), }; @@ -285,8 +308,15 @@ describe("AgentService", () => { const selectChain = { from: vi.fn(() => ({ where: vi.fn(() => ({ + limit: vi.fn(), orderBy: vi.fn().mockResolvedValue(agents), })), + orderBy: vi.fn(), + innerJoin: vi.fn(() => ({ + where: vi.fn(() => ({ + orderBy: vi.fn(), + })), + })), })), }; mockDb.select.mockReturnValue(selectChain); @@ -301,8 +331,15 @@ describe("AgentService", () => { const selectChain = { from: vi.fn(() => ({ where: vi.fn(() => ({ + limit: vi.fn(), orderBy: vi.fn().mockResolvedValue([]), })), + orderBy: vi.fn(), + innerJoin: vi.fn(() => ({ + where: vi.fn(() => ({ + orderBy: vi.fn(), + })), + })), })), }; mockDb.select.mockReturnValue(selectChain); @@ -317,8 +354,15 @@ describe("AgentService", () => { const selectChain = { from: vi.fn(() => ({ where: vi.fn(() => ({ + limit: vi.fn(), orderBy: vi.fn().mockRejectedValue(new Error("DB error")), })), + orderBy: vi.fn(), + innerJoin: vi.fn(() => ({ + where: vi.fn(() => ({ + orderBy: vi.fn(), + })), + })), })), }; mockDb.select.mockReturnValue(selectChain); @@ -490,6 +534,11 @@ describe("AgentService", () => { orderBy: vi.fn().mockResolvedValue(agents), })), })), + where: vi.fn(() => ({ + limit: vi.fn(), + orderBy: vi.fn(), + })), + orderBy: vi.fn(), })), }; mockDb.select.mockReturnValue(selectChain); @@ -507,6 +556,11 @@ describe("AgentService", () => { orderBy: vi.fn().mockResolvedValue([]), })), })), + where: vi.fn(() => ({ + limit: vi.fn(), + orderBy: vi.fn(), + })), + orderBy: vi.fn(), })), }; mockDb.select.mockReturnValue(selectChain); @@ -524,6 +578,11 @@ describe("AgentService", () => { orderBy: vi.fn().mockRejectedValue(new Error("DB error")), })), })), + where: vi.fn(() => ({ + limit: vi.fn(), + orderBy: vi.fn(), + })), + orderBy: vi.fn(), })), }; mockDb.select.mockReturnValue(selectChain); @@ -542,6 +601,7 @@ describe("AgentService", () => { it("should assign agent to channel successfully", async () => { const insertChain = { values: vi.fn(() => ({ + returning: vi.fn(), onConflictDoNothing: vi.fn().mockResolvedValue([]), })), }; @@ -558,6 +618,7 @@ describe("AgentService", () => { it("should handle database error", async () => { const insertChain = { values: vi.fn(() => ({ + returning: vi.fn(), onConflictDoNothing: vi.fn().mockRejectedValue(new Error("DB error")), })), }; @@ -629,6 +690,13 @@ describe("AgentService", () => { from: vi.fn(() => ({ where: vi.fn(() => ({ limit: vi.fn().mockResolvedValue([mockAgent]), + orderBy: vi.fn(), + })), + orderBy: vi.fn(), + innerJoin: vi.fn(() => ({ + where: vi.fn(() => ({ + orderBy: vi.fn(), + })), })), })), }; @@ -637,6 +705,12 @@ describe("AgentService", () => { const selectChainForOverlap = { from: vi.fn(() => ({ where: vi.fn().mockResolvedValue([]), + orderBy: vi.fn(), + innerJoin: vi.fn(() => ({ + where: vi.fn(() => ({ + orderBy: vi.fn(), + })), + })), })), }; @@ -649,6 +723,7 @@ describe("AgentService", () => { const insertChain = { values: vi.fn(() => ({ returning: vi.fn().mockResolvedValue([mockAbsence]), + onConflictDoNothing: vi.fn(), })), }; mockDb.insert.mockReturnValue(insertChain); @@ -702,6 +777,13 @@ describe("AgentService", () => { from: vi.fn(() => ({ where: vi.fn(() => ({ limit: vi.fn().mockResolvedValue([]), + orderBy: vi.fn(), + })), + orderBy: vi.fn(), + innerJoin: vi.fn(() => ({ + where: vi.fn(() => ({ + orderBy: vi.fn(), + })), })), })), }; @@ -724,6 +806,12 @@ describe("AgentService", () => { where: vi.fn(() => ({ limit: vi.fn().mockResolvedValue([mockAgent]), })), + orderBy: vi.fn(), + innerJoin: vi.fn(() => ({ + where: vi.fn(() => ({ + orderBy: vi.fn(), + })), + })), })), }; @@ -731,6 +819,12 @@ describe("AgentService", () => { const selectChainForOverlap = { from: vi.fn(() => ({ where: vi.fn().mockResolvedValue([mockAbsence]), + orderBy: vi.fn(), + innerJoin: vi.fn(() => ({ + where: vi.fn(() => ({ + orderBy: vi.fn(), + })), + })), })), }; @@ -750,6 +844,13 @@ describe("AgentService", () => { from: vi.fn(() => ({ where: vi.fn(() => ({ limit: vi.fn().mockResolvedValue([mockAbsence]), + orderBy: vi.fn(), + })), + orderBy: vi.fn(), + innerJoin: vi.fn(() => ({ + where: vi.fn(() => ({ + orderBy: vi.fn(), + })), })), })), }; @@ -765,6 +866,13 @@ describe("AgentService", () => { from: vi.fn(() => ({ where: vi.fn(() => ({ limit: vi.fn().mockResolvedValue([]), + orderBy: vi.fn(), + })), + orderBy: vi.fn(), + innerJoin: vi.fn(() => ({ + where: vi.fn(() => ({ + orderBy: vi.fn(), + })), })), })), }; @@ -825,6 +933,13 @@ describe("AgentService", () => { from: vi.fn(() => ({ where: vi.fn(() => ({ limit: vi.fn().mockResolvedValue([mockAbsence]), + orderBy: vi.fn(), + })), + orderBy: vi.fn(), + innerJoin: vi.fn(() => ({ + where: vi.fn(() => ({ + orderBy: vi.fn(), + })), })), })), }; @@ -863,6 +978,13 @@ describe("AgentService", () => { from: vi.fn(() => ({ where: vi.fn(() => ({ limit: vi.fn().mockResolvedValue([]), + orderBy: vi.fn(), + })), + orderBy: vi.fn(), + innerJoin: vi.fn(() => ({ + where: vi.fn(() => ({ + orderBy: vi.fn(), + })), })), })), }; @@ -883,6 +1005,13 @@ describe("AgentService", () => { from: vi.fn(() => ({ where: vi.fn(() => ({ limit: vi.fn().mockResolvedValue([mockAbsence]), + orderBy: vi.fn(), + })), + orderBy: vi.fn(), + innerJoin: vi.fn(() => ({ + where: vi.fn(() => ({ + orderBy: vi.fn(), + })), })), })), }; diff --git a/src/lib/server/services/__tests__/notification-service.test.ts b/src/lib/server/services/__tests__/notification-service.test.ts index 6fb7cb5..65e679d 100644 --- a/src/lib/server/services/__tests__/notification-service.test.ts +++ b/src/lib/server/services/__tests__/notification-service.test.ts @@ -13,14 +13,12 @@ vi.mock("../../db", () => ({ })); vi.mock("$lib/logger", () => ({ - UniversalLogger: vi.fn(() => ({ - setContext: vi.fn(() => ({ - debug: vi.fn(), - error: vi.fn(), - warn: vi.fn(), - info: vi.fn(), - })), - })), + UniversalLogger: class { + setContext = vi.fn().mockReturnThis(); + warn = vi.fn(); + error = vi.fn(); + info = vi.fn(); + }, default: { setContext: vi.fn(() => ({ debug: vi.fn(), @@ -245,6 +243,7 @@ describe("NotificationService", () => { const selectChain = { from: vi.fn(() => ({ where: vi.fn(() => ({ + limit: vi.fn(), orderBy: vi.fn().mockResolvedValue(mockNotifications), })), })), @@ -261,6 +260,7 @@ describe("NotificationService", () => { const selectChain = { from: vi.fn(() => ({ where: vi.fn(() => ({ + limit: vi.fn(), orderBy: vi.fn().mockResolvedValue([]), })), })), @@ -276,6 +276,7 @@ describe("NotificationService", () => { const selectChain = { from: vi.fn(() => ({ where: vi.fn(() => ({ + limit: vi.fn(), orderBy: vi.fn().mockRejectedValue(new Error("DB error")), })), })), @@ -298,6 +299,7 @@ describe("NotificationService", () => { from: vi.fn(() => ({ where: vi.fn(() => ({ limit: vi.fn().mockResolvedValue([{ id: "notification-123" }]), + orderBy: vi.fn(), })), })), }; @@ -313,6 +315,7 @@ describe("NotificationService", () => { from: vi.fn(() => ({ where: vi.fn(() => ({ limit: vi.fn().mockResolvedValue([]), + orderBy: vi.fn(), })), })), }; @@ -328,6 +331,7 @@ describe("NotificationService", () => { from: vi.fn(() => ({ where: vi.fn(() => ({ limit: vi.fn().mockRejectedValue(new Error("DB error")), + orderBy: vi.fn(), })), })), }; @@ -372,6 +376,7 @@ describe("NotificationService", () => { from: vi.fn(() => ({ where: vi.fn(() => ({ limit: vi.fn().mockResolvedValue([mockNotification]), + orderBy: vi.fn(), })), })), }; @@ -428,6 +433,7 @@ describe("NotificationService", () => { from: vi.fn(() => ({ where: vi.fn(() => ({ limit: vi.fn().mockResolvedValue([mockNotification]), + orderBy: vi.fn(), })), })), }; diff --git a/src/routes/api/admin/tenant/server.test.ts b/src/routes/api/admin/tenant/server.test.ts index 09ae961..a646585 100644 --- a/src/routes/api/admin/tenant/server.test.ts +++ b/src/routes/api/admin/tenant/server.test.ts @@ -59,12 +59,12 @@ vi.mock("$lib/server/auth/jwt-utils", () => ({ // Mock universal logger vi.mock("$lib/logger", () => ({ - UniversalLogger: vi.fn(() => ({ - setContext: vi.fn().mockReturnThis(), - warn: vi.fn(), - error: vi.fn(), - info: vi.fn(), - })), + UniversalLogger: class { + setContext = vi.fn().mockReturnThis(); + warn = vi.fn(); + error = vi.fn(); + info = vi.fn(); + }, })); // Mock openapi diff --git a/src/routes/api/auth/session/__tests__/server.test.ts b/src/routes/api/auth/session/__tests__/server.test.ts index bdd89a8..ea4fc15 100644 --- a/src/routes/api/auth/session/__tests__/server.test.ts +++ b/src/routes/api/auth/session/__tests__/server.test.ts @@ -6,12 +6,12 @@ import { mockCookies } from "$lib/tests/const"; // Mock the logger vi.mock("$lib/logger", () => ({ - UniversalLogger: vi.fn(() => ({ - setContext: vi.fn(() => ({ - error: vi.fn(), - debug: vi.fn(), - })), - })), + UniversalLogger: class { + setContext = vi.fn().mockReturnThis(); + warn = vi.fn(); + error = vi.fn(); + info = vi.fn(); + }, })); // Mock OpenAPI registration diff --git a/vite.config.ts b/vite.config.ts index 9e556d3..4f0b96b 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -2,7 +2,7 @@ import { paraglideVitePlugin } from "@inlang/paraglide-js"; import tailwindcss from "@tailwindcss/vite"; import { svelteTesting } from "@testing-library/svelte/vite"; import { sveltekit } from "@sveltejs/kit/vite"; -import { defineConfig } from "vite"; +import { defineConfig } from "vitest/config"; import { readFileSync } from "fs"; const pkg = JSON.parse(readFileSync(new URL("./package.json", import.meta.url), "utf8"));