Fix tests

This commit is contained in:
Karl Ludwig Weise
2025-09-25 16:04:29 +02:00
parent 6aefac8a02
commit fdb0441739
5 changed files with 21 additions and 12 deletions
+4 -3
View File
@@ -1,6 +1,7 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
import { handle } from "./hooks.server";
import { mockCookies } from "$lib/tests/const";
// Mock the startup service
vi.mock("$lib/server/services/startup-service", () => ({
@@ -61,7 +62,7 @@ describe("hooks.server", () => {
return {
url: new URL("http://localhost/api/health"),
request,
cookies: {} as any,
cookies: mockCookies as any,
fetch: {} as any,
getClientAddress: () => ip,
locals: {},
@@ -131,7 +132,7 @@ describe("hooks.server", () => {
"x-forwarded-for": "192.168.2.1", // Different IP for CORS tests
},
}),
cookies: {} as any,
cookies: mockCookies as any,
fetch: {} as any,
getClientAddress: () => "192.168.2.1",
locals: {},
@@ -178,7 +179,7 @@ describe("hooks.server", () => {
"x-forwarded-for": "192.168.3.1", // Different IP for security tests
},
}),
cookies: {} as any,
cookies: mockCookies as any,
fetch: {} as any,
getClientAddress: () => "192.168.3.1",
locals: {},
+5
View File
@@ -0,0 +1,5 @@
export const mockCookies = {
get: () => undefined,
set: () => undefined,
delete: () => undefined,
};
@@ -29,6 +29,7 @@ vi.mock("$env/dynamic/private", () => ({
import { TenantAdminService } from "$lib/server/services/tenant-admin-service";
import { InviteService } from "$lib/server/services/invite-service";
import { sendUserInviteEmail } from "$lib/server/email/email-service";
import { mockCookies } from "$lib/tests/const";
describe("POST /api/auth/invite", () => {
const mockTenant = {
@@ -73,7 +74,7 @@ describe("POST /api/auth/invite", () => {
url: new URL("http://localhost/api/auth/invite"),
params: {},
route: { id: "/api/auth/invite" } as any,
cookies: {} as any,
cookies: mockCookies as any,
fetch: {} as any,
getClientAddress: () => "127.0.0.1",
isDataRequest: false,
@@ -2,6 +2,7 @@
import { describe, it, expect, vi } from "vitest";
import { GET } from "../+server";
import type { RequestEvent } from "@sveltejs/kit";
import { mockCookies } from "$lib/tests/const";
// Mock the logger
vi.mock("$lib/logger", () => ({
@@ -25,7 +26,7 @@ const createMockRequestEvent = (locals: any): RequestEvent =>
url: new URL("http://localhost/api/auth/session"),
params: {},
route: { id: "/api/auth/session" },
cookies: {} as any,
cookies: mockCookies as any,
fetch: fetch,
getClientAddress: () => "127.0.0.1",
isDataRequest: false,
+8 -7
View File
@@ -3,6 +3,7 @@ import { describe, it, expect, vi, beforeEach } from "vitest";
import { POST } from "./+server.js";
import { GET } from "./config/defaults/+server.js";
import { ERRORS } from "$lib/errors.js";
import { mockCookies } from "$lib/tests/const.js";
// Mock the TenantAdminService
vi.mock("$lib/server/services/tenant-admin-service", () => ({
@@ -67,7 +68,7 @@ describe("/api/tenants", () => {
url: new URL("http://localhost"),
params: {},
route: { id: "" },
cookies: {} as any,
cookies: mockCookies as any,
fetch: {} as any,
getClientAddress: () => "",
isDataRequest: false,
@@ -118,7 +119,7 @@ describe("/api/tenants", () => {
url: new URL("http://localhost"),
params: {},
route: { id: "" },
cookies: {} as any,
cookies: mockCookies as any,
fetch: {} as any,
getClientAddress: () => "",
isDataRequest: false,
@@ -167,7 +168,7 @@ describe("/api/tenants", () => {
url: new URL("http://localhost"),
params: {},
route: { id: "" },
cookies: {} as any,
cookies: mockCookies as any,
fetch: {} as any,
getClientAddress: () => "",
isDataRequest: false,
@@ -207,7 +208,7 @@ describe("/api/tenants", () => {
url: new URL("http://localhost"),
params: {},
route: { id: "" },
cookies: {} as any,
cookies: mockCookies as any,
fetch: {} as any,
getClientAddress: () => "",
isDataRequest: false,
@@ -247,7 +248,7 @@ describe("/api/tenants", () => {
url: new URL("http://localhost"),
params: {},
route: { id: "" },
cookies: {} as any,
cookies: mockCookies as any,
fetch: {} as any,
getClientAddress: () => "",
isDataRequest: false,
@@ -293,7 +294,7 @@ describe("/api/tenants", () => {
url: new URL("http://localhost"),
params: {},
route: { id: "" },
cookies: {} as any,
cookies: mockCookies as any,
fetch: {} as any,
getClientAddress: () => "",
isDataRequest: false,
@@ -321,7 +322,7 @@ describe("/api/tenants", () => {
url: new URL("http://localhost"),
params: {},
route: { id: "" },
cookies: {} as any,
cookies: mockCookies as any,
fetch: {} as any,
getClientAddress: () => "",
isDataRequest: false,