refactor: consolidate admin/users management under /people

This commit is contained in:
2026-06-17 09:32:26 +02:00
parent 4f370eee70
commit d6b42d78e7
31 changed files with 1928 additions and 855 deletions
@@ -5,8 +5,10 @@ import { es } from "@/i18n/dictionaries/es"
const mocks = vi.hoisted(() => ({
getI18n: vi.fn(),
findByIdWithUser: vi.fn(),
findById: vi.fn(),
redirect: vi.fn(),
personForm: vi.fn(),
}))
vi.mock("@/i18n/server", () => ({
@@ -15,6 +17,7 @@ vi.mock("@/i18n/server", () => ({
vi.mock("@/services/person.service", () => ({
PersonService: {
findByIdWithUser: mocks.findByIdWithUser,
findById: mocks.findById,
},
}))
@@ -29,6 +32,14 @@ vi.mock("next/navigation", () => ({
vi.mock("@/actions/person.actions", () => ({
createNewPerson: vi.fn(),
updatePerson: vi.fn(),
updatePersonUserAction: vi.fn(),
}))
vi.mock("@/app/(dashboard)/people/_components/edit.person.form", () => ({
default: (props: unknown) => {
mocks.personForm(props)
return null
},
}))
vi.mock("sonner", () => ({
@@ -44,18 +55,23 @@ describe("person pages", () => {
mocks.getI18n.mockResolvedValue({ dictionary: es, locale: "es" })
})
it("renders the edit person page with Person heading and no username", async () => {
it("renders the edit person page with Person heading and passes person to unified form", async () => {
const { default: PersonEditPage } = await import(
"@/app/(dashboard)/people/[personId]/edit/page"
)
mocks.findById.mockResolvedValue({
mocks.findByIdWithUser.mockResolvedValue({
id: "person-1",
firstName: "Ada",
lastName: "Lovelace",
email: "ada@example.test",
phone: "1234",
department: "ENGINEERING",
userId: null,
isActive: true,
createdAt: new Date("2024-01-01"),
updatedAt: new Date("2024-01-01"),
user: null,
})
const html = renderToStaticMarkup(
@@ -65,8 +81,15 @@ describe("person pages", () => {
)
expect(html).toContain("Editar persona")
expect(html).toContain("Actualizar persona")
expect(html).not.toContain("Usuario")
expect(mocks.personForm).toHaveBeenCalledWith(
expect.objectContaining({
person: expect.objectContaining({
id: "person-1",
firstName: "Ada",
lastName: "Lovelace",
}),
}),
)
})
it("renders a Person not-found message on edit page", async () => {
@@ -74,7 +97,7 @@ describe("person pages", () => {
"@/app/(dashboard)/people/[personId]/edit/page"
)
mocks.findById.mockResolvedValue(null)
mocks.findByIdWithUser.mockResolvedValue(null)
const html = renderToStaticMarkup(
await PersonEditPage({