Add Logbuch: project update blog with admin, media and API
Public archive with sidebar navigation, project pages, month archive, search and entry pages with image blocks. Admin area for brands, projects, post types, users, api clients, media and the entry editor with drag and drop images, preview per audience, scheduling and publish checks. Read and write API with bearer tokens, audience scoping, idempotent creation, OpenAPI document and editorial guide. Magic link login with configurable allowed domains, whole app behind the session gate. 456 tests including design rule checks.
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { isOpenPath, loginTarget, requiresSession } from '~/domain/access-paths'
|
||||
|
||||
describe('isOpenPath', () => {
|
||||
const open = [
|
||||
'/login',
|
||||
'/api/auth/sign-in/email',
|
||||
'/api/auth/callback/magic-link',
|
||||
'/api/v1/posts',
|
||||
'/api/v1/media/file/2026/07/bild.webp',
|
||||
'/_next/static/chunks/main.js',
|
||||
'/favicon.ico',
|
||||
'/robots.txt',
|
||||
]
|
||||
|
||||
for (const path of open) {
|
||||
it(`lässt ${path} ohne Anmeldung durch`, () => {
|
||||
expect(isOpenPath(path)).toBe(true)
|
||||
})
|
||||
}
|
||||
|
||||
const closed = ['/', '/trakk', '/trakk/2026/07', '/trakk/ein-beitrag', '/search', '/admin', '/admin/entries/new']
|
||||
|
||||
for (const path of closed) {
|
||||
it(`verlangt für ${path} eine Anmeldung`, () => {
|
||||
expect(requiresSession(path)).toBe(true)
|
||||
})
|
||||
}
|
||||
|
||||
it('lässt sich nicht durch einen ähnlichen Anfang austricksen', () => {
|
||||
expect(isOpenPath('/loginversuch')).toBe(false)
|
||||
expect(isOpenPath('/api/v1x/posts')).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('loginTarget', () => {
|
||||
it('merkt sich das gewünschte Ziel', () => {
|
||||
expect(loginTarget('/trakk/ein-beitrag', '')).toBe('/login?next=%2Ftrakk%2Fein-beitrag')
|
||||
})
|
||||
|
||||
it('nimmt die Abfrageparameter mit', () => {
|
||||
expect(loginTarget('/search', '?q=regel')).toBe('/login?next=%2Fsearch%3Fq%3Dregel')
|
||||
})
|
||||
|
||||
it('lässt die Startseite ohne Ziel', () => {
|
||||
expect(loginTarget('/', '')).toBe('/login')
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,57 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { canAssignAudience, canSee, visibleAudiences } from '~/domain/audience'
|
||||
import type { Audience, ViewerScope } from '~/domain/types'
|
||||
|
||||
const cases: [ViewerScope, Audience, boolean][] = [
|
||||
['internal', 'internal', true],
|
||||
['internal', 'customer', true],
|
||||
['internal', 'public', true],
|
||||
['customer', 'internal', false],
|
||||
['customer', 'customer', true],
|
||||
['customer', 'public', true],
|
||||
['public', 'internal', false],
|
||||
['public', 'customer', false],
|
||||
['public', 'public', true],
|
||||
]
|
||||
|
||||
describe('canSee', () => {
|
||||
for (const [scope, audience, expected] of cases) {
|
||||
it(`${scope} sieht ${audience}: ${expected}`, () => {
|
||||
expect(canSee(scope, audience)).toBe(expected)
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
describe('visibleAudiences', () => {
|
||||
it('gibt für intern alle Zielgruppen zurück', () => {
|
||||
expect(visibleAudiences('internal').sort()).toEqual(['customer', 'internal', 'public'])
|
||||
})
|
||||
|
||||
it('gibt für Kunden keine internen Beiträge zurück', () => {
|
||||
expect(visibleAudiences('customer').sort()).toEqual(['customer', 'public'])
|
||||
})
|
||||
|
||||
it('gibt öffentlich nur öffentliche Beiträge zurück', () => {
|
||||
expect(visibleAudiences('public')).toEqual(['public'])
|
||||
})
|
||||
})
|
||||
|
||||
describe('canAssignAudience', () => {
|
||||
const cases: [ViewerScope, Audience, boolean][] = [
|
||||
['internal', 'internal', true],
|
||||
['internal', 'customer', false],
|
||||
['internal', 'public', false],
|
||||
['customer', 'internal', true],
|
||||
['customer', 'customer', true],
|
||||
['customer', 'public', false],
|
||||
['public', 'internal', true],
|
||||
['public', 'customer', true],
|
||||
['public', 'public', true],
|
||||
]
|
||||
|
||||
for (const [scope, audience, expected] of cases) {
|
||||
it(`${scope} darf ${audience} setzen: ${expected}`, () => {
|
||||
expect(canAssignAudience(scope, audience)).toBe(expected)
|
||||
})
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,74 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { blockMediaIds, emptyBlockData, isBlockEmpty, isBlockType, parseBlocks } from '~/domain/blocks'
|
||||
|
||||
const id = '11111111-1111-4111-8111-111111111111'
|
||||
|
||||
describe('parseBlocks', () => {
|
||||
it('nimmt alle Blocktypen in Reihenfolge an', async () => {
|
||||
const result = parseBlocks([
|
||||
{ type: 'text', data: { text: 'Hallo' } },
|
||||
{ type: 'image', data: { mediaId: id } },
|
||||
{ type: 'gallery', data: { mediaIds: [id] } },
|
||||
{ type: 'before_after', data: { beforeMediaId: id, afterMediaId: id } },
|
||||
{ type: 'video', data: { url: 'https://nyo.de/film.mp4' } },
|
||||
{ type: 'quote', data: { text: 'Kurz', source: 'Paul' } },
|
||||
{ type: 'code', data: { code: 'const a = 1', language: 'ts' } },
|
||||
{ type: 'link', data: { url: 'https://nyo.de', label: 'NYO' } },
|
||||
{ type: 'callout', data: { text: 'Achtung', tone: 'warning' } },
|
||||
])
|
||||
|
||||
expect(result.ok).toBe(true)
|
||||
expect(result.ok && result.blocks.map(block => block.type)).toEqual([
|
||||
'text',
|
||||
'image',
|
||||
'gallery',
|
||||
'before_after',
|
||||
'video',
|
||||
'quote',
|
||||
'code',
|
||||
'link',
|
||||
'callout',
|
||||
])
|
||||
})
|
||||
|
||||
it('füllt fehlende Felder mit leeren Werten', () => {
|
||||
const result = parseBlocks([{ type: 'callout', data: {} }])
|
||||
|
||||
expect(result.ok && result.blocks[0]?.data).toEqual({ title: '', text: '', tone: 'info' })
|
||||
})
|
||||
|
||||
it('meldet einen unbekannten Blocktyp mit Position', () => {
|
||||
const result = parseBlocks([{ type: 'text', data: { text: 'Hallo' } }, { type: 'karussell', data: {} }])
|
||||
|
||||
expect(result).toMatchObject({ ok: false, index: 1, type: 'karussell' })
|
||||
})
|
||||
|
||||
it('lehnt eine kaputte Adresse und eine kaputte Bildkennung ab', () => {
|
||||
expect(parseBlocks([{ type: 'link', data: { url: 'kein-verweis' } }]).ok).toBe(false)
|
||||
expect(parseBlocks([{ type: 'image', data: { mediaId: 'abc' } }]).ok).toBe(false)
|
||||
})
|
||||
|
||||
it('nimmt eine leere Bildkennung an', () => {
|
||||
expect(parseBlocks([{ type: 'image', data: { mediaId: '' } }]).ok).toBe(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('Blockhilfen', () => {
|
||||
it('sammelt alle Bildkennungen eines Blocks', () => {
|
||||
expect(blockMediaIds({ type: 'gallery', data: { mediaIds: [id, ''] } })).toEqual([id])
|
||||
expect(blockMediaIds({ type: 'before_after', data: { beforeMediaId: id, afterMediaId: '' } })).toEqual([id])
|
||||
})
|
||||
|
||||
it('erkennt leere Blöcke', () => {
|
||||
expect(isBlockEmpty({ type: 'text', data: emptyBlockData('text') })).toBe(true)
|
||||
expect(isBlockEmpty({ type: 'text', data: { text: ' ' } })).toBe(true)
|
||||
expect(isBlockEmpty({ type: 'text', data: { text: 'Inhalt' } })).toBe(false)
|
||||
expect(isBlockEmpty({ type: 'callout', data: emptyBlockData('callout') })).toBe(true)
|
||||
expect(isBlockEmpty({ type: 'image', data: { mediaId: id } })).toBe(false)
|
||||
})
|
||||
|
||||
it('kennt die erlaubten Typen', () => {
|
||||
expect(isBlockType('text')).toBe(true)
|
||||
expect(isBlockType('karussell')).toBe(false)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,23 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { isColor, normalizeColor } from '~/domain/color'
|
||||
|
||||
describe('normalizeColor', () => {
|
||||
it('ergänzt das Rautezeichen', () => {
|
||||
expect(normalizeColor('2E7D5B')).toBe('#2e7d5b')
|
||||
})
|
||||
|
||||
it('schreibt eine Kurzform aus', () => {
|
||||
expect(normalizeColor('#abc')).toBe('#aabbcc')
|
||||
})
|
||||
})
|
||||
|
||||
describe('isColor', () => {
|
||||
it('nimmt sechsstellige Hexwerte an', () => {
|
||||
expect(isColor('#2e7d5b')).toBe(true)
|
||||
})
|
||||
|
||||
it('lehnt alles andere ab', () => {
|
||||
expect(isColor('rot')).toBe(false)
|
||||
expect(isColor('#2e7d5')).toBe(false)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,65 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { emailDomain, isAllowedDomain, normaliseEmail, parseDomains } from '~/domain/email-domains'
|
||||
|
||||
const domains = parseDomains('nyo.de, pocketrocket.de,pocket-rocket.io')
|
||||
|
||||
describe('parseDomains', () => {
|
||||
it('trennt an Kommas, schneidet Leerraum und macht klein', () => {
|
||||
expect(parseDomains(' NYO.de , Pocket-Rocket.io ')).toEqual(['nyo.de', 'pocket-rocket.io'])
|
||||
})
|
||||
|
||||
it('entfernt ein führendes At-Zeichen', () => {
|
||||
expect(parseDomains('@nyo.de')).toEqual(['nyo.de'])
|
||||
})
|
||||
|
||||
it('liefert für leere Angaben eine leere Liste', () => {
|
||||
expect(parseDomains(undefined)).toEqual([])
|
||||
expect(parseDomains(' , ')).toEqual([])
|
||||
})
|
||||
})
|
||||
|
||||
describe('emailDomain', () => {
|
||||
it('liest die Domain hinter dem letzten At-Zeichen', () => {
|
||||
expect(emailDomain('Vorname.Nachname@NYO.de')).toBe('nyo.de')
|
||||
})
|
||||
|
||||
it('liefert für eine Adresse ohne At-Zeichen nichts', () => {
|
||||
expect(emailDomain('keine-adresse')).toBe('')
|
||||
})
|
||||
})
|
||||
|
||||
describe('isAllowedDomain', () => {
|
||||
it('lässt die freigegebenen Domains durch', () => {
|
||||
expect(isAllowedDomain('paul@nyo.de', domains)).toBe(true)
|
||||
expect(isAllowedDomain('paul@pocketrocket.de', domains)).toBe(true)
|
||||
expect(isAllowedDomain('paul@pocket-rocket.io', domains)).toBe(true)
|
||||
})
|
||||
|
||||
it('lässt Unterdomains der freigegebenen Domains durch', () => {
|
||||
expect(isAllowedDomain('paul@mail.nyo.de', domains)).toBe(true)
|
||||
})
|
||||
|
||||
it('weist fremde Domains ab', () => {
|
||||
expect(isAllowedDomain('paul@gmail.com', domains)).toBe(false)
|
||||
expect(isAllowedDomain('paul@nyo.de.angreifer.example', domains)).toBe(false)
|
||||
expect(isAllowedDomain('paul@xnyo.de', domains)).toBe(false)
|
||||
})
|
||||
|
||||
it('weist Eingaben ohne Domain ab', () => {
|
||||
expect(isAllowedDomain('paul', domains)).toBe(false)
|
||||
})
|
||||
|
||||
it('lässt ohne konfigurierte Liste alles durch', () => {
|
||||
expect(isAllowedDomain('paul@gmail.com', [])).toBe(true)
|
||||
})
|
||||
|
||||
it('ist unabhängig von Gross- und Kleinschreibung', () => {
|
||||
expect(isAllowedDomain('Paul@NYO.DE', domains)).toBe(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('normaliseEmail', () => {
|
||||
it('schneidet Leerraum und macht klein', () => {
|
||||
expect(normaliseEmail(' Paul@NYO.de ')).toBe('paul@nyo.de')
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,142 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { parseDomains } from '~/domain/email-domains'
|
||||
import {
|
||||
attemptsWithinWindow,
|
||||
decideMagicLinkRequest,
|
||||
magicLinkMaxAttempts,
|
||||
magicLinkResponse,
|
||||
type MagicLinkRequest,
|
||||
} from '~/domain/magic-link'
|
||||
|
||||
const domains = parseDomains('nyo.de,pocketrocket.de,pocket-rocket.io')
|
||||
|
||||
function request(overrides: Partial<MagicLinkRequest> = {}): MagicLinkRequest {
|
||||
return {
|
||||
email: 'paul@nyo.de',
|
||||
allowedDomains: domains,
|
||||
hasAccount: false,
|
||||
attempts: 1,
|
||||
...overrides,
|
||||
}
|
||||
}
|
||||
|
||||
describe('decideMagicLinkRequest', () => {
|
||||
it('schickt einen Link an jede freigegebene Domain, auch ohne Konto', () => {
|
||||
for (const email of ['paul@nyo.de', 'paul@pocketrocket.de', 'paul@pocket-rocket.io']) {
|
||||
expect(decideMagicLinkRequest(request({ email }))).toEqual({
|
||||
email,
|
||||
outcome: 'send',
|
||||
reason: 'allowed-domain',
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
it('schickt einen Link an ein bestehendes Konto mit fremder Domain', () => {
|
||||
expect(decideMagicLinkRequest(request({ email: 'thevisualdesigners@gmail.com', hasAccount: true })))
|
||||
.toEqual({
|
||||
email: 'thevisualdesigners@gmail.com',
|
||||
outcome: 'send',
|
||||
reason: 'known-account',
|
||||
})
|
||||
})
|
||||
|
||||
it('schickt keinen Link an eine fremde Domain ohne Konto', () => {
|
||||
expect(decideMagicLinkRequest(request({ email: 'fremd@example.com' }))).toEqual({
|
||||
email: 'fremd@example.com',
|
||||
outcome: 'ignore',
|
||||
reason: 'domain-not-allowed',
|
||||
})
|
||||
})
|
||||
|
||||
it('lässt sich nicht durch eine angehängte Domain täuschen', () => {
|
||||
expect(decideMagicLinkRequest(request({ email: 'paul@nyo.de.angreifer.example' })).outcome).toBe('ignore')
|
||||
})
|
||||
|
||||
it('behandelt Groß- und Kleinschreibung und Leerraum gleich', () => {
|
||||
expect(decideMagicLinkRequest(request({ email: ' Paul@NYO.de ' }))).toEqual({
|
||||
email: 'paul@nyo.de',
|
||||
outcome: 'send',
|
||||
reason: 'allowed-domain',
|
||||
})
|
||||
})
|
||||
|
||||
it('erlaubt genau fünf Anforderungen im Zeitfenster', () => {
|
||||
expect(decideMagicLinkRequest(request({ attempts: magicLinkMaxAttempts })).outcome).toBe('send')
|
||||
expect(decideMagicLinkRequest(request({ attempts: magicLinkMaxAttempts + 1 }))).toEqual({
|
||||
email: 'paul@nyo.de',
|
||||
outcome: 'throttle',
|
||||
reason: 'too-many-requests',
|
||||
})
|
||||
})
|
||||
|
||||
it('bremst jede Adresse, auch die abgewiesene', () => {
|
||||
const decision = decideMagicLinkRequest(request({ email: 'fremd@example.com', attempts: 6 }))
|
||||
|
||||
expect(decision.outcome).toBe('throttle')
|
||||
})
|
||||
|
||||
it('bremst auch ein bestehendes Konto', () => {
|
||||
const decision = decideMagicLinkRequest(request({
|
||||
email: 'thevisualdesigners@gmail.com',
|
||||
hasAccount: true,
|
||||
attempts: 6,
|
||||
}))
|
||||
|
||||
expect(decision.outcome).toBe('throttle')
|
||||
})
|
||||
})
|
||||
|
||||
describe('magicLinkResponse', () => {
|
||||
it('antwortet gleich, egal ob ein Link rausgeht oder nicht', () => {
|
||||
const sent = magicLinkResponse(decideMagicLinkRequest(request({ email: 'paul@nyo.de' })))
|
||||
const known = magicLinkResponse(decideMagicLinkRequest(request({
|
||||
email: 'paul@nyo.de',
|
||||
allowedDomains: parseDomains('example.org'),
|
||||
hasAccount: true,
|
||||
})))
|
||||
const ignored = magicLinkResponse(decideMagicLinkRequest(request({
|
||||
email: 'paul@nyo.de',
|
||||
allowedDomains: parseDomains('example.org'),
|
||||
})))
|
||||
|
||||
expect(sent).toEqual({ status: 'sent', email: 'paul@nyo.de' })
|
||||
expect(known).toEqual(sent)
|
||||
expect(ignored).toEqual(sent)
|
||||
})
|
||||
|
||||
it('verrät auch bei fremder Adresse nichts über das Konto', () => {
|
||||
const withAccount = magicLinkResponse(decideMagicLinkRequest(request({
|
||||
email: 'fremd@example.com',
|
||||
hasAccount: true,
|
||||
})))
|
||||
const withoutAccount = magicLinkResponse(decideMagicLinkRequest(request({
|
||||
email: 'fremd@example.com',
|
||||
hasAccount: false,
|
||||
})))
|
||||
|
||||
expect(withAccount).toEqual(withoutAccount)
|
||||
})
|
||||
|
||||
it('meldet nur die Bremse offen', () => {
|
||||
expect(magicLinkResponse(decideMagicLinkRequest(request({ attempts: 6 })))).toEqual({
|
||||
status: 'error',
|
||||
email: 'paul@nyo.de',
|
||||
error: 'tooMany',
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('attemptsWithinWindow', () => {
|
||||
it('behält nur die Zeitpunkte im Fenster', () => {
|
||||
const now = 1_000_000
|
||||
|
||||
expect(attemptsWithinWindow([now - 1000, now - 900_000, now - 100], now, 900_000)).toEqual([
|
||||
now - 1000,
|
||||
now - 100,
|
||||
])
|
||||
})
|
||||
|
||||
it('liefert für eine leere Liste nichts', () => {
|
||||
expect(attemptsWithinWindow([], 10, 900_000)).toEqual([])
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,49 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { canTransition } from '~/domain/post-status'
|
||||
import type { PostStatus } from '~/domain/types'
|
||||
|
||||
describe('canTransition', () => {
|
||||
it('erlaubt den Weg vom Entwurf bis zur Veröffentlichung', () => {
|
||||
expect(canTransition('draft', 'review')).toBe(true)
|
||||
expect(canTransition('review', 'published')).toBe(true)
|
||||
expect(canTransition('draft', 'published')).toBe(true)
|
||||
expect(canTransition('draft', 'scheduled')).toBe(true)
|
||||
expect(canTransition('scheduled', 'published')).toBe(true)
|
||||
})
|
||||
|
||||
it('erlaubt Zurückziehen und Wiederaufnahme', () => {
|
||||
expect(canTransition('published', 'archived')).toBe(true)
|
||||
expect(canTransition('archived', 'draft')).toBe(true)
|
||||
})
|
||||
|
||||
it('verbietet Sprünge zurück aus der Veröffentlichung in den Entwurf', () => {
|
||||
expect(canTransition('published', 'draft')).toBe(false)
|
||||
expect(canTransition('published', 'review')).toBe(false)
|
||||
})
|
||||
|
||||
it('verbietet gleichbleibenden Status als Übergang', () => {
|
||||
expect(canTransition('draft', 'draft')).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('canTransition deckt alle 25 Paare ab', () => {
|
||||
const states: PostStatus[] = ['draft', 'review', 'scheduled', 'published', 'archived']
|
||||
|
||||
const expected: Record<PostStatus, PostStatus[]> = {
|
||||
draft: ['review', 'scheduled', 'published', 'archived'],
|
||||
review: ['draft', 'scheduled', 'published', 'archived'],
|
||||
scheduled: ['draft', 'published', 'archived'],
|
||||
published: ['archived'],
|
||||
archived: ['draft'],
|
||||
}
|
||||
|
||||
for (const from of states) {
|
||||
for (const to of states) {
|
||||
const allowed = expected[from].includes(to)
|
||||
|
||||
it(`${from} nach ${to}: ${allowed}`, () => {
|
||||
expect(canTransition(from, to)).toBe(allowed)
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,127 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { projectCode } from '~/domain/project-code'
|
||||
|
||||
describe('projectCode mit gesetztem Kürzel', () => {
|
||||
it('nimmt das gesetzte Kürzel und schreibt es groß', () => {
|
||||
expect(projectCode({ code: 'trk', slug: 'trakk' })).toBe('TRK')
|
||||
})
|
||||
|
||||
it('sticht die Ableitung aus dem Slug aus', () => {
|
||||
expect(projectCode({ code: 'TEL', slug: 'mta-telematik' })).toBe('TEL')
|
||||
})
|
||||
|
||||
it('schneidet nach vier Zeichen ab', () => {
|
||||
expect(projectCode({ code: 'orbitalis', slug: 'orbit' })).toBe('ORBI')
|
||||
})
|
||||
|
||||
it('entfernt Leerraum und Sonderzeichen im Kürzel', () => {
|
||||
expect(projectCode({ code: ' p-l s ', slug: 'pulsar' })).toBe('PLS')
|
||||
})
|
||||
})
|
||||
|
||||
describe('projectCode mit fehlendem Kürzel', () => {
|
||||
it('fällt bei leerem Kürzel auf die Ableitung zurück', () => {
|
||||
expect(projectCode({ code: '', slug: 'trakk' })).toBe('TRA')
|
||||
})
|
||||
|
||||
it('fällt bei Leerraum als Kürzel auf die Ableitung zurück', () => {
|
||||
expect(projectCode({ code: ' ', slug: 'trakk' })).toBe('TRA')
|
||||
})
|
||||
|
||||
it('fällt bei null auf die Ableitung zurück', () => {
|
||||
expect(projectCode({ code: null, slug: 'trakk' })).toBe('TRA')
|
||||
})
|
||||
|
||||
it('fällt ohne Feld auf die Ableitung zurück', () => {
|
||||
expect(projectCode({ slug: 'mta360' })).toBe('MTA')
|
||||
})
|
||||
|
||||
it('fällt bei einem einzelnen Zeichen als Kürzel auf die Ableitung zurück', () => {
|
||||
expect(projectCode({ code: 'x', slug: 'pulsar' })).toBe('PUL')
|
||||
})
|
||||
})
|
||||
|
||||
describe('projectCode leitet aus dem Slug ab', () => {
|
||||
it('nimmt bei einem Wort die ersten drei Zeichen', () => {
|
||||
expect(projectCode({ slug: 'orbit' })).toBe('ORB')
|
||||
})
|
||||
|
||||
it('zählt Ziffern als Teil des Wortes', () => {
|
||||
expect(projectCode({ slug: 'mta360' })).toBe('MTA')
|
||||
})
|
||||
|
||||
it('füllt bei zwei Wörtern die Initialen auf drei Zeichen auf', () => {
|
||||
expect(projectCode({ slug: 'mta-telematik' })).toBe('MTE')
|
||||
})
|
||||
|
||||
it('nimmt bei drei Wörtern je den ersten Buchstaben', () => {
|
||||
expect(projectCode({ slug: 'pocket-rocket-labs' })).toBe('PRL')
|
||||
})
|
||||
|
||||
it('bleibt bei vier Wörtern bei drei Zeichen', () => {
|
||||
expect(projectCode({ slug: 'ein-eingang-fuer-alle' })).toBe('EEF')
|
||||
})
|
||||
|
||||
it('behandelt jedes nicht alphanumerische Zeichen als Worttrenner', () => {
|
||||
expect(projectCode({ slug: 'mta_360.pilot' })).toBe('M3P')
|
||||
})
|
||||
|
||||
it('ignoriert führende und mehrfache Trenner', () => {
|
||||
expect(projectCode({ slug: '--trakk--' })).toBe('TRA')
|
||||
})
|
||||
})
|
||||
|
||||
describe('projectCode mit Sonderzeichen und Umlauten', () => {
|
||||
it('bricht bei Umlauten nicht und schreibt sie als Grundbuchstaben', () => {
|
||||
expect(projectCode({ slug: 'übung' })).toBe('UBU')
|
||||
})
|
||||
|
||||
it('trennt an Umlautwörtern korrekt', () => {
|
||||
expect(projectCode({ slug: 'grüne-wiese' })).toBe('GWI')
|
||||
})
|
||||
|
||||
it('löst ß in SS auf', () => {
|
||||
expect(projectCode({ slug: 'straße' })).toBe('STR')
|
||||
})
|
||||
|
||||
it('nimmt Umlaute auch im gesetzten Kürzel an', () => {
|
||||
expect(projectCode({ code: 'öl', slug: 'orbit' })).toBe('OL')
|
||||
})
|
||||
|
||||
it('bricht bei Zeichen ohne Entsprechung nicht', () => {
|
||||
expect(projectCode({ slug: '★★★' })).toBe('LOG')
|
||||
})
|
||||
|
||||
it('bricht bei einem leeren Slug nicht', () => {
|
||||
expect(projectCode({ code: '', slug: '' })).toBe('LOG')
|
||||
})
|
||||
})
|
||||
|
||||
describe('projectCode leitet nie weniger als drei Zeichen ab', () => {
|
||||
const slugs = [
|
||||
'trakk',
|
||||
'mta360',
|
||||
'mta-telematik',
|
||||
'orbit',
|
||||
'pulsar',
|
||||
'a',
|
||||
'a-b',
|
||||
'',
|
||||
'★',
|
||||
'ein-sehr-langer-projekt-slug-mit-vielen-woertern',
|
||||
]
|
||||
|
||||
for (const slug of slugs) {
|
||||
it(`liefert für "${slug}" drei bis vier Großbuchstaben`, () => {
|
||||
const result = projectCode({ slug })
|
||||
|
||||
expect(result.length).toBeGreaterThanOrEqual(3)
|
||||
expect(result.length).toBeLessThanOrEqual(4)
|
||||
expect(result).toBe(result.toUpperCase())
|
||||
})
|
||||
}
|
||||
|
||||
it('füllt ein einzelnes ableitbares Zeichen auf drei Zeichen auf', () => {
|
||||
expect(projectCode({ slug: 'a' })).toBe('AAA')
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,71 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { checkPublish } from '~/domain/publish-checks'
|
||||
|
||||
const base = {
|
||||
title: 'Regel-Engine: Bedingung trifft Aktion',
|
||||
audience: 'internal' as const,
|
||||
blockCount: 3,
|
||||
images: [{ hasAlt: true }],
|
||||
tagCount: 1,
|
||||
hasCover: true,
|
||||
}
|
||||
|
||||
describe('checkPublish', () => {
|
||||
it('lässt einen vollständigen Beitrag ohne Sperre und ohne Hinweis durch', () => {
|
||||
expect(checkPublish(base)).toEqual({ blockers: [], hints: [] })
|
||||
})
|
||||
|
||||
it('sperrt einen Beitrag ohne Titel', () => {
|
||||
expect(checkPublish({ ...base, title: ' ' }).blockers).toContain('title_missing')
|
||||
})
|
||||
|
||||
it('sperrt einen leeren Beitrag', () => {
|
||||
expect(checkPublish({ ...base, blockCount: 0 }).blockers).toContain('content_empty')
|
||||
})
|
||||
|
||||
it('sperrt einen öffentlichen Beitrag mit Bild ohne Alt-Text', () => {
|
||||
const result = checkPublish({ ...base, audience: 'public', images: [{ hasAlt: false }] })
|
||||
expect(result.blockers).toContain('alt_text_missing')
|
||||
})
|
||||
|
||||
it('meldet fehlenden Alt-Text bei internen Beiträgen nur als Hinweis', () => {
|
||||
const result = checkPublish({ ...base, images: [{ hasAlt: false }] })
|
||||
expect(result.blockers).toEqual([])
|
||||
expect(result.hints).toContain('alt_text_missing')
|
||||
})
|
||||
|
||||
it('meldet fehlende Schlagworte und fehlendes Aufmacherbild als Hinweis', () => {
|
||||
const result = checkPublish({ ...base, tagCount: 0, hasCover: false })
|
||||
expect(result.blockers).toEqual([])
|
||||
expect(result.hints).toEqual(expect.arrayContaining(['tags_missing', 'cover_missing']))
|
||||
})
|
||||
|
||||
it('meldet fehlenden Alt-Text bei Kundenbeiträgen nur als Hinweis', () => {
|
||||
const result = checkPublish({ ...base, audience: 'customer', images: [{ hasAlt: false }] })
|
||||
|
||||
expect(result.blockers).toEqual([])
|
||||
expect(result.hints).toContain('alt_text_missing')
|
||||
})
|
||||
|
||||
it('sperrt einen öffentlichen Beitrag, wenn nur eines von mehreren Bildern keinen Alt-Text hat', () => {
|
||||
const result = checkPublish({
|
||||
...base,
|
||||
audience: 'public',
|
||||
images: [{ hasAlt: true }, { hasAlt: false }, { hasAlt: true }],
|
||||
})
|
||||
|
||||
expect(result.blockers).toContain('alt_text_missing')
|
||||
})
|
||||
|
||||
it('meldet mehrere Sperrgründe gleichzeitig', () => {
|
||||
const result = checkPublish({ ...base, title: '', blockCount: 0 })
|
||||
|
||||
expect(result.blockers).toEqual(expect.arrayContaining(['title_missing', 'content_empty']))
|
||||
})
|
||||
|
||||
it('sperrt einen Beitrag ohne Bilder nicht', () => {
|
||||
const result = checkPublish({ ...base, audience: 'public', images: [] })
|
||||
|
||||
expect(result.blockers).toEqual([])
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,39 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { isSlug, slugify } from '~/domain/slug'
|
||||
|
||||
describe('slugify', () => {
|
||||
it('macht aus einem Namen einen Slug', () => {
|
||||
expect(slugify('MTA Telematik')).toBe('mta-telematik')
|
||||
})
|
||||
|
||||
it('schreibt Umlaute aus', () => {
|
||||
expect(slugify('Größe und Öl')).toBe('groesse-und-oel')
|
||||
})
|
||||
|
||||
it('wirft Sonderzeichen weg und lässt keine Bindestriche am Rand', () => {
|
||||
expect(slugify(' Trakk / Regel-Engine! ')).toBe('trakk-regel-engine')
|
||||
})
|
||||
|
||||
it('liefert eine leere Zeichenkette, wenn nichts Verwertbares übrig bleibt', () => {
|
||||
expect(slugify('///')).toBe('')
|
||||
})
|
||||
})
|
||||
|
||||
describe('isSlug', () => {
|
||||
it('nimmt Kleinbuchstaben, Ziffern und Bindestriche an', () => {
|
||||
expect(isSlug('mta-360')).toBe(true)
|
||||
})
|
||||
|
||||
it('lehnt Großbuchstaben ab', () => {
|
||||
expect(isSlug('Trakk')).toBe(false)
|
||||
})
|
||||
|
||||
it('lehnt führende und doppelte Bindestriche ab', () => {
|
||||
expect(isSlug('-trakk')).toBe(false)
|
||||
expect(isSlug('trakk--web')).toBe(false)
|
||||
})
|
||||
|
||||
it('lehnt einen zu kurzen Slug ab', () => {
|
||||
expect(isSlug('a')).toBe(false)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user