import { test } from "node:test"; import assert from "node:assert/strict"; import { ulid, jobIdTime } from "./ulid"; // Run with: pnpm --filter yt-dlp-transcript-common exec tsx --test common/jobs/ulid.test.ts test("ulid is 26 chars and encodes the given time", () => { const now = 1_700_000_000_000; const id = ulid(now); assert.equal(id.length, 26); assert.equal(jobIdTime(id), now); }); test("jobIdTime round-trips a real timestamp within a ms", () => { const now = 1_735_000_123_456; assert.equal(jobIdTime(ulid(now)), now); }); test("jobIdTime decodes the legacy `-` scheme", () => { const now = 1_712_000_000_000; const legacy = `${now.toString(36)}-ab12cd`; assert.equal(jobIdTime(legacy), now); }); test("ulids sort lexicographically in time order", () => { const a = ulid(1_000); const b = ulid(2_000); const c = ulid(3_000); const shuffled = [c, a, b]; const sorted = [...shuffled].sort(); assert.deepEqual(sorted, [a, b, c]); }); test("jobIdTime returns 0 for garbage", () => { assert.equal(jobIdTime(""), 0); assert.equal(jobIdTime("!!!"), 0); });