import { describe, expect, test } from "bun:test"; import { parseCustomerOccurrenceName, parseTrackMessageId, } from "./sdk-event-options"; describe("parseCustomerOccurrenceName", () => { test("requires a string, trims it, and preserves the normalized length", () => { expect(parseCustomerOccurrenceName(" Checkout ", "eventName")).toBe( "Checkout", ); expect(parseCustomerOccurrenceName("n".repeat(255), "eventName")).toBe( "n".repeat(255), ); expect(() => parseCustomerOccurrenceName(undefined, "eventName")).toThrow( "eventName must be a non-empty string", ); }); test("rejects blank and overlong normalized names", () => { expect(() => parseCustomerOccurrenceName(" ", "pageName")).toThrow( "pageName must be a non-empty string", ); expect(() => parseCustomerOccurrenceName(` ${"n".repeat(256)} `, "screenName"), ).toThrow("screenName must be at most 255 characters"); }); }); describe("parseTrackMessageId", () => { test("preserves valid IDs without normalization", () => { expect(parseTrackMessageId(" occurrence_123 ")).toBe(" occurrence_123 "); expect(parseTrackMessageId("m".repeat(255))).toBe("m".repeat(255)); expect(parseTrackMessageId(undefined)).toBeUndefined(); }); test("rejects IDs that ingestion cannot preserve", () => { expect(() => parseTrackMessageId("")).toThrow("non-empty string"); expect(() => parseTrackMessageId(" ")).toThrow("non-empty string"); expect(() => parseTrackMessageId("m".repeat(256))).toThrow( "at most 255 characters", ); }); });