refactor: consolidate admin/users management under /people
This commit is contained in:
@@ -7,6 +7,7 @@ import { en } from "@/i18n/dictionaries/en"
|
||||
const mocks = vi.hoisted(() => ({
|
||||
findAllPaginated: vi.fn(),
|
||||
findById: vi.fn(),
|
||||
findByIdWithUser: vi.fn(),
|
||||
findAllByPerson: vi.fn(),
|
||||
getI18n: vi.fn(),
|
||||
}))
|
||||
@@ -19,6 +20,7 @@ vi.mock("@/services/person.service", () => ({
|
||||
PersonService: {
|
||||
findAllPaginated: mocks.findAllPaginated,
|
||||
findById: mocks.findById,
|
||||
findByIdWithUser: mocks.findByIdWithUser,
|
||||
},
|
||||
}))
|
||||
|
||||
@@ -62,6 +64,11 @@ describe("person pages", () => {
|
||||
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,
|
||||
},
|
||||
],
|
||||
totalPages: 1,
|
||||
@@ -86,6 +93,72 @@ describe("person pages", () => {
|
||||
expect(html).toContain("/people/person-1/edit")
|
||||
})
|
||||
|
||||
it("renders role and status columns for people with linked users", async () => {
|
||||
const { default: PeoplePage } = await import(
|
||||
"@/app/(dashboard)/people/page"
|
||||
)
|
||||
|
||||
mocks.findAllPaginated.mockResolvedValue({
|
||||
data: [
|
||||
{
|
||||
id: "person-1",
|
||||
firstName: "Ada",
|
||||
lastName: "Lovelace",
|
||||
email: "ada@example.test",
|
||||
phone: "1234",
|
||||
department: "ENGINEERING",
|
||||
userId: "user-1",
|
||||
isActive: true,
|
||||
createdAt: new Date("2024-01-01"),
|
||||
updatedAt: new Date("2024-01-01"),
|
||||
user: {
|
||||
id: "user-1",
|
||||
name: "Ada Lovelace",
|
||||
email: "ada@example.test",
|
||||
role: "ADMIN",
|
||||
isActive: true,
|
||||
createdAt: new Date("2024-01-01"),
|
||||
updatedAt: new Date("2024-01-01"),
|
||||
password: "hashed",
|
||||
movements: [],
|
||||
assignments: [],
|
||||
person: null,
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "person-2",
|
||||
firstName: "Bob",
|
||||
lastName: "Jones",
|
||||
email: "bob@example.test",
|
||||
phone: null,
|
||||
department: "IT",
|
||||
userId: null,
|
||||
isActive: true,
|
||||
createdAt: new Date("2024-01-01"),
|
||||
updatedAt: new Date("2024-01-01"),
|
||||
user: null,
|
||||
},
|
||||
],
|
||||
totalPages: 1,
|
||||
})
|
||||
|
||||
const html = renderToStaticMarkup(
|
||||
await PeoplePage({ searchParams: Promise.resolve({}) }),
|
||||
)
|
||||
|
||||
// Column headers from inventory.people.list.columns
|
||||
expect(html).toContain("Role")
|
||||
expect(html).toContain("Status")
|
||||
|
||||
// Person with linked user: role label + active label
|
||||
expect(html).toContain("Admin")
|
||||
expect(html).toContain("Active")
|
||||
|
||||
// Person without user: no canonical enum leaks, just placeholder
|
||||
expect(html).not.toContain(">STAFF<")
|
||||
expect(html).not.toContain(">ADMIN<")
|
||||
})
|
||||
|
||||
it("renders the person list empty state from Person copy", async () => {
|
||||
const { default: PeoplePage } = await import(
|
||||
"@/app/(dashboard)/people/page"
|
||||
@@ -108,13 +181,18 @@ describe("person pages", () => {
|
||||
"@/app/(dashboard)/people/[personId]/page"
|
||||
)
|
||||
|
||||
mocks.findById.mockResolvedValue({
|
||||
mocks.findByIdWithUser.mockResolvedValue({
|
||||
id: "person-1",
|
||||
firstName: "Ada",
|
||||
lastName: "Lovelace",
|
||||
email: "ada@example.test",
|
||||
phone: "1234",
|
||||
department: "DRIVER",
|
||||
userId: null,
|
||||
isActive: true,
|
||||
createdAt: new Date("2024-01-01"),
|
||||
updatedAt: new Date("2024-01-01"),
|
||||
user: null,
|
||||
})
|
||||
mocks.findAllByPerson.mockResolvedValue([
|
||||
{
|
||||
@@ -144,12 +222,87 @@ describe("person pages", () => {
|
||||
expect(html).toContain("Laptop")
|
||||
})
|
||||
|
||||
it("renders person detail User role and status when person has linked User", async () => {
|
||||
const { default: PersonInfoPage } = await import(
|
||||
"@/app/(dashboard)/people/[personId]/page"
|
||||
)
|
||||
|
||||
mocks.findByIdWithUser.mockResolvedValue({
|
||||
id: "person-1",
|
||||
firstName: "Ada",
|
||||
lastName: "Lovelace",
|
||||
email: "ada@example.test",
|
||||
phone: "1234",
|
||||
department: "DRIVER",
|
||||
userId: "user-1",
|
||||
isActive: true,
|
||||
createdAt: new Date("2024-01-01"),
|
||||
updatedAt: new Date("2024-01-01"),
|
||||
user: {
|
||||
id: "user-1",
|
||||
name: "Ada Lovelace",
|
||||
email: "ada@example.test",
|
||||
role: "ADMIN",
|
||||
isActive: true,
|
||||
createdAt: new Date("2024-01-01"),
|
||||
updatedAt: new Date("2024-01-01"),
|
||||
password: "hashed",
|
||||
movements: [],
|
||||
assignments: [],
|
||||
person: null,
|
||||
},
|
||||
})
|
||||
mocks.findAllByPerson.mockResolvedValue([])
|
||||
|
||||
const html = renderToStaticMarkup(
|
||||
await PersonInfoPage({
|
||||
params: Promise.resolve({ personId: "person-1" }),
|
||||
}),
|
||||
)
|
||||
|
||||
expect(html).toContain("Role")
|
||||
expect(html).toContain("Status")
|
||||
expect(html).toContain("Admin")
|
||||
expect(html).toContain("Active")
|
||||
// Canonical enum value must not leak into display
|
||||
expect(html).not.toContain(">ADMIN<")
|
||||
})
|
||||
|
||||
it("renders 'No user account' placeholder for person without linked User", async () => {
|
||||
const { default: PersonInfoPage } = await import(
|
||||
"@/app/(dashboard)/people/[personId]/page"
|
||||
)
|
||||
|
||||
mocks.findByIdWithUser.mockResolvedValue({
|
||||
id: "person-1",
|
||||
firstName: "Ada",
|
||||
lastName: "Lovelace",
|
||||
email: "ada@example.test",
|
||||
phone: "1234",
|
||||
department: "DRIVER",
|
||||
userId: null,
|
||||
isActive: true,
|
||||
createdAt: new Date("2024-01-01"),
|
||||
updatedAt: new Date("2024-01-01"),
|
||||
user: null,
|
||||
})
|
||||
mocks.findAllByPerson.mockResolvedValue([])
|
||||
|
||||
const html = renderToStaticMarkup(
|
||||
await PersonInfoPage({
|
||||
params: Promise.resolve({ personId: "person-1" }),
|
||||
}),
|
||||
)
|
||||
|
||||
expect(html).toContain("No user account")
|
||||
})
|
||||
|
||||
it("renders person detail not-found from Person copy", async () => {
|
||||
const { default: PersonInfoPage } = await import(
|
||||
"@/app/(dashboard)/people/[personId]/page"
|
||||
)
|
||||
|
||||
mocks.findById.mockResolvedValue(null)
|
||||
mocks.findByIdWithUser.mockResolvedValue(null)
|
||||
mocks.findAllByPerson.mockResolvedValue([])
|
||||
|
||||
const html = renderToStaticMarkup(
|
||||
|
||||
Reference in New Issue
Block a user