import { afterAll, beforeAll, beforeEach, describe, expect, it } from "vitest" import type { PrismaClient } from "@/generated/prisma/client" import { createTestPerson, createTestUser } from "../helpers/factories" import { resetIntegrationTestDatabase, startIntegrationTestDatabase, stopIntegrationTestDatabase, } from "../helpers/test-db" let prisma: PrismaClient beforeAll(async () => { await startIntegrationTestDatabase() const prismaModule = await import("@/lib/prisma") prisma = prismaModule.prisma }) beforeEach(async () => { await resetIntegrationTestDatabase(prisma) }) afterAll(async () => { await prisma?.$disconnect() await stopIntegrationTestDatabase() }) describe("/admin/users -> /people redirect routes", () => { it("does not have a /admin/users list page (route is consolidated into /people)", async () => { const fs = await import("node:fs/promises") const path = await import("node:path") // /admin/users/page.tsx must still exist (as a redirect stub) — verify it's just a redirect. const adminUsersPage = path.join( process.cwd(), "src/app/(dashboard)/admin/users/page.tsx", ) const contents = await fs.readFile(adminUsersPage, "utf-8") expect(contents).toMatch(/redirect\s*\(\s*["']\/people["']\s*\)/) }) it("resolves a userId back to its linked personId", async () => { // Build a Person<->User link to verify the redirect can find the person by userId. const user = await createTestUser(prisma, { email: "linked@example.test", }) const person = await createTestPerson(prisma, { email: "linked@example.test", }) await prisma.person.update({ where: { id: person.id }, data: { userId: user.id }, }) const found = await prisma.person.findFirst({ where: { userId: user.id }, select: { id: true }, }) expect(found?.id).toBe(person.id) }) })