46 lines
1.4 KiB
TypeScript
46 lines
1.4 KiB
TypeScript
import { describe, expect, it } from "vitest"
|
|
|
|
import { localizeCategoryFieldErrors } from "@/actions/category.messages"
|
|
|
|
const actionCopy = {
|
|
createSuccess: "Categoría creada correctamente",
|
|
createFailure: "Error al crear la categoría",
|
|
updateSuccess: "Categoría actualizada correctamente",
|
|
updateFailure: "Error al actualizar la categoría",
|
|
deleteSuccess: "Categoría eliminada correctamente",
|
|
deleteFailure: "Error al eliminar la categoría",
|
|
duplicateName: "La categoría ya existe",
|
|
unchangedName: "El nombre de la categoría no cambió",
|
|
notFound: "Categoría no encontrada",
|
|
hasItems: "No se puede eliminar una categoría con artículos",
|
|
}
|
|
|
|
describe("category action message localization", () => {
|
|
it("localizes known category field errors", () => {
|
|
expect(
|
|
localizeCategoryFieldErrors(
|
|
{
|
|
name: [
|
|
"Category already exists",
|
|
"Category name is the same as the old one",
|
|
],
|
|
id: ["Category not found", "Category has items"],
|
|
},
|
|
actionCopy,
|
|
),
|
|
).toEqual({
|
|
name: [actionCopy.duplicateName, actionCopy.unchangedName],
|
|
id: [actionCopy.notFound, actionCopy.hasItems],
|
|
})
|
|
})
|
|
|
|
it("keeps unknown messages unchanged", () => {
|
|
expect(
|
|
localizeCategoryFieldErrors(
|
|
{ name: ["Unexpected category issue"] },
|
|
actionCopy,
|
|
),
|
|
).toEqual({ name: ["Unexpected category issue"] })
|
|
})
|
|
})
|