From 44565e3a6222e9af1064e1dca55225cdf9fa2aa7 Mon Sep 17 00:00:00 2001 From: stock-manager-bot Date: Thu, 25 Jun 2026 19:50:02 +0200 Subject: [PATCH] test(cleanup): fix pre-existing test mocks and data --- .../assignments/assignment-form-pages.test.ts | 3 ++ tests/unit/app/people/person-pages.test.ts | 4 +++ tests/unit/services/user.service.test.ts | 34 +++++++++---------- 3 files changed, 24 insertions(+), 17 deletions(-) diff --git a/tests/unit/app/assignments/assignment-form-pages.test.ts b/tests/unit/app/assignments/assignment-form-pages.test.ts index c7b8ce4..56b4665 100644 --- a/tests/unit/app/assignments/assignment-form-pages.test.ts +++ b/tests/unit/app/assignments/assignment-form-pages.test.ts @@ -59,6 +59,9 @@ vi.mock("next/navigation", () => ({ useRouter: () => ({ push: mocks.push, }), + useSearchParams: () => ({ + get: vi.fn(() => null), + }), })) vi.mock("sonner", () => ({ diff --git a/tests/unit/app/people/person-pages.test.ts b/tests/unit/app/people/person-pages.test.ts index a6c2dae..c64a4c4 100644 --- a/tests/unit/app/people/person-pages.test.ts +++ b/tests/unit/app/people/person-pages.test.ts @@ -116,6 +116,8 @@ describe("person pages", () => { name: "Ada Lovelace", email: "ada@example.test", role: "ADMIN", + status: "ACTIVE", + deletedAt: null, isActive: true, createdAt: new Date("2024-01-01"), updatedAt: new Date("2024-01-01"), @@ -243,6 +245,8 @@ describe("person pages", () => { name: "Ada Lovelace", email: "ada@example.test", role: "ADMIN", + status: "ACTIVE", + deletedAt: null, isActive: true, createdAt: new Date("2024-01-01"), updatedAt: new Date("2024-01-01"), diff --git a/tests/unit/services/user.service.test.ts b/tests/unit/services/user.service.test.ts index 9b5d8ca..6926fe7 100644 --- a/tests/unit/services/user.service.test.ts +++ b/tests/unit/services/user.service.test.ts @@ -12,19 +12,19 @@ import { describe("getUserById", () => { it("does not select passwordHash across the broad user lookup boundary", async () => { - const findUnique = vi.fn().mockResolvedValue(null) + const findFirst = vi.fn().mockResolvedValue(null) const db = { user: { - findUnique, + findFirst, }, } await getUserById("user-1", db as never) - expect(findUnique).toHaveBeenCalledWith({ - where: { + expect(findFirst).toHaveBeenCalledWith({ + where: expect.objectContaining({ id: "user-1", - }, + }), select: expect.not.objectContaining({ passwordHash: true, }), @@ -34,19 +34,19 @@ describe("getUserById", () => { describe("getUserByEmail", () => { it("queries emailNormalized with a normalized email", async () => { - const findUnique = vi.fn().mockResolvedValue(null) + const findFirst = vi.fn().mockResolvedValue(null) const db = { user: { - findUnique, + findFirst, }, } await getUserByEmail(" Admin@Example.Test ", db as never) - expect(findUnique).toHaveBeenCalledWith({ - where: { + expect(findFirst).toHaveBeenCalledWith({ + where: expect.objectContaining({ emailNormalized: "admin@example.test", - }, + }), select: expect.not.objectContaining({ passwordHash: true, }), @@ -54,7 +54,7 @@ describe("getUserByEmail", () => { }) it("does not return passwordHash across the broad user lookup boundary", async () => { - const findUnique = vi.fn().mockResolvedValue({ + const findFirst = vi.fn().mockResolvedValue({ id: "user-1", name: "Admin", email: "admin@example.test", @@ -65,7 +65,7 @@ describe("getUserByEmail", () => { }) const db = { user: { - findUnique, + findFirst, }, } @@ -77,19 +77,19 @@ describe("getUserByEmail", () => { describe("getUserCredentialsByEmail", () => { it("selects passwordHash only for credential verification", async () => { - const findUnique = vi.fn().mockResolvedValue(null) + const findFirst = vi.fn().mockResolvedValue(null) const db = { user: { - findUnique, + findFirst, }, } await getUserCredentialsByEmail("Admin@Example.Test", db as never) - expect(findUnique).toHaveBeenCalledWith({ - where: { + expect(findFirst).toHaveBeenCalledWith({ + where: expect.objectContaining({ emailNormalized: "admin@example.test", - }, + }), select: expect.objectContaining({ passwordHash: true, }),