Files
logbuch/tests/support/entries.ts
T
Matthias Giesselmann b90ff252d1 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.
2026-07-31 21:33:42 +02:00

50 lines
1.3 KiB
TypeScript

import { randomUUID } from 'node:crypto'
import { db } from '~/data/db'
import { media, posts, type Media, type Post } from '~/data/schema'
import { postTypeId } from './post-types'
import type { EntryInput } from '~/lib/entry-types'
export async function makeMedia(projectId: string, alt: string | null = 'Ein Bild'): Promise<Media> {
const id = randomUUID()
const rows = await db.insert(media).values({
id,
projectId,
kind: 'image',
originalFilename: 'bild.png',
path: `${projectId}/${id}/original.png`,
mime: 'image/png',
width: 1200,
height: 800,
byteSize: 2048,
variants: [],
alt,
}).returning()
return rows[0]!
}
export async function makePost(projectId: string, values: Partial<typeof posts.$inferInsert> = {}): Promise<Post> {
const rows = await db.insert(posts).values({
projectId,
number: 1,
slug: 'ein-beitrag',
title: 'Ein Beitrag',
...values,
}).returning()
return rows[0]!
}
export function entryInput(projectId: string, overrides: Partial<EntryInput> = {}): EntryInput {
return {
projectId,
title: 'Regel-Engine',
teaser: 'Bedingung trifft Aktion.',
typeId: postTypeId('feature'),
audience: 'internal',
coverMediaId: null,
blocks: [{ type: 'text', data: { text: 'Der Worker prüft jede Bedingung.' } }],
...overrides,
}
}