feat(i18n): localize assignment validation messages
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
import { describe, expect, it } from "vitest"
|
||||
|
||||
import { localizeAssignmentFieldErrors } from "@/actions/assignment.messages"
|
||||
|
||||
const actionCopy = {
|
||||
createSuccess: "Asignación creada correctamente",
|
||||
createFailure: "Error al crear la asignación",
|
||||
updateSuccess: "Asignación actualizada correctamente",
|
||||
updateFailure: "Error al actualizar la asignación",
|
||||
returnSuccess: "Asignación devuelta correctamente",
|
||||
returnFailure: "Error al devolver la asignación",
|
||||
notFound: "Asignación no encontrada",
|
||||
itemNotFound: "Artículo no encontrado",
|
||||
itemInsufficientStock: "El artículo no tiene stock suficiente",
|
||||
assetNotFound: "Activo no encontrado",
|
||||
assetItemMismatch: "El activo no pertenece al artículo",
|
||||
assignmentAlreadyReturned: "La asignación ya fue devuelta",
|
||||
invalidData: "Datos de asignación inválidos",
|
||||
genericFailure: "Error al procesar la asignación",
|
||||
}
|
||||
|
||||
describe("assignment action message localization", () => {
|
||||
it("localizes known assignment field errors from use-case output", () => {
|
||||
expect(
|
||||
localizeAssignmentFieldErrors(
|
||||
{
|
||||
itemId: ["Item not found"],
|
||||
quantity: ["Item does not have enough stock"],
|
||||
assetId: ["Asset not found"],
|
||||
id: ["Assignment not found", "Assignment already returned"],
|
||||
},
|
||||
actionCopy,
|
||||
),
|
||||
).toEqual({
|
||||
itemId: [actionCopy.itemNotFound],
|
||||
quantity: [actionCopy.itemInsufficientStock],
|
||||
assetId: [actionCopy.assetNotFound],
|
||||
id: [actionCopy.notFound, actionCopy.assignmentAlreadyReturned],
|
||||
})
|
||||
})
|
||||
|
||||
it("localizes asset-item mismatch and generic data errors", () => {
|
||||
expect(
|
||||
localizeAssignmentFieldErrors(
|
||||
{
|
||||
assetId: ["Asset does not belong to item"],
|
||||
error: ["Invalid assignment data"],
|
||||
},
|
||||
actionCopy,
|
||||
),
|
||||
).toEqual({
|
||||
assetId: [actionCopy.assetItemMismatch],
|
||||
error: [actionCopy.invalidData],
|
||||
})
|
||||
})
|
||||
|
||||
it("keeps unknown messages unchanged", () => {
|
||||
expect(
|
||||
localizeAssignmentFieldErrors(
|
||||
{ error: ["Unexpected assignment issue"] },
|
||||
actionCopy,
|
||||
),
|
||||
).toEqual({ error: ["Unexpected assignment issue"] })
|
||||
})
|
||||
|
||||
it("returns undefined when no errors are provided", () => {
|
||||
expect(localizeAssignmentFieldErrors(undefined, actionCopy)).toBeUndefined()
|
||||
})
|
||||
|
||||
it("returns undefined when errors object is empty", () => {
|
||||
expect(localizeAssignmentFieldErrors({}, actionCopy)).toEqual({})
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user