48 lines
1.6 KiB
TypeScript
48 lines
1.6 KiB
TypeScript
import { describe, expect, it } from "vitest"
|
|
|
|
import { localizeItemFieldErrors } from "@/actions/item.messages"
|
|
|
|
const actionCopy = {
|
|
createSuccess: "Artículo creado correctamente",
|
|
createFailure: "Error al crear el artículo",
|
|
updateSuccess: "Artículo actualizado correctamente",
|
|
updateFailure: "Error al actualizar el artículo",
|
|
deleteSuccess: "Artículo eliminado correctamente",
|
|
deleteFailure: "Error al eliminar el artículo",
|
|
duplicateName: "El artículo ya existe",
|
|
notFound: "Artículo no encontrado",
|
|
hasAssets: "No se puede eliminar un artículo con activos",
|
|
hasStock: "No se puede eliminar un artículo con stock",
|
|
invalidStock: "Stock inválido",
|
|
negativeStock: "El stock no puede ser negativo",
|
|
}
|
|
|
|
describe("item action message localization", () => {
|
|
it("localizes known item field errors", () => {
|
|
expect(
|
|
localizeItemFieldErrors(
|
|
{
|
|
name: ["An item with this name already exists"],
|
|
id: [
|
|
"Item not found",
|
|
"Item has assets, you cannot delete it",
|
|
"Item has stock, you cannot delete it",
|
|
],
|
|
stock: ["Stock cannot be negative", "Invalid stock"],
|
|
},
|
|
actionCopy,
|
|
),
|
|
).toEqual({
|
|
name: [actionCopy.duplicateName],
|
|
id: [actionCopy.notFound, actionCopy.hasAssets, actionCopy.hasStock],
|
|
stock: [actionCopy.negativeStock, actionCopy.invalidStock],
|
|
})
|
|
})
|
|
|
|
it("keeps unknown messages unchanged", () => {
|
|
expect(
|
|
localizeItemFieldErrors({ name: ["Unexpected item issue"] }, actionCopy),
|
|
).toEqual({ name: ["Unexpected item issue"] })
|
|
})
|
|
})
|