refactor: complete i18n rename recipients to people, finalize tests
This commit is contained in:
@@ -36,7 +36,6 @@ export const en = {
|
|||||||
items: "Items",
|
items: "Items",
|
||||||
categories: "Categories",
|
categories: "Categories",
|
||||||
assets: "Assets",
|
assets: "Assets",
|
||||||
recipients: "Recipients",
|
|
||||||
people: "People",
|
people: "People",
|
||||||
movements: "Movements",
|
movements: "Movements",
|
||||||
assignments: "Assignments",
|
assignments: "Assignments",
|
||||||
@@ -51,7 +50,6 @@ export const en = {
|
|||||||
category: "Category",
|
category: "Category",
|
||||||
item: "Item",
|
item: "Item",
|
||||||
asset: "Asset",
|
asset: "Asset",
|
||||||
recipient: "Recipient",
|
|
||||||
person: "Person",
|
person: "Person",
|
||||||
assignment: "Assignment",
|
assignment: "Assignment",
|
||||||
},
|
},
|
||||||
@@ -392,86 +390,7 @@ export const en = {
|
|||||||
departmentRequired: "Department is required",
|
departmentRequired: "Department is required",
|
||||||
emailInvalid: "Email format is invalid",
|
emailInvalid: "Email format is invalid",
|
||||||
idRequired: "ID is required",
|
idRequired: "ID is required",
|
||||||
},
|
userIdInvalid: "User ID must be a valid UUID",
|
||||||
},
|
|
||||||
recipients: {
|
|
||||||
list: {
|
|
||||||
title: "Recipients",
|
|
||||||
addLabel: "Add Recipient",
|
|
||||||
empty: "No recipients found.",
|
|
||||||
columns: {
|
|
||||||
username: "Username",
|
|
||||||
name: "Name",
|
|
||||||
email: "Email",
|
|
||||||
phone: "Phone",
|
|
||||||
department: "Department",
|
|
||||||
actions: "Actions",
|
|
||||||
},
|
|
||||||
actions: {
|
|
||||||
view: "View recipient",
|
|
||||||
edit: "Edit recipient",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
detail: {
|
|
||||||
notFound: "Recipient not found",
|
|
||||||
labels: {
|
|
||||||
username: "Username",
|
|
||||||
email: "Email",
|
|
||||||
phone: "Phone",
|
|
||||||
department: "Department",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
new: {
|
|
||||||
title: "Add Recipient",
|
|
||||||
},
|
|
||||||
edit: {
|
|
||||||
title: "Edit Recipient",
|
|
||||||
notFound: "Recipient not found",
|
|
||||||
},
|
|
||||||
form: {
|
|
||||||
usernameLabel: "Username",
|
|
||||||
usernamePlaceholder: "Username",
|
|
||||||
firstNameLabel: "First Name",
|
|
||||||
firstNamePlaceholder: "First name",
|
|
||||||
lastNameLabel: "Last Name",
|
|
||||||
lastNamePlaceholder: "Last name",
|
|
||||||
departmentLabel: "Department",
|
|
||||||
departmentPlaceholder: "Select a department",
|
|
||||||
emailLabel: "Email",
|
|
||||||
emailPlaceholder: "Email",
|
|
||||||
phoneLabel: "Phone",
|
|
||||||
phonePlaceholder: "Phone",
|
|
||||||
createSubmit: "Create Recipient",
|
|
||||||
updateSubmit: "Update Recipient",
|
|
||||||
},
|
|
||||||
fallback: {
|
|
||||||
unknownDepartment: "Unknown department",
|
|
||||||
},
|
|
||||||
departments: {
|
|
||||||
IT: "IT",
|
|
||||||
ENGINEERING: "Engineering",
|
|
||||||
LOGISTICS: "Logistics",
|
|
||||||
TRAFFIC: "Traffic",
|
|
||||||
DRIVER: "Driver",
|
|
||||||
ADMINISTRATION: "Administration",
|
|
||||||
SALES: "Sales",
|
|
||||||
OTHER: "Other",
|
|
||||||
},
|
|
||||||
actions: {
|
|
||||||
createSuccess: "Recipient created successfully",
|
|
||||||
createFailure: "Failed to create recipient",
|
|
||||||
updateSuccess: "Recipient updated successfully",
|
|
||||||
updateFailure: "Failed to update recipient",
|
|
||||||
duplicateUsername: "Username already exists",
|
|
||||||
duplicateEmail: "Email already exists",
|
|
||||||
},
|
|
||||||
schema: {
|
|
||||||
usernameRequired: "Username is required",
|
|
||||||
firstNameRequired: "First name is required",
|
|
||||||
lastNameRequired: "Last name is required",
|
|
||||||
departmentRequired: "Department is required",
|
|
||||||
emailInvalid: "Email format is invalid",
|
|
||||||
idRequired: "ID is required",
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
movements: {
|
movements: {
|
||||||
@@ -608,10 +527,6 @@ export const en = {
|
|||||||
title: "Total Assets",
|
title: "Total Assets",
|
||||||
countLabel: "Total",
|
countLabel: "Total",
|
||||||
},
|
},
|
||||||
recipients: {
|
|
||||||
title: "Total Recipients",
|
|
||||||
countLabel: "Total",
|
|
||||||
},
|
|
||||||
people: {
|
people: {
|
||||||
title: "Total People",
|
title: "Total People",
|
||||||
countLabel: "Total",
|
countLabel: "Total",
|
||||||
|
|||||||
@@ -38,7 +38,6 @@ export const es = {
|
|||||||
items: "Artículos",
|
items: "Artículos",
|
||||||
categories: "Categorías",
|
categories: "Categorías",
|
||||||
assets: "Activos",
|
assets: "Activos",
|
||||||
recipients: "Destinatarios",
|
|
||||||
people: "Personas",
|
people: "Personas",
|
||||||
movements: "Movimientos",
|
movements: "Movimientos",
|
||||||
assignments: "Asignaciones",
|
assignments: "Asignaciones",
|
||||||
@@ -53,7 +52,6 @@ export const es = {
|
|||||||
category: "Categoría",
|
category: "Categoría",
|
||||||
item: "Artículo",
|
item: "Artículo",
|
||||||
asset: "Activo",
|
asset: "Activo",
|
||||||
recipient: "Destinatario",
|
|
||||||
person: "Persona",
|
person: "Persona",
|
||||||
assignment: "Asignación",
|
assignment: "Asignación",
|
||||||
},
|
},
|
||||||
@@ -397,86 +395,7 @@ export const es = {
|
|||||||
departmentRequired: "El departamento es obligatorio",
|
departmentRequired: "El departamento es obligatorio",
|
||||||
emailInvalid: "El correo electrónico no es válido",
|
emailInvalid: "El correo electrónico no es válido",
|
||||||
idRequired: "El ID es obligatorio",
|
idRequired: "El ID es obligatorio",
|
||||||
},
|
userIdInvalid: "El ID de usuario debe ser un UUID válido",
|
||||||
},
|
|
||||||
recipients: {
|
|
||||||
list: {
|
|
||||||
title: "Destinatarios",
|
|
||||||
addLabel: "Agregar destinatario",
|
|
||||||
empty: "No se encontraron destinatarios.",
|
|
||||||
columns: {
|
|
||||||
username: "Usuario",
|
|
||||||
name: "Nombre",
|
|
||||||
email: "Correo electrónico",
|
|
||||||
phone: "Teléfono",
|
|
||||||
department: "Departamento",
|
|
||||||
actions: "Acciones",
|
|
||||||
},
|
|
||||||
actions: {
|
|
||||||
view: "Ver destinatario",
|
|
||||||
edit: "Editar destinatario",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
detail: {
|
|
||||||
notFound: "Destinatario no encontrado",
|
|
||||||
labels: {
|
|
||||||
username: "Usuario",
|
|
||||||
email: "Correo electrónico",
|
|
||||||
phone: "Teléfono",
|
|
||||||
department: "Departamento",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
new: {
|
|
||||||
title: "Agregar destinatario",
|
|
||||||
},
|
|
||||||
edit: {
|
|
||||||
title: "Editar destinatario",
|
|
||||||
notFound: "Destinatario no encontrado",
|
|
||||||
},
|
|
||||||
form: {
|
|
||||||
usernameLabel: "Usuario",
|
|
||||||
usernamePlaceholder: "Usuario",
|
|
||||||
firstNameLabel: "Nombre",
|
|
||||||
firstNamePlaceholder: "Nombre",
|
|
||||||
lastNameLabel: "Apellido",
|
|
||||||
lastNamePlaceholder: "Apellido",
|
|
||||||
departmentLabel: "Departamento",
|
|
||||||
departmentPlaceholder: "Selecciona un departamento",
|
|
||||||
emailLabel: "Correo electrónico",
|
|
||||||
emailPlaceholder: "Correo electrónico",
|
|
||||||
phoneLabel: "Teléfono",
|
|
||||||
phonePlaceholder: "Teléfono",
|
|
||||||
createSubmit: "Crear destinatario",
|
|
||||||
updateSubmit: "Actualizar destinatario",
|
|
||||||
},
|
|
||||||
fallback: {
|
|
||||||
unknownDepartment: "Departamento desconocido",
|
|
||||||
},
|
|
||||||
departments: {
|
|
||||||
IT: "IT",
|
|
||||||
ENGINEERING: "Ingeniería",
|
|
||||||
LOGISTICS: "Logística",
|
|
||||||
TRAFFIC: "Tráfico",
|
|
||||||
DRIVER: "Chofer",
|
|
||||||
ADMINISTRATION: "Administración",
|
|
||||||
SALES: "Ventas",
|
|
||||||
OTHER: "Otro",
|
|
||||||
},
|
|
||||||
actions: {
|
|
||||||
createSuccess: "Destinatario creado correctamente",
|
|
||||||
createFailure: "Error al crear el destinatario",
|
|
||||||
updateSuccess: "Destinatario actualizado correctamente",
|
|
||||||
updateFailure: "Error al actualizar el destinatario",
|
|
||||||
duplicateUsername: "El nombre de usuario ya existe",
|
|
||||||
duplicateEmail: "El correo electrónico ya existe",
|
|
||||||
},
|
|
||||||
schema: {
|
|
||||||
usernameRequired: "El usuario es obligatorio",
|
|
||||||
firstNameRequired: "El nombre es obligatorio",
|
|
||||||
lastNameRequired: "El apellido es obligatorio",
|
|
||||||
departmentRequired: "El departamento es obligatorio",
|
|
||||||
emailInvalid: "El correo electrónico no es válido",
|
|
||||||
idRequired: "El ID es obligatorio",
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
movements: {
|
movements: {
|
||||||
@@ -613,10 +532,6 @@ export const es = {
|
|||||||
title: "Total de activos",
|
title: "Total de activos",
|
||||||
countLabel: "Total",
|
countLabel: "Total",
|
||||||
},
|
},
|
||||||
recipients: {
|
|
||||||
title: "Total de destinatarios",
|
|
||||||
countLabel: "Total",
|
|
||||||
},
|
|
||||||
people: {
|
people: {
|
||||||
title: "Total de personas",
|
title: "Total de personas",
|
||||||
countLabel: "Total",
|
countLabel: "Total",
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ const defaultPersonSchemaCopy: PersonSchemaCopy = {
|
|||||||
departmentRequired: "Department is required",
|
departmentRequired: "Department is required",
|
||||||
emailInvalid: "Email format is invalid",
|
emailInvalid: "Email format is invalid",
|
||||||
idRequired: "ID is required",
|
idRequired: "ID is required",
|
||||||
|
userIdInvalid: "User ID must be a valid UUID",
|
||||||
}
|
}
|
||||||
|
|
||||||
const personDepartments = [
|
const personDepartments = [
|
||||||
@@ -37,7 +38,11 @@ function buildPersonBaseSchema(copy: PersonSchemaCopy) {
|
|||||||
}),
|
}),
|
||||||
email: z.string().optional().nullable(),
|
email: z.string().optional().nullable(),
|
||||||
phone: z.string().optional().nullable(),
|
phone: z.string().optional().nullable(),
|
||||||
userId: z.string().uuid().optional().nullable(),
|
userId: z
|
||||||
|
.string()
|
||||||
|
.uuid({ error: copy.userIdInvalid })
|
||||||
|
.optional()
|
||||||
|
.nullable(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,112 @@
|
|||||||
|
import { beforeEach, describe, expect, it, vi } from "vitest"
|
||||||
|
|
||||||
|
import { en } from "@/i18n/dictionaries/en"
|
||||||
|
import { es } from "@/i18n/dictionaries/es"
|
||||||
|
|
||||||
|
const mocks = vi.hoisted(() => ({
|
||||||
|
revalidatePath: vi.fn(),
|
||||||
|
getI18n: vi.fn(),
|
||||||
|
createPersonUseCase: vi.fn(),
|
||||||
|
updatePersonUseCase: vi.fn(),
|
||||||
|
}))
|
||||||
|
|
||||||
|
vi.mock("next/cache", () => ({
|
||||||
|
revalidatePath: mocks.revalidatePath,
|
||||||
|
}))
|
||||||
|
|
||||||
|
vi.mock("@/i18n/server", () => ({
|
||||||
|
getI18n: mocks.getI18n,
|
||||||
|
}))
|
||||||
|
|
||||||
|
vi.mock("@/use-cases/person.use-cases", () => ({
|
||||||
|
createPersonUseCase: mocks.createPersonUseCase,
|
||||||
|
updatePersonUseCase: mocks.updatePersonUseCase,
|
||||||
|
}))
|
||||||
|
|
||||||
|
import { createNewPerson, updatePerson } from "@/actions/person.actions"
|
||||||
|
|
||||||
|
describe("person actions localization", () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
vi.clearAllMocks()
|
||||||
|
mocks.getI18n.mockResolvedValue({ dictionary: es, locale: "es" })
|
||||||
|
})
|
||||||
|
|
||||||
|
it("returns localized schema validation errors for invalid create input (no username)", async () => {
|
||||||
|
const result = await createNewPerson({
|
||||||
|
firstName: "",
|
||||||
|
lastName: "",
|
||||||
|
department: "",
|
||||||
|
email: "not-an-email",
|
||||||
|
} as unknown as Parameters<typeof createNewPerson>[0])
|
||||||
|
|
||||||
|
expect(mocks.getI18n).toHaveBeenCalledOnce()
|
||||||
|
expect(mocks.createPersonUseCase).not.toHaveBeenCalled()
|
||||||
|
expect(result).toEqual({
|
||||||
|
success: false,
|
||||||
|
errors: {
|
||||||
|
firstName: [es.inventory.people.schema.firstNameRequired],
|
||||||
|
lastName: [es.inventory.people.schema.lastNameRequired],
|
||||||
|
department: [es.inventory.people.schema.departmentRequired],
|
||||||
|
},
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it("localizes mapped duplicate field errors for create failures (no duplicateUsername)", async () => {
|
||||||
|
mocks.createPersonUseCase.mockResolvedValue({
|
||||||
|
success: false,
|
||||||
|
errors: {
|
||||||
|
email: ["Email already exists"],
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const result = await createNewPerson({
|
||||||
|
firstName: "Ada",
|
||||||
|
lastName: "Lovelace",
|
||||||
|
department: "ENGINEERING",
|
||||||
|
email: "ada@example.test",
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(result).toEqual({
|
||||||
|
success: false,
|
||||||
|
errors: {
|
||||||
|
email: [es.inventory.people.actions.duplicateEmail],
|
||||||
|
},
|
||||||
|
message: es.inventory.people.actions.createFailure,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it("returns a localized update success message and revalidates /people", async () => {
|
||||||
|
mocks.getI18n.mockResolvedValue({ dictionary: en, locale: "en" })
|
||||||
|
mocks.updatePersonUseCase.mockResolvedValue({ success: true })
|
||||||
|
|
||||||
|
const result = await updatePerson({
|
||||||
|
id: "person-1",
|
||||||
|
firstName: "Ada",
|
||||||
|
lastName: "Lovelace",
|
||||||
|
department: "ENGINEERING",
|
||||||
|
email: "ada@example.test",
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(result).toEqual({
|
||||||
|
success: true,
|
||||||
|
message: en.inventory.people.actions.updateSuccess,
|
||||||
|
})
|
||||||
|
expect(mocks.revalidatePath).toHaveBeenCalledWith("/people")
|
||||||
|
})
|
||||||
|
|
||||||
|
it("returns localized validation error for invalid userId UUID on create", async () => {
|
||||||
|
const result = await createNewPerson({
|
||||||
|
firstName: "Ada",
|
||||||
|
lastName: "Lovelace",
|
||||||
|
department: "ENGINEERING",
|
||||||
|
userId: "not-a-uuid",
|
||||||
|
} as unknown as Parameters<typeof createNewPerson>[0])
|
||||||
|
|
||||||
|
expect(result).toEqual({
|
||||||
|
success: false,
|
||||||
|
errors: {
|
||||||
|
userId: [es.inventory.people.schema.userIdInvalid],
|
||||||
|
},
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
import { describe, expect, it } from "vitest"
|
||||||
|
|
||||||
|
import { localizePersonFieldErrors } from "@/actions/person.messages"
|
||||||
|
|
||||||
|
const actionCopy = {
|
||||||
|
createSuccess: "Persona creada correctamente",
|
||||||
|
createFailure: "Error al crear la persona",
|
||||||
|
updateSuccess: "Persona actualizada correctamente",
|
||||||
|
updateFailure: "Error al actualizar la persona",
|
||||||
|
duplicateEmail: "El correo electrónico ya existe",
|
||||||
|
}
|
||||||
|
|
||||||
|
describe("person action message localization", () => {
|
||||||
|
it("localizes known person field errors (email only, no username)", () => {
|
||||||
|
expect(
|
||||||
|
localizePersonFieldErrors(
|
||||||
|
{
|
||||||
|
email: ["Email already exists"],
|
||||||
|
},
|
||||||
|
actionCopy,
|
||||||
|
),
|
||||||
|
).toEqual({
|
||||||
|
email: [actionCopy.duplicateEmail],
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it("keeps unknown messages unchanged", () => {
|
||||||
|
expect(
|
||||||
|
localizePersonFieldErrors(
|
||||||
|
{ firstName: ["Unexpected person issue"] },
|
||||||
|
actionCopy,
|
||||||
|
),
|
||||||
|
).toEqual({ firstName: ["Unexpected person issue"] })
|
||||||
|
})
|
||||||
|
|
||||||
|
it("returns undefined when errors are undefined", () => {
|
||||||
|
expect(localizePersonFieldErrors(undefined, actionCopy)).toBeUndefined()
|
||||||
|
})
|
||||||
|
|
||||||
|
it("returns undefined when errors are empty", () => {
|
||||||
|
expect(localizePersonFieldErrors({}, actionCopy)).toEqual({})
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -1,103 +0,0 @@
|
|||||||
import { beforeEach, describe, expect, it, vi } from "vitest"
|
|
||||||
|
|
||||||
import { es } from "@/i18n/dictionaries/es"
|
|
||||||
|
|
||||||
const mocks = vi.hoisted(() => ({
|
|
||||||
revalidatePath: vi.fn(),
|
|
||||||
getI18n: vi.fn(),
|
|
||||||
createRecipientUseCase: vi.fn(),
|
|
||||||
updateRecipientUseCase: vi.fn(),
|
|
||||||
}))
|
|
||||||
|
|
||||||
vi.mock("next/cache", () => ({
|
|
||||||
revalidatePath: mocks.revalidatePath,
|
|
||||||
}))
|
|
||||||
|
|
||||||
vi.mock("@/i18n/server", () => ({
|
|
||||||
getI18n: mocks.getI18n,
|
|
||||||
}))
|
|
||||||
|
|
||||||
vi.mock("@/use-cases/recipient.use-cases", () => ({
|
|
||||||
createRecipientUseCase: mocks.createRecipientUseCase,
|
|
||||||
updateRecipientUseCase: mocks.updateRecipientUseCase,
|
|
||||||
}))
|
|
||||||
|
|
||||||
import {
|
|
||||||
createNewRecipient,
|
|
||||||
updateRecipient,
|
|
||||||
} from "@/actions/recipient.actions"
|
|
||||||
|
|
||||||
describe("recipient actions localization", () => {
|
|
||||||
beforeEach(() => {
|
|
||||||
vi.clearAllMocks()
|
|
||||||
mocks.getI18n.mockResolvedValue({ dictionary: es, locale: "es" })
|
|
||||||
})
|
|
||||||
|
|
||||||
it("returns localized schema validation errors for invalid create input", async () => {
|
|
||||||
const result = await createNewRecipient({
|
|
||||||
username: "",
|
|
||||||
firstName: "",
|
|
||||||
lastName: "",
|
|
||||||
department: "",
|
|
||||||
email: "not-an-email",
|
|
||||||
} as unknown as Parameters<typeof createNewRecipient>[0])
|
|
||||||
|
|
||||||
expect(mocks.getI18n).toHaveBeenCalledOnce()
|
|
||||||
expect(mocks.createRecipientUseCase).not.toHaveBeenCalled()
|
|
||||||
expect(result).toEqual({
|
|
||||||
success: false,
|
|
||||||
errors: {
|
|
||||||
username: [es.inventory.recipients.schema.usernameRequired],
|
|
||||||
firstName: [es.inventory.recipients.schema.firstNameRequired],
|
|
||||||
lastName: [es.inventory.recipients.schema.lastNameRequired],
|
|
||||||
department: [es.inventory.recipients.schema.departmentRequired],
|
|
||||||
},
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
it("localizes mapped duplicate field errors for create failures", async () => {
|
|
||||||
mocks.createRecipientUseCase.mockResolvedValue({
|
|
||||||
success: false,
|
|
||||||
errors: {
|
|
||||||
username: ["Username already exists"],
|
|
||||||
email: ["Email already exists"],
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
const result = await createNewRecipient({
|
|
||||||
username: "ada",
|
|
||||||
firstName: "Ada",
|
|
||||||
lastName: "Lovelace",
|
|
||||||
department: "ENGINEERING",
|
|
||||||
email: "ada@example.test",
|
|
||||||
})
|
|
||||||
|
|
||||||
expect(result).toEqual({
|
|
||||||
success: false,
|
|
||||||
errors: {
|
|
||||||
username: [es.inventory.recipients.actions.duplicateUsername],
|
|
||||||
email: [es.inventory.recipients.actions.duplicateEmail],
|
|
||||||
},
|
|
||||||
message: es.inventory.recipients.actions.createFailure,
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
it("returns a localized update success message and revalidates recipients", async () => {
|
|
||||||
mocks.updateRecipientUseCase.mockResolvedValue({ success: true })
|
|
||||||
|
|
||||||
const result = await updateRecipient({
|
|
||||||
id: "recipient-1",
|
|
||||||
username: "ada",
|
|
||||||
firstName: "Ada",
|
|
||||||
lastName: "Lovelace",
|
|
||||||
department: "ENGINEERING",
|
|
||||||
email: "ada@example.test",
|
|
||||||
})
|
|
||||||
|
|
||||||
expect(result).toEqual({
|
|
||||||
success: true,
|
|
||||||
message: es.inventory.recipients.actions.updateSuccess,
|
|
||||||
})
|
|
||||||
expect(mocks.revalidatePath).toHaveBeenCalledWith("/recipients")
|
|
||||||
})
|
|
||||||
})
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
import { describe, expect, it } from "vitest"
|
|
||||||
|
|
||||||
import { localizeRecipientFieldErrors } from "@/actions/recipient.messages"
|
|
||||||
|
|
||||||
const actionCopy = {
|
|
||||||
createSuccess: "Destinatario creado correctamente",
|
|
||||||
createFailure: "Error al crear el destinatario",
|
|
||||||
updateSuccess: "Destinatario actualizado correctamente",
|
|
||||||
updateFailure: "Error al actualizar el destinatario",
|
|
||||||
duplicateUsername: "El nombre de usuario ya existe",
|
|
||||||
duplicateEmail: "El correo electrónico ya existe",
|
|
||||||
}
|
|
||||||
|
|
||||||
describe("recipient action message localization", () => {
|
|
||||||
it("localizes known recipient field errors", () => {
|
|
||||||
expect(
|
|
||||||
localizeRecipientFieldErrors(
|
|
||||||
{
|
|
||||||
username: ["Username already exists"],
|
|
||||||
email: ["Email already exists"],
|
|
||||||
},
|
|
||||||
actionCopy,
|
|
||||||
),
|
|
||||||
).toEqual({
|
|
||||||
username: [actionCopy.duplicateUsername],
|
|
||||||
email: [actionCopy.duplicateEmail],
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
it("keeps unknown messages unchanged", () => {
|
|
||||||
expect(
|
|
||||||
localizeRecipientFieldErrors(
|
|
||||||
{ username: ["Unexpected recipient issue"] },
|
|
||||||
actionCopy,
|
|
||||||
),
|
|
||||||
).toEqual({ username: ["Unexpected recipient issue"] })
|
|
||||||
})
|
|
||||||
})
|
|
||||||
@@ -1,125 +0,0 @@
|
|||||||
import { renderToStaticMarkup } from "react-dom/server"
|
|
||||||
import { beforeEach, describe, expect, it, vi } from "vitest"
|
|
||||||
|
|
||||||
import { en } from "@/i18n/dictionaries/en"
|
|
||||||
import { es } from "@/i18n/dictionaries/es"
|
|
||||||
|
|
||||||
const mocks = vi.hoisted(() => ({
|
|
||||||
getI18n: vi.fn(),
|
|
||||||
findById: vi.fn(),
|
|
||||||
createNewRecipient: vi.fn(),
|
|
||||||
updateRecipient: vi.fn(),
|
|
||||||
push: vi.fn(),
|
|
||||||
toastError: vi.fn(),
|
|
||||||
toastSuccess: vi.fn(),
|
|
||||||
}))
|
|
||||||
|
|
||||||
vi.mock("@/i18n/server", () => ({
|
|
||||||
getI18n: mocks.getI18n,
|
|
||||||
}))
|
|
||||||
|
|
||||||
vi.mock("@/services/recipient.service", () => ({
|
|
||||||
RecipientService: {
|
|
||||||
findById: mocks.findById,
|
|
||||||
},
|
|
||||||
}))
|
|
||||||
|
|
||||||
vi.mock("@/actions/recipient.actions", () => ({
|
|
||||||
createNewRecipient: mocks.createNewRecipient,
|
|
||||||
updateRecipient: mocks.updateRecipient,
|
|
||||||
}))
|
|
||||||
|
|
||||||
vi.mock("next/navigation", () => ({
|
|
||||||
useRouter: () => ({
|
|
||||||
push: mocks.push,
|
|
||||||
}),
|
|
||||||
}))
|
|
||||||
|
|
||||||
vi.mock("sonner", () => ({
|
|
||||||
toast: {
|
|
||||||
error: mocks.toastError,
|
|
||||||
success: mocks.toastSuccess,
|
|
||||||
},
|
|
||||||
}))
|
|
||||||
|
|
||||||
describe("recipient form pages localization", () => {
|
|
||||||
beforeEach(() => {
|
|
||||||
vi.clearAllMocks()
|
|
||||||
mocks.getI18n.mockResolvedValue({ dictionary: es, locale: "es" })
|
|
||||||
})
|
|
||||||
|
|
||||||
it("renders the new recipient page with localized form copy and canonical department option values", async () => {
|
|
||||||
const { default: NewRecipientPage } = await import(
|
|
||||||
"@/app/(dashboard)/recipients/new/page"
|
|
||||||
)
|
|
||||||
|
|
||||||
const html = renderToStaticMarkup(await NewRecipientPage())
|
|
||||||
|
|
||||||
expect(html).toContain("Agregar destinatario")
|
|
||||||
expect(html).toContain("Usuario")
|
|
||||||
expect(html).toContain('placeholder="Usuario"')
|
|
||||||
expect(html).toContain("Nombre")
|
|
||||||
expect(html).toContain("Apellido")
|
|
||||||
expect(html).toContain("Selecciona un departamento")
|
|
||||||
expect(html).toContain('option value="ENGINEERING"')
|
|
||||||
expect(html).toContain(">Ingeniería</option>")
|
|
||||||
expect(html).toContain("Correo electrónico")
|
|
||||||
expect(html).toContain("Teléfono")
|
|
||||||
expect(html).toContain("Crear destinatario")
|
|
||||||
})
|
|
||||||
|
|
||||||
it("renders the edit recipient page with localized heading and submit text", async () => {
|
|
||||||
const { default: RecipientEditPage } = await import(
|
|
||||||
"@/app/(dashboard)/recipients/[recipientId]/edit/page"
|
|
||||||
)
|
|
||||||
|
|
||||||
mocks.findById.mockResolvedValue({
|
|
||||||
id: "recipient-1",
|
|
||||||
username: "ada",
|
|
||||||
firstName: "Ada",
|
|
||||||
lastName: "Lovelace",
|
|
||||||
email: "ada@example.test",
|
|
||||||
phone: "1234",
|
|
||||||
department: "ENGINEERING",
|
|
||||||
})
|
|
||||||
|
|
||||||
const html = renderToStaticMarkup(
|
|
||||||
await RecipientEditPage({
|
|
||||||
params: Promise.resolve({ recipientId: "recipient-1" }),
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(html).toContain("Editar destinatario")
|
|
||||||
expect(html).toContain("Actualizar destinatario")
|
|
||||||
expect(html).toContain('placeholder="Correo electrónico"')
|
|
||||||
expect(html).toContain(">Ingeniería</option>")
|
|
||||||
})
|
|
||||||
|
|
||||||
it("renders a localized edit-page not-found message", async () => {
|
|
||||||
const { default: RecipientEditPage } = await import(
|
|
||||||
"@/app/(dashboard)/recipients/[recipientId]/edit/page"
|
|
||||||
)
|
|
||||||
|
|
||||||
mocks.findById.mockResolvedValue(null)
|
|
||||||
|
|
||||||
const html = renderToStaticMarkup(
|
|
||||||
await RecipientEditPage({
|
|
||||||
params: Promise.resolve({ recipientId: "missing-recipient" }),
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(html).toContain("Destinatario no encontrado")
|
|
||||||
})
|
|
||||||
|
|
||||||
it("wires English recipient form submit copy through the new page", async () => {
|
|
||||||
const { default: NewRecipientPage } = await import(
|
|
||||||
"@/app/(dashboard)/recipients/new/page"
|
|
||||||
)
|
|
||||||
|
|
||||||
mocks.getI18n.mockResolvedValueOnce({ dictionary: en, locale: "en" })
|
|
||||||
|
|
||||||
const html = renderToStaticMarkup(await NewRecipientPage())
|
|
||||||
|
|
||||||
expect(html).toContain("Create Recipient")
|
|
||||||
})
|
|
||||||
})
|
|
||||||
@@ -1,82 +0,0 @@
|
|||||||
import { createElement } from "react"
|
|
||||||
import { renderToStaticMarkup } from "react-dom/server"
|
|
||||||
import { beforeEach, describe, expect, it, vi } from "vitest"
|
|
||||||
|
|
||||||
import { en } from "@/i18n/dictionaries/en"
|
|
||||||
import { es } from "@/i18n/dictionaries/es"
|
|
||||||
|
|
||||||
const mocks = vi.hoisted(() => ({
|
|
||||||
getI18n: vi.fn(),
|
|
||||||
findById: vi.fn(),
|
|
||||||
recipientForm: vi.fn(),
|
|
||||||
}))
|
|
||||||
|
|
||||||
vi.mock("@/i18n/server", () => ({
|
|
||||||
getI18n: mocks.getI18n,
|
|
||||||
}))
|
|
||||||
|
|
||||||
vi.mock("@/services/recipient.service", () => ({
|
|
||||||
RecipientService: {
|
|
||||||
findById: mocks.findById,
|
|
||||||
},
|
|
||||||
}))
|
|
||||||
|
|
||||||
vi.mock("@/app/(dashboard)/recipients/_components/recipient.form", () => ({
|
|
||||||
default: (props: unknown) => {
|
|
||||||
mocks.recipientForm(props)
|
|
||||||
return createElement("div", null, "Recipient form")
|
|
||||||
},
|
|
||||||
}))
|
|
||||||
|
|
||||||
describe("recipient form schema wiring", () => {
|
|
||||||
beforeEach(() => {
|
|
||||||
vi.clearAllMocks()
|
|
||||||
})
|
|
||||||
|
|
||||||
it("passes server-resolved schema copy into the new recipient form boundary", async () => {
|
|
||||||
mocks.getI18n.mockResolvedValue({ dictionary: es, locale: "es" })
|
|
||||||
|
|
||||||
const { default: NewRecipientPage } = await import(
|
|
||||||
"@/app/(dashboard)/recipients/new/page"
|
|
||||||
)
|
|
||||||
|
|
||||||
renderToStaticMarkup(await NewRecipientPage())
|
|
||||||
|
|
||||||
expect(mocks.recipientForm).toHaveBeenCalledWith(
|
|
||||||
expect.objectContaining({
|
|
||||||
mode: "create",
|
|
||||||
schemaCopy: es.inventory.recipients.schema,
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
it("passes server-resolved schema copy into the edit recipient form boundary", async () => {
|
|
||||||
mocks.getI18n.mockResolvedValue({ dictionary: en, locale: "en" })
|
|
||||||
mocks.findById.mockResolvedValue({
|
|
||||||
id: "recipient-1",
|
|
||||||
username: "ada",
|
|
||||||
firstName: "Ada",
|
|
||||||
lastName: "Lovelace",
|
|
||||||
department: "ENGINEERING",
|
|
||||||
email: "ada@example.test",
|
|
||||||
phone: "1234",
|
|
||||||
})
|
|
||||||
|
|
||||||
const { default: RecipientEditPage } = await import(
|
|
||||||
"@/app/(dashboard)/recipients/[recipientId]/edit/page"
|
|
||||||
)
|
|
||||||
|
|
||||||
renderToStaticMarkup(
|
|
||||||
await RecipientEditPage({
|
|
||||||
params: Promise.resolve({ recipientId: "recipient-1" }),
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(mocks.recipientForm).toHaveBeenCalledWith(
|
|
||||||
expect.objectContaining({
|
|
||||||
mode: "edit",
|
|
||||||
schemaCopy: en.inventory.recipients.schema,
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
@@ -1,165 +0,0 @@
|
|||||||
import { createElement } from "react"
|
|
||||||
import { renderToStaticMarkup } from "react-dom/server"
|
|
||||||
import { beforeEach, describe, expect, it, vi } from "vitest"
|
|
||||||
|
|
||||||
import { es } from "@/i18n/dictionaries/es"
|
|
||||||
|
|
||||||
const mocks = vi.hoisted(() => ({
|
|
||||||
findAllPaginated: vi.fn(),
|
|
||||||
findById: vi.fn(),
|
|
||||||
findAllByRecipient: vi.fn(),
|
|
||||||
getI18n: vi.fn(),
|
|
||||||
}))
|
|
||||||
|
|
||||||
vi.mock("@/i18n/server", () => ({
|
|
||||||
getI18n: mocks.getI18n,
|
|
||||||
}))
|
|
||||||
|
|
||||||
vi.mock("@/services/recipient.service", () => ({
|
|
||||||
RecipientService: {
|
|
||||||
findAllPaginated: mocks.findAllPaginated,
|
|
||||||
findById: mocks.findById,
|
|
||||||
},
|
|
||||||
}))
|
|
||||||
|
|
||||||
vi.mock("@/services/assignment.service", () => ({
|
|
||||||
AssignmentService: {
|
|
||||||
findAllByRecipient: mocks.findAllByRecipient,
|
|
||||||
},
|
|
||||||
}))
|
|
||||||
|
|
||||||
vi.mock("@/components/common/pageheader", () => ({
|
|
||||||
default: ({ title, addLabel }: { title: string; addLabel?: string }) =>
|
|
||||||
createElement(
|
|
||||||
"header",
|
|
||||||
null,
|
|
||||||
[title, addLabel].filter(Boolean).join(" | "),
|
|
||||||
),
|
|
||||||
}))
|
|
||||||
|
|
||||||
vi.mock("@/components/common/pagination", () => ({
|
|
||||||
default: ({ totalPages }: { totalPages: number }) =>
|
|
||||||
createElement("nav", { "aria-label": "Pagination" }, totalPages),
|
|
||||||
}))
|
|
||||||
|
|
||||||
describe("recipient pages localization", () => {
|
|
||||||
beforeEach(() => {
|
|
||||||
vi.clearAllMocks()
|
|
||||||
mocks.getI18n.mockResolvedValue({ dictionary: es, locale: "es" })
|
|
||||||
})
|
|
||||||
|
|
||||||
it("renders the recipient list in Spanish while keeping stored department values display-only", async () => {
|
|
||||||
const { default: RecipientsPage } = await import(
|
|
||||||
"@/app/(dashboard)/recipients/page"
|
|
||||||
)
|
|
||||||
|
|
||||||
mocks.findAllPaginated.mockResolvedValue({
|
|
||||||
data: [
|
|
||||||
{
|
|
||||||
id: "recipient-1",
|
|
||||||
username: "ada",
|
|
||||||
firstName: "Ada",
|
|
||||||
lastName: "Lovelace",
|
|
||||||
email: "ada@example.test",
|
|
||||||
phone: "1234",
|
|
||||||
department: "ENGINEERING",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
totalPages: 1,
|
|
||||||
})
|
|
||||||
|
|
||||||
const html = renderToStaticMarkup(
|
|
||||||
await RecipientsPage({ searchParams: Promise.resolve({}) }),
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(html).toContain("Destinatarios")
|
|
||||||
expect(html).toContain("Agregar destinatario")
|
|
||||||
expect(html).toContain("Usuario")
|
|
||||||
expect(html).toContain("Nombre")
|
|
||||||
expect(html).toContain("Correo electrónico")
|
|
||||||
expect(html).toContain("Teléfono")
|
|
||||||
expect(html).toContain("Departamento")
|
|
||||||
expect(html).toContain("Acciones")
|
|
||||||
expect(html).toContain("Ada Lovelace")
|
|
||||||
expect(html).toContain("Ingeniería")
|
|
||||||
expect(html).toContain('aria-label="Ver destinatario"')
|
|
||||||
expect(html).toContain('aria-label="Editar destinatario"')
|
|
||||||
expect(html).not.toContain(">ENGINEERING<")
|
|
||||||
})
|
|
||||||
|
|
||||||
it("renders the localized recipient empty state when no recipients exist", async () => {
|
|
||||||
const { default: RecipientsPage } = await import(
|
|
||||||
"@/app/(dashboard)/recipients/page"
|
|
||||||
)
|
|
||||||
|
|
||||||
mocks.findAllPaginated.mockResolvedValue({
|
|
||||||
data: [],
|
|
||||||
totalPages: 0,
|
|
||||||
})
|
|
||||||
|
|
||||||
const html = renderToStaticMarkup(
|
|
||||||
await RecipientsPage({ searchParams: Promise.resolve({}) }),
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(html).toContain("No se encontraron destinatarios.")
|
|
||||||
})
|
|
||||||
|
|
||||||
it("renders localized recipient-owned detail labels and localizes the embedded assignments title only", async () => {
|
|
||||||
const { default: RecipientInfoPage } = await import(
|
|
||||||
"@/app/(dashboard)/recipients/[recipientId]/page"
|
|
||||||
)
|
|
||||||
|
|
||||||
mocks.findById.mockResolvedValue({
|
|
||||||
id: "recipient-1",
|
|
||||||
username: "ada",
|
|
||||||
firstName: "Ada",
|
|
||||||
lastName: "Lovelace",
|
|
||||||
email: "ada@example.test",
|
|
||||||
phone: "1234",
|
|
||||||
department: "DRIVER",
|
|
||||||
})
|
|
||||||
mocks.findAllByRecipient.mockResolvedValue([
|
|
||||||
{
|
|
||||||
id: "assignment-1",
|
|
||||||
item: { name: "Laptop" },
|
|
||||||
asset: { serialNumber: "SN-001" },
|
|
||||||
quantity: 1,
|
|
||||||
},
|
|
||||||
])
|
|
||||||
|
|
||||||
const html = renderToStaticMarkup(
|
|
||||||
await RecipientInfoPage({
|
|
||||||
params: Promise.resolve({ recipientId: "recipient-1" }),
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(html).toContain("Usuario")
|
|
||||||
expect(html).toContain("Correo electrónico")
|
|
||||||
expect(html).toContain("Teléfono")
|
|
||||||
expect(html).toContain("Departamento")
|
|
||||||
expect(html).toContain("Chofer")
|
|
||||||
expect(html).toContain("ada")
|
|
||||||
expect(html).toContain("ada@example.test")
|
|
||||||
expect(html).toContain("Asignaciones")
|
|
||||||
expect(html).toContain("Laptop")
|
|
||||||
expect(html).not.toContain(">DRIVER<")
|
|
||||||
expect(html).not.toContain("Assignments")
|
|
||||||
})
|
|
||||||
|
|
||||||
it("renders a localized recipient detail not-found message", async () => {
|
|
||||||
const { default: RecipientInfoPage } = await import(
|
|
||||||
"@/app/(dashboard)/recipients/[recipientId]/page"
|
|
||||||
)
|
|
||||||
|
|
||||||
mocks.findById.mockResolvedValue(null)
|
|
||||||
mocks.findAllByRecipient.mockResolvedValue([])
|
|
||||||
|
|
||||||
const html = renderToStaticMarkup(
|
|
||||||
await RecipientInfoPage({
|
|
||||||
params: Promise.resolve({ recipientId: "missing-recipient" }),
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(html).toContain("Destinatario no encontrado")
|
|
||||||
})
|
|
||||||
})
|
|
||||||
@@ -52,7 +52,6 @@ describe("i18n dictionaries", () => {
|
|||||||
items: "Items",
|
items: "Items",
|
||||||
categories: "Categories",
|
categories: "Categories",
|
||||||
assets: "Assets",
|
assets: "Assets",
|
||||||
recipients: "Recipients",
|
|
||||||
people: "People",
|
people: "People",
|
||||||
movements: "Movements",
|
movements: "Movements",
|
||||||
assignments: "Assignments",
|
assignments: "Assignments",
|
||||||
@@ -67,7 +66,6 @@ describe("i18n dictionaries", () => {
|
|||||||
category: "Category",
|
category: "Category",
|
||||||
item: "Item",
|
item: "Item",
|
||||||
asset: "Asset",
|
asset: "Asset",
|
||||||
recipient: "Recipient",
|
|
||||||
person: "Person",
|
person: "Person",
|
||||||
assignment: "Assignment",
|
assignment: "Assignment",
|
||||||
},
|
},
|
||||||
@@ -89,7 +87,6 @@ describe("i18n dictionaries", () => {
|
|||||||
items: "Artículos",
|
items: "Artículos",
|
||||||
categories: "Categorías",
|
categories: "Categorías",
|
||||||
assets: "Activos",
|
assets: "Activos",
|
||||||
recipients: "Destinatarios",
|
|
||||||
people: "Personas",
|
people: "Personas",
|
||||||
movements: "Movimientos",
|
movements: "Movimientos",
|
||||||
assignments: "Asignaciones",
|
assignments: "Asignaciones",
|
||||||
@@ -104,7 +101,6 @@ describe("i18n dictionaries", () => {
|
|||||||
category: "Categoría",
|
category: "Categoría",
|
||||||
item: "Artículo",
|
item: "Artículo",
|
||||||
asset: "Activo",
|
asset: "Activo",
|
||||||
recipient: "Destinatario",
|
|
||||||
person: "Persona",
|
person: "Persona",
|
||||||
assignment: "Asignación",
|
assignment: "Asignación",
|
||||||
},
|
},
|
||||||
@@ -694,14 +690,13 @@ describe("i18n dictionaries", () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it("provides localized recipient UI copy for English and Spanish", () => {
|
it("provides localized people UI copy for English and Spanish", () => {
|
||||||
expect(getDictionary("en").inventory.recipients).toEqual({
|
expect(getDictionary("en").inventory.people).toEqual({
|
||||||
list: {
|
list: {
|
||||||
title: "Recipients",
|
title: "People",
|
||||||
addLabel: "Add Recipient",
|
addLabel: "Add Person",
|
||||||
empty: "No recipients found.",
|
empty: "No people found.",
|
||||||
columns: {
|
columns: {
|
||||||
username: "Username",
|
|
||||||
name: "Name",
|
name: "Name",
|
||||||
email: "Email",
|
email: "Email",
|
||||||
phone: "Phone",
|
phone: "Phone",
|
||||||
@@ -709,29 +704,26 @@ describe("i18n dictionaries", () => {
|
|||||||
actions: "Actions",
|
actions: "Actions",
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
view: "View recipient",
|
view: "View person",
|
||||||
edit: "Edit recipient",
|
edit: "Edit person",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
detail: {
|
detail: {
|
||||||
notFound: "Recipient not found",
|
notFound: "Person not found",
|
||||||
labels: {
|
labels: {
|
||||||
username: "Username",
|
|
||||||
email: "Email",
|
email: "Email",
|
||||||
phone: "Phone",
|
phone: "Phone",
|
||||||
department: "Department",
|
department: "Department",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
new: {
|
new: {
|
||||||
title: "Add Recipient",
|
title: "Add Person",
|
||||||
},
|
},
|
||||||
edit: {
|
edit: {
|
||||||
title: "Edit Recipient",
|
title: "Edit Person",
|
||||||
notFound: "Recipient not found",
|
notFound: "Person not found",
|
||||||
},
|
},
|
||||||
form: {
|
form: {
|
||||||
usernameLabel: "Username",
|
|
||||||
usernamePlaceholder: "Username",
|
|
||||||
firstNameLabel: "First Name",
|
firstNameLabel: "First Name",
|
||||||
firstNamePlaceholder: "First name",
|
firstNamePlaceholder: "First name",
|
||||||
lastNameLabel: "Last Name",
|
lastNameLabel: "Last Name",
|
||||||
@@ -742,8 +734,8 @@ describe("i18n dictionaries", () => {
|
|||||||
emailPlaceholder: "Email",
|
emailPlaceholder: "Email",
|
||||||
phoneLabel: "Phone",
|
phoneLabel: "Phone",
|
||||||
phonePlaceholder: "Phone",
|
phonePlaceholder: "Phone",
|
||||||
createSubmit: "Create Recipient",
|
createSubmit: "Create Person",
|
||||||
updateSubmit: "Update Recipient",
|
updateSubmit: "Update Person",
|
||||||
},
|
},
|
||||||
fallback: {
|
fallback: {
|
||||||
unknownDepartment: "Unknown department",
|
unknownDepartment: "Unknown department",
|
||||||
@@ -759,30 +751,28 @@ describe("i18n dictionaries", () => {
|
|||||||
OTHER: "Other",
|
OTHER: "Other",
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
createSuccess: "Recipient created successfully",
|
createSuccess: "Person created successfully",
|
||||||
createFailure: "Failed to create recipient",
|
createFailure: "Failed to create person",
|
||||||
updateSuccess: "Recipient updated successfully",
|
updateSuccess: "Person updated successfully",
|
||||||
updateFailure: "Failed to update recipient",
|
updateFailure: "Failed to update person",
|
||||||
duplicateUsername: "Username already exists",
|
|
||||||
duplicateEmail: "Email already exists",
|
duplicateEmail: "Email already exists",
|
||||||
},
|
},
|
||||||
schema: {
|
schema: {
|
||||||
usernameRequired: "Username is required",
|
|
||||||
firstNameRequired: "First name is required",
|
firstNameRequired: "First name is required",
|
||||||
lastNameRequired: "Last name is required",
|
lastNameRequired: "Last name is required",
|
||||||
departmentRequired: "Department is required",
|
departmentRequired: "Department is required",
|
||||||
emailInvalid: "Email format is invalid",
|
emailInvalid: "Email format is invalid",
|
||||||
idRequired: "ID is required",
|
idRequired: "ID is required",
|
||||||
|
userIdInvalid: "User ID must be a valid UUID",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
expect(getDictionary("es").inventory.recipients).toEqual({
|
expect(getDictionary("es").inventory.people).toEqual({
|
||||||
list: {
|
list: {
|
||||||
title: "Destinatarios",
|
title: "Personas",
|
||||||
addLabel: "Agregar destinatario",
|
addLabel: "Agregar persona",
|
||||||
empty: "No se encontraron destinatarios.",
|
empty: "No se encontraron personas.",
|
||||||
columns: {
|
columns: {
|
||||||
username: "Usuario",
|
|
||||||
name: "Nombre",
|
name: "Nombre",
|
||||||
email: "Correo electrónico",
|
email: "Correo electrónico",
|
||||||
phone: "Teléfono",
|
phone: "Teléfono",
|
||||||
@@ -790,29 +780,26 @@ describe("i18n dictionaries", () => {
|
|||||||
actions: "Acciones",
|
actions: "Acciones",
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
view: "Ver destinatario",
|
view: "Ver persona",
|
||||||
edit: "Editar destinatario",
|
edit: "Editar persona",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
detail: {
|
detail: {
|
||||||
notFound: "Destinatario no encontrado",
|
notFound: "Persona no encontrada",
|
||||||
labels: {
|
labels: {
|
||||||
username: "Usuario",
|
|
||||||
email: "Correo electrónico",
|
email: "Correo electrónico",
|
||||||
phone: "Teléfono",
|
phone: "Teléfono",
|
||||||
department: "Departamento",
|
department: "Departamento",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
new: {
|
new: {
|
||||||
title: "Agregar destinatario",
|
title: "Agregar persona",
|
||||||
},
|
},
|
||||||
edit: {
|
edit: {
|
||||||
title: "Editar destinatario",
|
title: "Editar persona",
|
||||||
notFound: "Destinatario no encontrado",
|
notFound: "Persona no encontrada",
|
||||||
},
|
},
|
||||||
form: {
|
form: {
|
||||||
usernameLabel: "Usuario",
|
|
||||||
usernamePlaceholder: "Usuario",
|
|
||||||
firstNameLabel: "Nombre",
|
firstNameLabel: "Nombre",
|
||||||
firstNamePlaceholder: "Nombre",
|
firstNamePlaceholder: "Nombre",
|
||||||
lastNameLabel: "Apellido",
|
lastNameLabel: "Apellido",
|
||||||
@@ -823,8 +810,8 @@ describe("i18n dictionaries", () => {
|
|||||||
emailPlaceholder: "Correo electrónico",
|
emailPlaceholder: "Correo electrónico",
|
||||||
phoneLabel: "Teléfono",
|
phoneLabel: "Teléfono",
|
||||||
phonePlaceholder: "Teléfono",
|
phonePlaceholder: "Teléfono",
|
||||||
createSubmit: "Crear destinatario",
|
createSubmit: "Crear persona",
|
||||||
updateSubmit: "Actualizar destinatario",
|
updateSubmit: "Actualizar persona",
|
||||||
},
|
},
|
||||||
fallback: {
|
fallback: {
|
||||||
unknownDepartment: "Departamento desconocido",
|
unknownDepartment: "Departamento desconocido",
|
||||||
@@ -840,24 +827,34 @@ describe("i18n dictionaries", () => {
|
|||||||
OTHER: "Otro",
|
OTHER: "Otro",
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
createSuccess: "Destinatario creado correctamente",
|
createSuccess: "Persona creada correctamente",
|
||||||
createFailure: "Error al crear el destinatario",
|
createFailure: "Error al crear la persona",
|
||||||
updateSuccess: "Destinatario actualizado correctamente",
|
updateSuccess: "Persona actualizada correctamente",
|
||||||
updateFailure: "Error al actualizar el destinatario",
|
updateFailure: "Error al actualizar la persona",
|
||||||
duplicateUsername: "El nombre de usuario ya existe",
|
|
||||||
duplicateEmail: "El correo electrónico ya existe",
|
duplicateEmail: "El correo electrónico ya existe",
|
||||||
},
|
},
|
||||||
schema: {
|
schema: {
|
||||||
usernameRequired: "El usuario es obligatorio",
|
|
||||||
firstNameRequired: "El nombre es obligatorio",
|
firstNameRequired: "El nombre es obligatorio",
|
||||||
lastNameRequired: "El apellido es obligatorio",
|
lastNameRequired: "El apellido es obligatorio",
|
||||||
departmentRequired: "El departamento es obligatorio",
|
departmentRequired: "El departamento es obligatorio",
|
||||||
emailInvalid: "El correo electrónico no es válido",
|
emailInvalid: "El correo electrónico no es válido",
|
||||||
idRequired: "El ID es obligatorio",
|
idRequired: "El ID es obligatorio",
|
||||||
|
userIdInvalid: "El ID de usuario debe ser un UUID válido",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("does not have inventory.recipients or legacy recipient keys in either locale", () => {
|
||||||
|
expect("recipients" in getDictionary("en").inventory).toBe(false)
|
||||||
|
expect("recipients" in getDictionary("es").inventory).toBe(false)
|
||||||
|
expect("recipients" in getDictionary("en").layout.sidebar).toBe(false)
|
||||||
|
expect("recipient" in getDictionary("en").layout.addMenu).toBe(false)
|
||||||
|
expect("recipients" in getDictionary("es").layout.sidebar).toBe(false)
|
||||||
|
expect("recipient" in getDictionary("es").layout.addMenu).toBe(false)
|
||||||
|
expect("recipients" in getDictionary("en").dashboardHome.cards).toBe(false)
|
||||||
|
expect("recipients" in getDictionary("es").dashboardHome.cards).toBe(false)
|
||||||
|
})
|
||||||
|
|
||||||
it("provides localized movement UI copy for English and Spanish", () => {
|
it("provides localized movement UI copy for English and Spanish", () => {
|
||||||
expect(getDictionary("en").inventory.movements).toEqual({
|
expect(getDictionary("en").inventory.movements).toEqual({
|
||||||
list: {
|
list: {
|
||||||
@@ -940,10 +937,6 @@ describe("i18n dictionaries", () => {
|
|||||||
title: "Total Assets",
|
title: "Total Assets",
|
||||||
countLabel: "Total",
|
countLabel: "Total",
|
||||||
},
|
},
|
||||||
recipients: {
|
|
||||||
title: "Total Recipients",
|
|
||||||
countLabel: "Total",
|
|
||||||
},
|
|
||||||
people: {
|
people: {
|
||||||
title: "Total People",
|
title: "Total People",
|
||||||
countLabel: "Total",
|
countLabel: "Total",
|
||||||
@@ -962,10 +955,6 @@ describe("i18n dictionaries", () => {
|
|||||||
title: "Total de activos",
|
title: "Total de activos",
|
||||||
countLabel: "Total",
|
countLabel: "Total",
|
||||||
},
|
},
|
||||||
recipients: {
|
|
||||||
title: "Total de destinatarios",
|
|
||||||
countLabel: "Total",
|
|
||||||
},
|
|
||||||
people: {
|
people: {
|
||||||
title: "Total de personas",
|
title: "Total de personas",
|
||||||
countLabel: "Total",
|
countLabel: "Total",
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { signInSchema } from "@/schemas/auth.schema"
|
|||||||
import { createCategorySchema } from "@/schemas/category.schema"
|
import { createCategorySchema } from "@/schemas/category.schema"
|
||||||
import { createItemSchema, updateItemSchema } from "@/schemas/item.schema"
|
import { createItemSchema, updateItemSchema } from "@/schemas/item.schema"
|
||||||
import { createMovementSchema } from "@/schemas/movement.schema"
|
import { createMovementSchema } from "@/schemas/movement.schema"
|
||||||
import { createRecipientSchema } from "@/schemas/recipient.schema"
|
import { createPersonSchema } from "@/schemas/person.schema"
|
||||||
import { createUserSchema, updateUserSchema } from "@/schemas/user.schema"
|
import { createUserSchema, updateUserSchema } from "@/schemas/user.schema"
|
||||||
|
|
||||||
describe("core schemas", () => {
|
describe("core schemas", () => {
|
||||||
@@ -120,32 +120,29 @@ describe("core schemas", () => {
|
|||||||
).toBe(false)
|
).toBe(false)
|
||||||
})
|
})
|
||||||
|
|
||||||
it("validates recipient email only when present", () => {
|
it("validates person email only when present", () => {
|
||||||
expect(
|
expect(
|
||||||
createRecipientSchema.safeParse({
|
createPersonSchema.safeParse({
|
||||||
username: "recipient",
|
firstName: "Per",
|
||||||
firstName: "Rec",
|
lastName: "Son",
|
||||||
lastName: "Ipient",
|
|
||||||
department: "IT",
|
department: "IT",
|
||||||
email: "recipient@example.test",
|
email: "person@example.test",
|
||||||
}).success,
|
}).success,
|
||||||
).toBe(true)
|
).toBe(true)
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
createRecipientSchema.safeParse({
|
createPersonSchema.safeParse({
|
||||||
username: "recipient",
|
firstName: "Per",
|
||||||
firstName: "Rec",
|
lastName: "Son",
|
||||||
lastName: "Ipient",
|
|
||||||
department: "IT",
|
department: "IT",
|
||||||
email: "not-an-email",
|
email: "not-an-email",
|
||||||
}).success,
|
}).success,
|
||||||
).toBe(false)
|
).toBe(false)
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
createRecipientSchema.safeParse({
|
createPersonSchema.safeParse({
|
||||||
username: "recipient",
|
firstName: "Per",
|
||||||
firstName: "Rec",
|
lastName: "Son",
|
||||||
lastName: "Ipient",
|
|
||||||
department: "IT",
|
department: "IT",
|
||||||
email: "",
|
email: "",
|
||||||
}).success,
|
}).success,
|
||||||
|
|||||||
+42
-16
@@ -1,23 +1,22 @@
|
|||||||
import { describe, expect, it } from "vitest"
|
import { describe, expect, it } from "vitest"
|
||||||
|
|
||||||
import {
|
import {
|
||||||
buildCreateRecipientSchema,
|
buildCreatePersonSchema,
|
||||||
buildUpdateRecipientSchema,
|
buildUpdatePersonSchema,
|
||||||
} from "@/schemas/recipient.schema"
|
} from "@/schemas/person.schema"
|
||||||
|
|
||||||
const schemaCopy = {
|
const schemaCopy = {
|
||||||
usernameRequired: "El usuario es obligatorio",
|
|
||||||
firstNameRequired: "El nombre es obligatorio",
|
firstNameRequired: "El nombre es obligatorio",
|
||||||
lastNameRequired: "El apellido es obligatorio",
|
lastNameRequired: "El apellido es obligatorio",
|
||||||
departmentRequired: "El departamento es obligatorio",
|
departmentRequired: "El departamento es obligatorio",
|
||||||
emailInvalid: "El correo electrónico no es válido",
|
emailInvalid: "El correo electrónico no es válido",
|
||||||
idRequired: "El ID es obligatorio",
|
idRequired: "El ID es obligatorio",
|
||||||
|
userIdInvalid: "El ID de usuario debe ser un UUID válido",
|
||||||
}
|
}
|
||||||
|
|
||||||
describe("recipient schema localization", () => {
|
describe("person schema validation", () => {
|
||||||
it("uses localized required-field validation messages for create", () => {
|
it("uses localized required-field validation messages for create (no username)", () => {
|
||||||
const result = buildCreateRecipientSchema(schemaCopy).safeParse({
|
const result = buildCreatePersonSchema(schemaCopy).safeParse({
|
||||||
username: "",
|
|
||||||
firstName: "",
|
firstName: "",
|
||||||
lastName: "",
|
lastName: "",
|
||||||
department: "",
|
department: "",
|
||||||
@@ -27,7 +26,6 @@ describe("recipient schema localization", () => {
|
|||||||
if (!result.success) {
|
if (!result.success) {
|
||||||
const errors = result.error.flatten().fieldErrors
|
const errors = result.error.flatten().fieldErrors
|
||||||
|
|
||||||
expect(errors.username).toContain(schemaCopy.usernameRequired)
|
|
||||||
expect(errors.firstName).toContain(schemaCopy.firstNameRequired)
|
expect(errors.firstName).toContain(schemaCopy.firstNameRequired)
|
||||||
expect(errors.lastName).toContain(schemaCopy.lastNameRequired)
|
expect(errors.lastName).toContain(schemaCopy.lastNameRequired)
|
||||||
expect(errors.department).toContain(schemaCopy.departmentRequired)
|
expect(errors.department).toContain(schemaCopy.departmentRequired)
|
||||||
@@ -35,8 +33,7 @@ describe("recipient schema localization", () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it("uses a localized invalid email message for create", () => {
|
it("uses a localized invalid email message for create", () => {
|
||||||
const result = buildCreateRecipientSchema(schemaCopy).safeParse({
|
const result = buildCreatePersonSchema(schemaCopy).safeParse({
|
||||||
username: "ada",
|
|
||||||
firstName: "Ada",
|
firstName: "Ada",
|
||||||
lastName: "Lovelace",
|
lastName: "Lovelace",
|
||||||
department: "ENGINEERING",
|
department: "ENGINEERING",
|
||||||
@@ -51,10 +48,25 @@ describe("recipient schema localization", () => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("uses a localized invalid userId message for create with non-UUID", () => {
|
||||||
|
const result = buildCreatePersonSchema(schemaCopy).safeParse({
|
||||||
|
firstName: "Ada",
|
||||||
|
lastName: "Lovelace",
|
||||||
|
department: "ENGINEERING",
|
||||||
|
userId: "not-a-uuid",
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(result.success).toBe(false)
|
||||||
|
if (!result.success) {
|
||||||
|
expect(result.error.flatten().fieldErrors.userId).toContain(
|
||||||
|
schemaCopy.userIdInvalid,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
it("uses localized update identifier validation messages", () => {
|
it("uses localized update identifier validation messages", () => {
|
||||||
const result = buildUpdateRecipientSchema(schemaCopy).safeParse({
|
const result = buildUpdatePersonSchema(schemaCopy).safeParse({
|
||||||
id: "",
|
id: "",
|
||||||
username: "ada",
|
|
||||||
firstName: "Ada",
|
firstName: "Ada",
|
||||||
lastName: "Lovelace",
|
lastName: "Lovelace",
|
||||||
department: "ENGINEERING",
|
department: "ENGINEERING",
|
||||||
@@ -69,19 +81,33 @@ describe("recipient schema localization", () => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
it("preserves canonical department values and optional empty email semantics", () => {
|
it("preserves canonical department values and accepts optional userId UUID", () => {
|
||||||
const result = buildCreateRecipientSchema(schemaCopy).safeParse({
|
const result = buildCreatePersonSchema(schemaCopy).safeParse({
|
||||||
username: "ada",
|
|
||||||
firstName: "Ada",
|
firstName: "Ada",
|
||||||
lastName: "Lovelace",
|
lastName: "Lovelace",
|
||||||
department: "ENGINEERING",
|
department: "ENGINEERING",
|
||||||
email: "",
|
email: "",
|
||||||
|
userId: "550e8400-e29b-41d4-a716-446655440000",
|
||||||
})
|
})
|
||||||
|
|
||||||
expect(result.success).toBe(true)
|
expect(result.success).toBe(true)
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
expect(result.data.department).toBe("ENGINEERING")
|
expect(result.data.department).toBe("ENGINEERING")
|
||||||
expect(result.data.email).toBe("")
|
expect(result.data.email).toBe("")
|
||||||
|
expect(result.data.userId).toBe("550e8400-e29b-41d4-a716-446655440000")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
it("accepts create without username field (removed from schema)", () => {
|
||||||
|
const result = buildCreatePersonSchema(schemaCopy).safeParse({
|
||||||
|
firstName: "Ada",
|
||||||
|
lastName: "Lovelace",
|
||||||
|
department: "ENGINEERING",
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(result.success).toBe(true)
|
||||||
|
if (result.success) {
|
||||||
|
expect("username" in result.data).toBe(false)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
Reference in New Issue
Block a user