Presupuestador_web/server/src/contexts/sales/infrastructure/mappers/quote.mapper.test.ts

53 lines
1.6 KiB
TypeScript

import { ISalesContext } from "../Sales.context";
import { createQuoteMapper } from "./quote.mapper";
const source = (showLineDiscountColumn: boolean | null, taxLabel?: string | null) =>
({
show_line_discount_column: showLineDiscountColumn,
items: [],
dataValues: {
id: "770672b9-5a87-4e8e-a8af-8b44a7432e12",
status: "draft",
date: "2026-10-03",
reference: "Q-1",
currency_code: "EUR",
lang_code: "es",
customer_reference: "",
customer_information: "Customer",
validity: "",
payment_method: "",
notes: "",
discount: 0,
tax: 21,
tax_label: taxLabel,
dealer_id: "770672b9-5a87-4e8e-a8af-8b44a7432e12",
date_sent: null,
},
}) as any;
describe("QuoteMapper show_line_discount_column", () => {
const mapper = createQuoteMapper({} as ISalesContext);
it("maps false in both persistence directions", () => {
const quote = mapper.mapToDomain(source(false));
expect(quote.showLineDiscountColumn).toBe(false);
expect(mapper.mapToPersistence(quote).show_line_discount_column).toBe(false);
});
it("uses true for historical null values", () => {
expect(mapper.mapToDomain(source(null)).showLineDiscountColumn).toBe(true);
});
it("maps a tax label in both persistence directions", () => {
const quote = mapper.mapToDomain(source(true, "% IGIC"));
expect(quote.taxLabel.toString()).toBe("% IGIC");
expect(mapper.mapToPersistence(quote).tax_label).toBe("% IGIC");
});
it("uses the default tax label for historical null values", () => {
expect(mapper.mapToDomain(source(true, null)).taxLabel.toString()).toBe("% IVA");
});
});