News: Fotos mit Pixelgrenze, sauberer Fehlerzuordnung und mehr Tests

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
knsoandClaude Opus 5.5 committed 2026-09-30 16:40:24 +00:00
1 parent ac7375e889
commit ad0b08f32a
2 files changed
+56 -16

No files matched your search

+33 -10
View File
@@ -7,7 +7,7 @@ import { readFile, writeFile } from 'node:fs/promises'
import sharp from 'sharp'
process.env.NEWS_UPLOAD_DIR = mkdtempSync(path.join(os.tmpdir(), 'news-images-'))
const { storeNewsImage, claimNewsImage, newsImagePath, purgeUnclaimedNewsImages, newsImageRateLimited, NEWS_IMAGE_MAX_BYTES } =
const { storeNewsImage, claimNewsImage, deleteNewsImage, newsImagePath, purgeUnclaimedNewsImages, newsImageRateLimited, NEWS_IMAGE_MAX_BYTES } =
await import('../server/services/newsImages.js')
const solid = (width, height) => sharp({ create: { width, height, channels: 3, background: '#c33' } })
@@ -60,12 +60,12 @@ test('pfad_nur_saubere_ids', () => {
test('unbenutzte_nach_24h_weg', async () => {
const input = await solid(100, 100).png().toBuffer()
const old = await storeNewsImage({ customerId: 'c1', projectId: 'p2', buffer: input })
const kept = await storeNewsImage({ customerId: 'c1', projectId: 'p2', buffer: input })
const fresh = await storeNewsImage({ customerId: 'c1', projectId: 'p2', buffer: input })
await claimNewsImage('p2', kept.imageId)
const old = await storeNewsImage({ customerId: 'c1', projectId: 'p-purge', buffer: input })
const kept = await storeNewsImage({ customerId: 'c1', projectId: 'p-purge', buffer: input })
const fresh = await storeNewsImage({ customerId: 'c1', projectId: 'p-purge', buffer: input })
await claimNewsImage('p-purge', kept.imageId)
const backdate = async (id) => {
const f = path.join(process.env.NEWS_UPLOAD_DIR, 'p2', `${id}.json`)
const f = path.join(process.env.NEWS_UPLOAD_DIR, 'p-purge', `${id}.json`)
const meta = JSON.parse(await readFile(f, 'utf8'))
meta.createdAt = new Date(Date.now() - 25 * 3600 * 1000).toISOString()
await writeFile(f, JSON.stringify(meta))
@@ -73,10 +73,33 @@ test('unbenutzte_nach_24h_weg', async () => {
await backdate(old.imageId)
await backdate(kept.imageId)
assert.equal(await purgeUnclaimedNewsImages(), 1)
assert.equal(existsSync(newsImagePath('p2', old.imageId, 'l')), false)
assert.equal(existsSync(newsImagePath('p2', old.imageId, 's')), false)
assert.equal(existsSync(newsImagePath('p2', kept.imageId, 'l')), true)
assert.equal(existsSync(newsImagePath('p2', fresh.imageId, 'l')), true)
assert.equal(existsSync(newsImagePath('p-purge', old.imageId, 'l')), false)
assert.equal(existsSync(newsImagePath('p-purge', old.imageId, 's')), false)
assert.equal(existsSync(newsImagePath('p-purge', kept.imageId, 'l')), true)
assert.equal(existsSync(newsImagePath('p-purge', fresh.imageId, 'l')), true)
})
test('zu_viele_pixel_415', async () => {
const input = await solid(8000, 8000).png({ compressionLevel: 9 }).toBuffer()
assert.ok(input.length < NEWS_IMAGE_MAX_BYTES)
await assert.rejects(storeNewsImage({ customerId: 'c1', projectId: 'p1', buffer: input }), { status: 415 })
})
test('kaputtes_bild_415', async () => {
const input = (await solid(100, 100).png().toBuffer()).subarray(0, 60)
await assert.rejects(storeNewsImage({ customerId: 'c1', projectId: 'p1', buffer: input }), { status: 415 })
})
test('loeschen_entfernt_dateien_und_sidecar', async () => {
const input = await solid(100, 100).png().toBuffer()
const { imageId } = await storeNewsImage({ customerId: 'c1', projectId: 'p-del', buffer: input })
const sidecar = path.join(process.env.NEWS_UPLOAD_DIR, 'p-del', `${imageId}.json`)
assert.equal(existsSync(sidecar), true)
await deleteNewsImage('p-del', imageId)
assert.equal(existsSync(newsImagePath('p-del', imageId, 'l')), false)
assert.equal(existsSync(newsImagePath('p-del', imageId, 's')), false)
assert.equal(existsSync(sidecar), false)
await deleteNewsImage('p-del', imageId)
})
test('rate_limit_20_pro_stunde', () => {