Fix some issues from vitest update

This commit is contained in:
Karl Ludwig Weise
2026-06-03 21:10:47 +02:00
parent c58e32cee2
commit 6f13926edc
5 changed files with 156 additions and 21 deletions
@@ -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(),
})),
})),
})),
};
@@ -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(),
})),
})),
};
+6 -6
View File
@@ -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
@@ -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
+1 -1
View File
@@ -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"));