feat(documents): PDF prints only the document's selected company custom fields
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -5,6 +5,9 @@ import {
|
||||
} from "../utils/custom-fields";
|
||||
import { afterAll } from "vitest";
|
||||
import { createOffer, getOffer } from "../services/offers.service";
|
||||
import { renderOfferHtml } from "../routes/admin/offers-pdf";
|
||||
import type { OfferForPdf } from "../routes/admin/offers-pdf";
|
||||
import type { company_settings } from "@prisma/client";
|
||||
import prisma from "../config/database";
|
||||
|
||||
describe("selected custom fields encode/decode", () => {
|
||||
@@ -71,3 +74,56 @@ describe("offers selected_custom_fields round-trip", () => {
|
||||
expect(row?.selected_custom_fields).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe("offer PDF prints only selected company custom fields", () => {
|
||||
// Two company custom fields; the document selects only index 0.
|
||||
const settings = {
|
||||
company_name: "Test s.r.o.",
|
||||
custom_fields: JSON.stringify({
|
||||
fields: [
|
||||
{ name: "Email", value: "selected@example.com", showLabel: false },
|
||||
{ name: "Web", value: "notselected.example.com", showLabel: false },
|
||||
],
|
||||
field_order: [],
|
||||
}),
|
||||
logo_data: null,
|
||||
} as unknown as company_settings;
|
||||
|
||||
const baseQuotation = {
|
||||
quotation_number: "TEST-2098-001",
|
||||
language: "EN",
|
||||
currency: "EUR",
|
||||
valid_until: new Date("2098-01-01"),
|
||||
project_code: null,
|
||||
created_at: new Date("2098-01-01"),
|
||||
customers: { name: "Cust" },
|
||||
quotation_items: [],
|
||||
scope_sections: [],
|
||||
};
|
||||
|
||||
it("renders the selected custom field and omits the non-selected one", () => {
|
||||
const html = renderOfferHtml(
|
||||
{
|
||||
...baseQuotation,
|
||||
selected_custom_fields: "[0]",
|
||||
} as unknown as OfferForPdf,
|
||||
settings,
|
||||
);
|
||||
expect(html).toContain("selected@example.com");
|
||||
expect(html).not.toContain("notselected.example.com");
|
||||
});
|
||||
|
||||
it("prints NO company custom fields when the document selects none", () => {
|
||||
// The company call site always passes a parsed array; a null column
|
||||
// decodes to [] → empty selection → no custom fields on the document.
|
||||
const html = renderOfferHtml(
|
||||
{
|
||||
...baseQuotation,
|
||||
selected_custom_fields: null,
|
||||
} as unknown as OfferForPdf,
|
||||
settings,
|
||||
);
|
||||
expect(html).not.toContain("selected@example.com");
|
||||
expect(html).not.toContain("notselected.example.com");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user