feat(tests): agregar pruebas para la validación de proformas y manejo de items
This commit is contained in:
parent
6b05ee01f3
commit
569f150c19
@ -0,0 +1,59 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
|
||||
import { buildProformaUpdateDefault } from "../utils";
|
||||
|
||||
import { ProformaUpdateFormSchema } from "./proforma-update-form.schema";
|
||||
|
||||
const buildValidForm = () => ({
|
||||
...buildProformaUpdateDefault(),
|
||||
proformaDate: "2026-09-14",
|
||||
operationDate: "2026-09-14",
|
||||
customerId: "customer-1",
|
||||
});
|
||||
|
||||
test("acepta un borrador sin líneas", () => {
|
||||
assert.equal(ProformaUpdateFormSchema.safeParse(buildValidForm()).success, true);
|
||||
});
|
||||
|
||||
test("acepta una línea válida", () => {
|
||||
assert.equal(
|
||||
ProformaUpdateFormSchema.safeParse({
|
||||
...buildValidForm(),
|
||||
items: [
|
||||
{
|
||||
id: "item-1",
|
||||
position: 0,
|
||||
description: "Servicio",
|
||||
quantity: 1,
|
||||
unitAmount: 100,
|
||||
itemDiscountPercentage: null,
|
||||
taxPercentage: 21,
|
||||
recPercentage: null,
|
||||
},
|
||||
],
|
||||
}).success,
|
||||
true
|
||||
);
|
||||
});
|
||||
|
||||
test("mantiene la validación de la estructura de las líneas", () => {
|
||||
assert.equal(
|
||||
ProformaUpdateFormSchema.safeParse({
|
||||
...buildValidForm(),
|
||||
items: [
|
||||
{
|
||||
id: "item-1",
|
||||
position: "0",
|
||||
description: "Servicio",
|
||||
quantity: 1,
|
||||
unitAmount: 100,
|
||||
itemDiscountPercentage: null,
|
||||
taxPercentage: 21,
|
||||
recPercentage: null,
|
||||
},
|
||||
],
|
||||
}).success,
|
||||
false
|
||||
);
|
||||
});
|
||||
@ -51,9 +51,7 @@ export const ProformaUpdateFormSchema = z
|
||||
paymentMethodId: z.string().nullable(),
|
||||
paymentTermId: z.string().nullable(),
|
||||
|
||||
items: z
|
||||
.array(ProformaItemUpdateFormSchema)
|
||||
.min(1, "Debe haber al menos un item en la proforma"),
|
||||
items: z.array(ProformaItemUpdateFormSchema),
|
||||
})
|
||||
.refine(
|
||||
(formValues) => {
|
||||
|
||||
@ -81,3 +81,25 @@ test("mantiene los items vacíos y respeta su orden al construir el PUT de updat
|
||||
});
|
||||
assert.equal(result.data.items?.[1]?.position, 1);
|
||||
});
|
||||
|
||||
test("omite items cuando no se han modificado", () => {
|
||||
const formData = buildFormData();
|
||||
|
||||
const result = buildUpdateProformaByIdParams(
|
||||
"proforma-1",
|
||||
{ reference: "Referencia actualizada" },
|
||||
formData
|
||||
);
|
||||
|
||||
assert.equal("items" in result.data, false);
|
||||
});
|
||||
|
||||
test("envía una colección vacía cuando el usuario elimina todas las líneas", () => {
|
||||
const formData = buildFormData({
|
||||
items: [],
|
||||
});
|
||||
|
||||
const result = buildUpdateProformaByIdParams("proforma-1", { items: [] }, formData);
|
||||
|
||||
assert.deepEqual(result.data.items, []);
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user