import { test } from "node:test"; import assert from "node:assert/strict"; import { issueQuoteInput, quoteExpiry, quoteResponseInput } from "../src/lib/quotes.ts"; const id = "d66c798a-f764-4b88-8d13-ace328ff1010"; test("quotation expiry requires an explicit timezone and a future instant within 90 days", () => { const now = Date.parse("2026-11-15T00:00:00.000Z"); assert.equal(quoteExpiry("2026-11-16T15:30:00+05:30", now), "2026-11-16T10:00:00.000Z"); assert.throws(() => quoteExpiry("2026-11-16T15:30:00", now)); assert.throws(() => quoteExpiry("2026-11-15T00:00:00Z", now), /next 90 days/); assert.throws(() => quoteExpiry("2027-03-01T00:00:00Z", now), /next 90 days/); }); test("quotation commands enforce unique variant lines and a trimmed response note", () => { const payload = { accountId: id, priceListId: id, expiresAt: "2026-11-16T10:00:00Z", idempotencyKey: id, lines: [{ variantId: id, quantity: 12 }] }; assert.deepEqual(issueQuoteInput.parse(payload), payload); assert.equal(issueQuoteInput.safeParse({ ...payload, lines: [...payload.lines, { variantId: id.toUpperCase(), quantity: 13 }] }).success, false); assert.equal(quoteResponseInput.parse({ kind: "ACCEPTED", note: " Confirmed by email ", idempotencyKey: id }).note, "Confirmed by email"); assert.equal(quoteResponseInput.safeParse({ kind: "DECLINED", note: " ", idempotencyKey: id }).success, false); });