Files
logbuch/tests/lib/publish-due.test.ts
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

59 lines
2.3 KiB
TypeScript

import { beforeEach, describe, expect, it } from 'vitest'
import { findEntry } from '~/data/repositories/entries'
import { publishDueEntries } from '~/lib/publish-due'
import { auditEntries, makeBrand, makeProject, resetAccounts } from '../support/admin'
import { makePost } from '../support/entries'
beforeEach(resetAccounts)
const past = new Date('2026-07-30T06:00:00Z')
const future = new Date('2026-08-30T06:00:00Z')
const now = new Date('2026-07-30T08:00:00Z')
describe('publishDueEntries', () => {
it('veröffentlicht nur fällige terminierte Beiträge', async () => {
const brand = await makeBrand()
const project = await makeProject(brand.id)
const due = await makePost(project.id, { number: 1, slug: 'faellig', status: 'scheduled', publishAt: past })
const later = await makePost(project.id, { number: 2, slug: 'spaeter', status: 'scheduled', publishAt: future })
const draft = await makePost(project.id, { number: 3, slug: 'entwurf', status: 'draft', publishAt: past })
const result = await publishDueEntries(now)
expect(result.published.map(entry => entry.slug)).toEqual(['faellig'])
expect((await findEntry(due.id))?.status).toBe('published')
expect((await findEntry(later.id))?.status).toBe('scheduled')
expect((await findEntry(draft.id))?.status).toBe('draft')
})
it('behält den geplanten Zeitpunkt und schreibt ins Protokoll', async () => {
const brand = await makeBrand()
const project = await makeProject(brand.id)
const due = await makePost(project.id, { number: 1, slug: 'faellig', status: 'scheduled', publishAt: past })
await publishDueEntries(now)
const saved = await findEntry(due.id)
const entries = await auditEntries()
expect(saved?.publishAt?.toISOString()).toBe(past.toISOString())
expect(entries[0]).toMatchObject({ action: 'post.publish.due', entityId: due.id, actorType: 'client' })
})
it('veröffentlicht bei einem zweiten Lauf nichts noch einmal', async () => {
const brand = await makeBrand()
const project = await makeProject(brand.id)
await makePost(project.id, { number: 1, slug: 'faellig', status: 'scheduled', publishAt: past })
const first = await publishDueEntries(now)
const second = await publishDueEntries(now)
expect(first.published).toHaveLength(1)
expect(second.published).toHaveLength(0)
})
})