1import { describe, expect, it } from 'vitest';2import {3 base64UrlToBytes,4 bytesToBase64Url,5 isoOf,6 nanoid,7 randomDecimalSeed,8 sha256Hex,9} from '../src/util';1011describe('nanoid', () => {12 it('produces 21-char url-safe ids by default', () => {13 for (let i = 0; i < 50; i++) {14 expect(nanoid()).toMatch(/^[A-Za-z0-9_-]{21}$/);15 }16 });1718 it('honors a custom size', () => {19 expect(nanoid(8)).toHaveLength(8);20 });2122 it('does not collide over a small sample', () => {23 const seen = new Set(Array.from({ length: 1000 }, () => nanoid()));24 expect(seen.size).toBe(1000);25 });26});2728describe('randomDecimalSeed', () => {29 it('matches the CreateSimInput seed pattern', () => {30 for (let i = 0; i < 100; i++) {31 expect(randomDecimalSeed()).toMatch(/^\d{1,15}$/);32 }33 });34});3536describe('base64url', () => {37 it('round-trips arbitrary bytes without padding chars', () => {38 const bytes = new Uint8Array([0, 1, 250, 255, 128, 63, 62]);39 const encoded = bytesToBase64Url(bytes);40 expect(encoded).not.toMatch(/[+/=]/);41 expect([...base64UrlToBytes(encoded)]).toEqual([...bytes]);42 });43});4445describe('sha256Hex / isoOf', () => {46 it('hashes the empty string to the known vector', async () => {47 expect(await sha256Hex('')).toBe(48 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855',49 );50 });5152 it('formats epoch seconds as ISO', () => {53 expect(isoOf(0)).toBe('1970-01-01T00:00:00.000Z');54 });55});