import { describe, expect, it } from 'vitest' import { detectFileType } from './file-type.ts' const bytes = (...values: (number | string)[]) => new Uint8Array(values.flatMap((v) => (typeof v === 'string' ? [...v].map((ch) => ch.charCodeAt(0)) : [v]))) describe('detectFileType', () => { it('recognises supported formats', () => { expect(detectFileType(bytes(0xff, 0xd8, 0xff, 0xe0))?.contentType).toBe('image/jpeg') expect(detectFileType(bytes('RIFF', 0, 0, 0, 0, 'WEBP'))?.contentType).toBe('image/webp') expect(detectFileType(bytes(0, 0, 0, 24, 'ftypheic'))?.contentType).toBe('image/heic') expect(detectFileType(bytes('%PDF-1.7'))?.contentType).toBe('application/pdf') }) it('rejects everything else', () => { expect(detectFileType(bytes(''))).toBeNull() expect(detectFileType(bytes('PK', 3, 4))).toBeNull() expect(detectFileType(new Uint8Array())).toBeNull() }) })