/// import { describe, expect, test } from "bun:test"; import { formatZonedDateTime, getDefaultScheduledSendAt, isValidTimeZone, toLocalDateTimeInputValue, } from "../src/time-zone"; import { EXPENSE_CATEGORIES, formatElapsedSeconds, getEffectiveInvoiceStatus, parseReceiptText, } from "../src"; describe("shared domain behavior", () => { test("exposes the expense category vocabulary", () => { expect(EXPENSE_CATEGORIES).toContain("Professional Services"); }); test("calculates overdue status at day precision", () => { const yesterday = new Date(); yesterday.setDate(yesterday.getDate() - 1); expect(getEffectiveInvoiceStatus("sent", yesterday)).toBe("overdue"); expect(getEffectiveInvoiceStatus("paid", yesterday)).toBe("paid"); }); test("formats elapsed time", () => { expect(formatElapsedSeconds(3_661)).toBe("01:01:01"); }); test("extracts receipt totals and line items", () => { const receipt = parseReceiptText( "Corner Store\nCoffee 3.50\nSubtotal 3.50\nTax 0.31\nTotal 3.81", ); expect(receipt.amount).toBe(3.81); expect(receipt.tax).toBe(0.31); expect(receipt.items[0]?.name).toBe("Coffee"); }); }); describe("time-zone helpers", () => { test("formats the same instant in the selected IANA time zone", () => { const instant = new Date("2026-08-17T16:30:00.000Z"); expect(formatZonedDateTime(instant, "America/New_York")).toContain( "12:30 PM", ); expect(formatZonedDateTime(instant, "America/Los_Angeles")).toContain( "9:30 AM", ); }); test("validates IANA time zones", () => { expect(isValidTimeZone("America/New_York")).toBe(true); expect(isValidTimeZone("not/a-zone")).toBe(false); }); test("rounds the default schedule to the next local hour", () => { const result = getDefaultScheduledSendAt(new Date(2026, 7, 17, 10, 42, 19)); expect(toLocalDateTimeInputValue(result)).toBe("2026-08-17T11:00"); }); });