import { IProfileContext } from "../Profile.context"; import { createProfileMapper } from "./profile.mapper"; const source = (defaultShowLineDiscountColumn: boolean | null, defaultTaxLabel?: string | null) => ({ default_show_line_discount_column: defaultShowLineDiscountColumn, dataValues: { id: "770672b9-5a87-4e8e-a8af-8b44a7432e12", name: "Dealer", status: "actived", lang_code: "es", currency_code: "EUR", logo: "", contact_information: "", default_payment_method: "", default_notes: "", default_legal_terms: "", default_quote_validity: "", default_tax: 2100, default_tax_label: defaultTaxLabel, }, }) as any; describe("ProfileMapper default_show_line_discount_column", () => { const mapper = createProfileMapper({} as IProfileContext); it("maps false in both persistence directions", () => { const profile = mapper.mapToDomain(source(false)); expect(profile.defaultShowLineDiscountColumn).toBe(false); expect(mapper.mapToPersistence(profile).default_show_line_discount_column).toBe(false); }); it("uses true for historical null values", () => { expect(mapper.mapToDomain(source(null)).defaultShowLineDiscountColumn).toBe(true); }); it("maps a tax label in both persistence directions", () => { const profile = mapper.mapToDomain(source(true, "% IGIC")); expect(profile.defaultTaxLabel.toString()).toBe("% IGIC"); expect(mapper.mapToPersistence(profile).default_tax_label).toBe("% IGIC"); }); it("uses the default tax label for historical null values", () => { expect(mapper.mapToDomain(source(true, null)).defaultTaxLabel.toString()).toBe("% IVA"); }); });