| import { describe, it, expect } from 'vitest' |
| import { validateImageFile, validateAudioFile, MAX_IMAGE_BYTES } from './validate' |
|
|
| function fakeFile(type: string, size: number): File { |
| const f = new File(['x'], 'f', { type }) |
| Object.defineProperty(f, 'size', { value: size }) |
| return f |
| } |
|
|
| describe('media validation', () => { |
| it('accepts an image', () => expect(validateImageFile(fakeFile('image/png', 1000))).toBeUndefined()) |
| it('rejects non-image for image slot', () => expect(validateImageFile(fakeFile('audio/wav', 1000))).toBe('bio.err.imageType')) |
| it('rejects oversize image', () => expect(validateImageFile(fakeFile('image/png', MAX_IMAGE_BYTES + 1))).toBe('bio.err.tooLarge')) |
| it('accepts audio', () => expect(validateAudioFile(fakeFile('audio/webm', 1000))).toBeUndefined()) |
| it('rejects non-audio for audio slot', () => expect(validateAudioFile(fakeFile('image/png', 1000))).toBe('bio.err.audioType')) |
| }) |
|
|