News: Beiträge – Titel optional, Datumsprüfung, Bildregeln

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
knsoandClaude Opus 5.5 committed 2026-09-30 16:45:42 +00:00
1 parent 434bab0b7a
commit d320730251
2 files changed
+40 -6

No files matched your search

+24
View File
@@ -49,6 +49,8 @@ test('datum_grenzen_400', () => {
assert.throws(() => np.visibleUntilFor('date', NOW, '2026-10-01'), { status: 400, field: 'date' })
assert.throws(() => np.visibleUntilFor('date', NOW, '2027-10-02'), { status: 400 })
assert.throws(() => np.visibleUntilFor('date', NOW, 'morgen'), { status: 400 })
assert.throws(() => np.visibleUntilFor('date', NOW, '2026-11-31'), { status: 400, field: 'date' })
assert.throws(() => np.visibleUntilFor('date', NOW, '2027-02-31'), { status: 400, field: 'date' })
assert.ok(np.visibleUntilFor('date', NOW, '2026-10-02'))
assert.ok(np.visibleUntilFor('date', NOW, '2027-10-01'))
})
@@ -58,6 +60,8 @@ test('validierung', () => {
assert.throws(() => np.validatePostInput({ ...base, type: 'photo' }), { status: 400, field: 'imageId' })
assert.throws(() => np.validatePostInput({ ...base, paper: 'lila' }), { status: 400, field: 'paper' })
assert.throws(() => np.validatePostInput({ ...base, text: '' }), { status: 400, field: 'text' })
assert.equal(np.validatePostInput({ ...base, title: undefined }).title, '')
assert.equal(np.validatePostInput({ ...base, type: 'photo', title: '', text: '', imageId: 'i1' }).title, '')
assert.throws(() => np.validatePostInput({ ...base, text: 'x'.repeat(401) }), { status: 400, field: 'text' })
assert.throws(() => np.validatePostInput({ ...base, type: 'combo', imageId: 'i1', text: '' }), { status: 400, field: 'text' })
assert.equal(np.validatePostInput({ ...base, type: 'photo', text: '', imageId: 'i1' }).imageId, 'i1')
@@ -118,3 +122,23 @@ test('bild_gehoert_zum_projekt_und_wird_mitgeloescht', async () => {
assert.equal(existsSync(newsImagePath('pd', b.imageId, 'l')), false)
assert.equal((await np.listPosts('pd', NOW)).hanging.length, 0)
})
test('bearbeiten_datum_bild_regeln', async () => {
const post = await mk('pf', { duration: 'date', date: '2026-10-10' })
const edit = (input, now) => np.updatePost({ customerId: 'c1', projectId: 'pf', id: post.$id, input: { ...base, duration: 'date', ...input }, now })
const late = new Date('2026-10-10T08:00:00.000Z')
// unveraendertes Datum (heute) bleibt speicherbar, geaendertes wird geprueft
const ok = await edit({ date: '2026-10-10', title: 'Neu' }, late)
assert.equal(ok.title, 'Neu')
assert.equal(ok.visibleUntil, post.visibleUntil)
await assert.rejects(edit({ date: '2026-10-11' }, new Date('2026-10-11T08:00:00.000Z')), { status: 400, field: 'date' })
// Bild eines anderen Beitrags
const img = await storeNewsImage({ customerId: 'c1', projectId: 'pf', buffer: await png() })
await mk('pf', { type: 'photo', imageId: img.imageId })
await assert.rejects(edit({ type: 'photo', imageId: img.imageId, date: '2026-10-10' }, late), { status: 400, field: 'imageId' })
})
test('create_ohne_bild_belegt_nichts', async () => {
await assert.rejects(mk('pg', { type: 'photo', imageId: 'nope' }), { status: 400, field: 'imageId' })
assert.equal((await np.listPosts('pg', NOW)).hanging.length, 0)
})