Files
ims/tests/lib/capa/submit-validation.test.ts

31 lines
1.2 KiB
TypeScript

import { describe, it, expect } from 'vitest'
import { validateCapaSubmission, MAX_CAPA_PHOTOS } from '@/lib/capa/submit-validation'
const img = { type: 'image/jpeg' }
describe('validateCapaSubmission', () => {
it('accepts a note with 1 image and trims the note', () => {
expect(validateCapaSubmission(' done ', [img])).toEqual({ ok: true, note: 'done' })
})
it('rejects an empty or whitespace note', () => {
const r = validateCapaSubmission(' ', [img])
expect(r.ok).toBe(false)
if (!r.ok) expect(r.errors).toContain('Completion note is required')
})
it('rejects zero files', () => {
const r = validateCapaSubmission('done', [])
expect(r.ok).toBe(false)
if (!r.ok) expect(r.errors).toContain('At least 1 photo is required')
})
it('rejects more than the max', () => {
const r = validateCapaSubmission('done', Array(MAX_CAPA_PHOTOS + 1).fill(img))
expect(r.ok).toBe(false)
if (!r.ok) expect(r.errors).toContain(`At most ${MAX_CAPA_PHOTOS} photos are allowed`)
})
it('rejects non-image files', () => {
const r = validateCapaSubmission('done', [{ type: 'application/pdf' }])
expect(r.ok).toBe(false)
if (!r.ok) expect(r.errors).toContain('Only image files are allowed')
})
})