feat(items): adapt item flows to inventory schema defaults and SKU generation
This commit is contained in:
@@ -10,6 +10,10 @@ const schemaCopy = {
|
||||
nameRequired: "El nombre es obligatorio",
|
||||
categoryRequired: "La categoría es obligatoria",
|
||||
stockRequired: "El stock es obligatorio",
|
||||
trackingTypeRequired: "El tipo de seguimiento es obligatorio",
|
||||
invalidTrackingType: "Tipo de seguimiento inválido",
|
||||
statusRequired: "El estado es obligatorio",
|
||||
invalidStatus: "Estado inválido",
|
||||
itemRequired: "El artículo es obligatorio",
|
||||
}
|
||||
|
||||
@@ -31,6 +35,47 @@ describe("item schema localization", () => {
|
||||
}
|
||||
})
|
||||
|
||||
it("supports operational item fields with default tracking metadata", () => {
|
||||
const result = buildCreateItemSchema(schemaCopy).safeParse({
|
||||
name: "Laptop",
|
||||
categoryId: "category-1",
|
||||
stock: "2",
|
||||
})
|
||||
|
||||
expect(result.success).toBe(true)
|
||||
if (result.success) {
|
||||
expect(result.data).toMatchObject({
|
||||
name: "Laptop",
|
||||
categoryId: "category-1",
|
||||
stock: 2,
|
||||
trackingType: "QUANTITY",
|
||||
status: "ACTIVE",
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
it("accepts explicit operational item fields", () => {
|
||||
const result = buildCreateItemSchema(schemaCopy).safeParse({
|
||||
name: "Laptop",
|
||||
categoryId: "category-1",
|
||||
stock: "2",
|
||||
trackingType: "SERIALIZED",
|
||||
status: "DISCONTINUED",
|
||||
minStock: "1",
|
||||
targetStock: "5",
|
||||
})
|
||||
|
||||
expect(result.success).toBe(true)
|
||||
if (result.success) {
|
||||
expect(result.data).toMatchObject({
|
||||
trackingType: "SERIALIZED",
|
||||
status: "DISCONTINUED",
|
||||
minStock: 1,
|
||||
targetStock: 5,
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
it("uses localized update identifier validation messages", () => {
|
||||
const result = buildUpdateItemSchema(schemaCopy).safeParse({
|
||||
id: "",
|
||||
@@ -47,6 +92,30 @@ describe("item schema localization", () => {
|
||||
}
|
||||
})
|
||||
|
||||
it("allows operational item fields in update payloads", () => {
|
||||
const result = buildUpdateItemSchema(schemaCopy).safeParse({
|
||||
id: "item-1",
|
||||
name: "Laptop",
|
||||
categoryId: "category-1",
|
||||
stock: 3,
|
||||
trackingType: "SERIALIZED",
|
||||
status: "ARCHIVED",
|
||||
minStock: "2",
|
||||
targetStock: "6",
|
||||
})
|
||||
|
||||
expect(result.success).toBe(true)
|
||||
if (result.success) {
|
||||
expect(result.data).toMatchObject({
|
||||
id: "item-1",
|
||||
trackingType: "SERIALIZED",
|
||||
status: "ARCHIVED",
|
||||
minStock: 2,
|
||||
targetStock: 6,
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
it("uses localized get-by-id validation messages", () => {
|
||||
const result = buildGetItemByIdSchema(schemaCopy).safeParse({ id: "" })
|
||||
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
import { describe, expect, it } from "vitest"
|
||||
|
||||
import { buildItemSku } from "@/use-cases/item.helpers"
|
||||
|
||||
describe("item sku generation", () => {
|
||||
it("builds a normalized sku from the item name", () => {
|
||||
expect(buildItemSku("Item A!", 0)).toBe("ITEM-A")
|
||||
})
|
||||
|
||||
it("adds a numeric suffix for repeated normalized names", () => {
|
||||
expect(buildItemSku("Item A?", 1)).toBe("ITEM-A-2")
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user