const { describe, it } = require("node:test");
const assert = require("node:assert");
const { normalizePosPayload } = require("../lib/pos-payload");

describe("pos payload normalization", () => {
  it("maps POS alias fields", () => {
    const order = normalizePosPayload(
      {
        orderNo: "A-12",
        cart: [{ menuItemName: "Broast", qty: 2, unitPrice: 450 }],
        grandTotal: 900,
        customer_phone: "03001234567",
        organizationName: "My Cafe",
        tableNo: 5,
      },
      { BUSINESS_NAME: "Fallback" },
    );
    assert.equal(order.orderNumber, "A-12");
    assert.equal(order.items[0].name, "Broast");
    assert.equal(order.items[0].quantity, 2);
    assert.equal(order.customerPhone, "03001234567");
    assert.equal(order.businessName, "My Cafe");
    assert.equal(order.tableNumber, 5);
  });

  it("computes tax from taxRate when tax missing", () => {
    const order = normalizePosPayload({ subtotal: 1000, taxRate: 5, total: 1050 });
    assert.equal(order.tax, 50);
  });
});
