File size: 928 Bytes
004f460
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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'))
})