diff --git a/src/hooks.server.test.ts b/src/hooks.server.test.ts index 3fc4de1..e7a051c 100644 --- a/src/hooks.server.test.ts +++ b/src/hooks.server.test.ts @@ -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: {}, diff --git a/src/lib/tests/const.ts b/src/lib/tests/const.ts new file mode 100644 index 0000000..900d6a8 --- /dev/null +++ b/src/lib/tests/const.ts @@ -0,0 +1,5 @@ +export const mockCookies = { + get: () => undefined, + set: () => undefined, + delete: () => undefined, +}; diff --git a/src/routes/api/auth/invite/__tests__/invite.test.ts b/src/routes/api/auth/invite/__tests__/invite.test.ts index ce41de0..79c9dd7 100644 --- a/src/routes/api/auth/invite/__tests__/invite.test.ts +++ b/src/routes/api/auth/invite/__tests__/invite.test.ts @@ -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, diff --git a/src/routes/api/auth/session/__tests__/server.test.ts b/src/routes/api/auth/session/__tests__/server.test.ts index 99ed6d3..614d6ba 100644 --- a/src/routes/api/auth/session/__tests__/server.test.ts +++ b/src/routes/api/auth/session/__tests__/server.test.ts @@ -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, diff --git a/src/routes/api/tenants/tenants.test.ts b/src/routes/api/tenants/tenants.test.ts index 2685f74..9a5cb21 100644 --- a/src/routes/api/tenants/tenants.test.ts +++ b/src/routes/api/tenants/tenants.test.ts @@ -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,