test(cleanup): fix pre-existing test mocks and data

This commit is contained in:
stock-manager-bot
2026-06-25 19:50:02 +02:00
parent 18e274ef37
commit 44565e3a62
3 changed files with 24 additions and 17 deletions
@@ -59,6 +59,9 @@ vi.mock("next/navigation", () => ({
useRouter: () => ({ useRouter: () => ({
push: mocks.push, push: mocks.push,
}), }),
useSearchParams: () => ({
get: vi.fn(() => null),
}),
})) }))
vi.mock("sonner", () => ({ vi.mock("sonner", () => ({
@@ -116,6 +116,8 @@ describe("person pages", () => {
name: "Ada Lovelace", name: "Ada Lovelace",
email: "ada@example.test", email: "ada@example.test",
role: "ADMIN", role: "ADMIN",
status: "ACTIVE",
deletedAt: null,
isActive: true, isActive: true,
createdAt: new Date("2024-01-01"), createdAt: new Date("2024-01-01"),
updatedAt: new Date("2024-01-01"), updatedAt: new Date("2024-01-01"),
@@ -243,6 +245,8 @@ describe("person pages", () => {
name: "Ada Lovelace", name: "Ada Lovelace",
email: "ada@example.test", email: "ada@example.test",
role: "ADMIN", role: "ADMIN",
status: "ACTIVE",
deletedAt: null,
isActive: true, isActive: true,
createdAt: new Date("2024-01-01"), createdAt: new Date("2024-01-01"),
updatedAt: new Date("2024-01-01"), updatedAt: new Date("2024-01-01"),
+17 -17
View File
@@ -12,19 +12,19 @@ import {
describe("getUserById", () => { describe("getUserById", () => {
it("does not select passwordHash across the broad user lookup boundary", async () => { 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 = { const db = {
user: { user: {
findUnique, findFirst,
}, },
} }
await getUserById("user-1", db as never) await getUserById("user-1", db as never)
expect(findUnique).toHaveBeenCalledWith({ expect(findFirst).toHaveBeenCalledWith({
where: { where: expect.objectContaining({
id: "user-1", id: "user-1",
}, }),
select: expect.not.objectContaining({ select: expect.not.objectContaining({
passwordHash: true, passwordHash: true,
}), }),
@@ -34,19 +34,19 @@ describe("getUserById", () => {
describe("getUserByEmail", () => { describe("getUserByEmail", () => {
it("queries emailNormalized with a normalized email", async () => { it("queries emailNormalized with a normalized email", async () => {
const findUnique = vi.fn().mockResolvedValue(null) const findFirst = vi.fn().mockResolvedValue(null)
const db = { const db = {
user: { user: {
findUnique, findFirst,
}, },
} }
await getUserByEmail(" Admin@Example.Test ", db as never) await getUserByEmail(" Admin@Example.Test ", db as never)
expect(findUnique).toHaveBeenCalledWith({ expect(findFirst).toHaveBeenCalledWith({
where: { where: expect.objectContaining({
emailNormalized: "admin@example.test", emailNormalized: "admin@example.test",
}, }),
select: expect.not.objectContaining({ select: expect.not.objectContaining({
passwordHash: true, passwordHash: true,
}), }),
@@ -54,7 +54,7 @@ describe("getUserByEmail", () => {
}) })
it("does not return passwordHash across the broad user lookup boundary", async () => { 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", id: "user-1",
name: "Admin", name: "Admin",
email: "admin@example.test", email: "admin@example.test",
@@ -65,7 +65,7 @@ describe("getUserByEmail", () => {
}) })
const db = { const db = {
user: { user: {
findUnique, findFirst,
}, },
} }
@@ -77,19 +77,19 @@ describe("getUserByEmail", () => {
describe("getUserCredentialsByEmail", () => { describe("getUserCredentialsByEmail", () => {
it("selects passwordHash only for credential verification", async () => { it("selects passwordHash only for credential verification", async () => {
const findUnique = vi.fn().mockResolvedValue(null) const findFirst = vi.fn().mockResolvedValue(null)
const db = { const db = {
user: { user: {
findUnique, findFirst,
}, },
} }
await getUserCredentialsByEmail("Admin@Example.Test", db as never) await getUserCredentialsByEmail("Admin@Example.Test", db as never)
expect(findUnique).toHaveBeenCalledWith({ expect(findFirst).toHaveBeenCalledWith({
where: { where: expect.objectContaining({
emailNormalized: "admin@example.test", emailNormalized: "admin@example.test",
}, }),
select: expect.objectContaining({ select: expect.objectContaining({
passwordHash: true, passwordHash: true,
}), }),