import { describe, expect, it } from "vitest";
import { buildInHouseBillLines } from "./job-lines.in-house-bill-lines.utils";

describe("buildInHouseBillLines", () => {
  it("carries job line part quantity into the in-house bill line", () => {
    const billLines = buildInHouseBillLines([
      {
        id: "job-line-1",
        act_price: 125,
        line_desc: "Door shell",
        line_remarks: "Left",
        part_type: "PAA",
        part_qty: 3
      }
    ]);

    expect(billLines[0]).toMatchObject({
      joblineid: "job-line-1",
      actual_price: 125,
      actual_cost: 0,
      line_desc: "Door shell",
      line_remarks: "Left",
      part_type: "PAA",
      quantity: 3,
      applicable_taxes: { local: false, state: false, federal: false }
    });
  });

  it("falls back to legacy quantity and then one when part quantity is absent", () => {
    expect(buildInHouseBillLines([{ id: "legacy", quantity: 2 }])[0].quantity).toBe(2);
    expect(buildInHouseBillLines([{ id: "missing" }])[0].quantity).toBe(1);
  });
});
