import { MoneyValue, Percentage, Quantity } from "@/core/common/domain"; import { CustomerInvoiceItemDescription } from "../../value-objects"; import { CustomerInvoiceItem } from "./customerCustomerInvoice-item"; describe("CustomerInvoiceItem", () => { it("debería calcular correctamente el subtotal (unitPrice * quantity)", () => { const props = { description: CustomerInvoiceItemDescription.create("Producto A"), quantity: Quantity.create({ amount: 200, scale: 2 }), unitPrice: MoneyValue.create(50), discount: Percentage.create(0), }; const result = CustomerInvoiceItem.create(props); expect(result.isOk()).toBe(true); const customerCustomerInvoiceItem = result.unwrap(); expect(customerCustomerInvoiceItem.subtotalPrice.value).toBe(100); // 50 * 2 }); it("debería calcular correctamente el total con descuento", () => { const props = { description: new CustomerInvoiceItemDescription("Producto B"), quantity: new Quantity(3), unitPrice: new MoneyValue(30), discount: new Percentage(10), // 10% }; const result = CustomerInvoiceItem.create(props); expect(result.isOk()).toBe(true); const customerCustomerInvoiceItem = result.unwrap(); expect(customerCustomerInvoiceItem.totalPrice.value).toBe(81); // (30 * 3) - 10% de (30 * 3) }); it("debería devolver los valores correctos de las propiedades", () => { const props = { description: new CustomerInvoiceItemDescription("Producto C"), quantity: new Quantity(1), unitPrice: new MoneyValue(100), discount: new Percentage(5), }; const result = CustomerInvoiceItem.create(props); expect(result.isOk()).toBe(true); const customerCustomerInvoiceItem = result.unwrap(); expect(customerCustomerInvoiceItem.description.value).toBe("Producto C"); expect(customerCustomerInvoiceItem.quantity.value).toBe(1); expect(customerCustomerInvoiceItem.unitPrice.value).toBe(100); expect(customerCustomerInvoiceItem.discount.value).toBe(5); }); it("debería manejar correctamente un descuento del 0%", () => { const props = { description: new CustomerInvoiceItemDescription("Producto D"), quantity: new Quantity(4), unitPrice: new MoneyValue(25), discount: new Percentage(0), }; const result = CustomerInvoiceItem.create(props); expect(result.isOk()).toBe(true); const customerCustomerInvoiceItem = result.unwrap(); expect(customerCustomerInvoiceItem.totalPrice.value).toBe(100); // 25 * 4 }); it("debería manejar correctamente un descuento del 100%", () => { const props = { description: new CustomerInvoiceItemDescription("Producto E"), quantity: new Quantity(2), unitPrice: new MoneyValue(50), discount: new Percentage(100), }; const result = CustomerInvoiceItem.create(props); expect(result.isOk()).toBe(true); const customerCustomerInvoiceItem = result.unwrap(); expect(customerCustomerInvoiceItem.totalPrice.value).toBe(0); // (50 * 2) - 100% de (50 * 2) }); });