2026-04-18 06:48:27 +02:00
|
|
|
import { assertEquals, assertThrows } from '@std/assert'
|
2026-04-18 05:23:18 +02:00
|
|
|
import { validatePost, validateSlug } from '../src/core/validation.ts'
|
|
|
|
|
import type { Frontmatter } from '../src/core/frontmatter.ts'
|
|
|
|
|
|
|
|
|
|
Deno.test('validateSlug: akzeptiert lowercase/digits/hyphen', () => {
|
|
|
|
|
validateSlug('abc-123')
|
|
|
|
|
validateSlug('a')
|
|
|
|
|
validateSlug('dezentrale-oep-oer')
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
Deno.test('validateSlug: lehnt Großbuchstaben ab', () => {
|
|
|
|
|
assertThrows(() => validateSlug('Abc'), Error, 'slug')
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
Deno.test('validateSlug: lehnt Unterstriche/Leerzeichen ab', () => {
|
|
|
|
|
assertThrows(() => validateSlug('a_b'), Error, 'slug')
|
|
|
|
|
assertThrows(() => validateSlug('a b'), Error, 'slug')
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
Deno.test('validateSlug: lehnt führenden Bindestrich ab', () => {
|
|
|
|
|
assertThrows(() => validateSlug('-abc'), Error, 'slug')
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
Deno.test('validatePost: ok bei vollständigem Frontmatter', () => {
|
|
|
|
|
const fm: Frontmatter = {
|
|
|
|
|
title: 'T',
|
|
|
|
|
slug: 'ok-slug',
|
|
|
|
|
date: new Date('2024-01-01'),
|
|
|
|
|
}
|
|
|
|
|
validatePost(fm)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
Deno.test('validatePost: fehlt title', () => {
|
|
|
|
|
const fm = { slug: 'ok', date: new Date() } as unknown as Frontmatter
|
|
|
|
|
assertThrows(() => validatePost(fm), Error, 'title')
|
|
|
|
|
})
|
|
|
|
|
|
2026-04-18 06:48:27 +02:00
|
|
|
Deno.test('validatePost: lehnt beliebige strings als date ab', () => {
|
2026-04-18 05:23:18 +02:00
|
|
|
const fm = { title: 'T', slug: 'ok', date: 'not-a-date' } as unknown as Frontmatter
|
|
|
|
|
assertThrows(() => validatePost(fm), Error, 'date')
|
|
|
|
|
})
|
2026-04-18 06:48:27 +02:00
|
|
|
|
|
|
|
|
Deno.test('validatePost: akzeptiert YYYY-MM-DD string-date (coerce zu Date)', () => {
|
|
|
|
|
const fm = { title: 'T', slug: 'ok', date: '2023-02-26' } as unknown as Frontmatter
|
|
|
|
|
validatePost(fm)
|
|
|
|
|
assertEquals(fm.date instanceof Date, true)
|
|
|
|
|
assertEquals((fm.date as Date).toISOString().startsWith('2023-02-26'), true)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
Deno.test('validatePost: akzeptiert ISO-string-date', () => {
|
|
|
|
|
const fm = {
|
|
|
|
|
title: 'T',
|
|
|
|
|
slug: 'ok',
|
|
|
|
|
date: '2024-01-15T10:30:00Z',
|
|
|
|
|
} as unknown as Frontmatter
|
|
|
|
|
validatePost(fm)
|
|
|
|
|
assertEquals(fm.date instanceof Date, true)
|
|
|
|
|
})
|