import { describe, it, expect } from 'vitest' import { isValidSlug, isValidArticleCategory, isValidWorkCategory, normalizeBlocks, normalizeTags, normalizeGallery, } from '../server/utils/validateContent' describe('content validation', () => { it('validates slugs', () => { expect(isValidSlug('design-trends-2026')).toBe(true) expect(isValidSlug('a')).toBe(false) expect(isValidSlug('')).toBe(false) expect(isValidSlug('with space')).toBe(false) expect(isValidSlug('UPPER')).toBe(false) expect(isValidSlug('x'.repeat(65))).toBe(false) }) it('validates article/work categories', () => { expect(isValidArticleCategory('insights')).toBe(true) expect(isValidArticleCategory('projects')).toBe(true) expect(isValidArticleCategory('bogus')).toBe(false) expect(isValidWorkCategory('webDesign')).toBe(true) expect(isValidWorkCategory('development')).toBe(true) expect(isValidWorkCategory('insights')).toBe(false) }) it('normalizes content blocks (filters invalid)', () => { const input = [ { type: 'paragraph', text: 'hi' }, { type: 'heading', text: 'title' }, { type: 'quote', text: 'quote' }, { type: 'image', text: 'https://x/a.png' }, { type: 'bogus', text: 'x' }, { text: 'no-type' }, null, 'string', ] expect(normalizeBlocks(input as never[])).toEqual([ { type: 'paragraph', text: 'hi' }, { type: 'heading', text: 'title' }, { type: 'quote', text: 'quote' }, { type: 'image', text: 'https://x/a.png' }, ]) expect(normalizeBlocks(undefined)).toEqual([]) }) it('normalizes tags and gallery', () => { expect(normalizeTags([' a ', 'b', '', 5])).toEqual(['a', 'b']) expect(normalizeTags('not-array' as never)).toEqual([]) expect(normalizeGallery(['/x.png', ' ', '/y.png'])).toEqual(['/x.png', '/y.png']) }) })