Only send what is new, and lead with a picture

The window now starts at the last dispatch, so pressing send twice does not
repeat a digest. Cards prefer entries that have a cover, the newest one of
them opens the message as a full width image, and the page says when the
last digest went out.
This commit is contained in:
Matthias G
2026-08-03 13:24:46 +02:00
parent 78ff7d2c3f
commit c1cfd41ad3
8 changed files with 133 additions and 16 deletions
+22
View File
@@ -121,3 +121,25 @@ describe('Bot-Token', () => {
expect(outcome.run).toMatchObject({ sent: false, detail: 'channel_not_found' })
})
})
describe('Doppelter Versand', () => {
it('schickt nach einem Versand nichts Zweites, solange nichts Neues erscheint', async () => {
const brand = await makeBrand()
const project = await makeProject(brand.id)
await makePost(project.id, { number: 1, slug: 'eins', status: 'published', publishAt: new Date() })
await writeSetting('slack.botToken', 'xoxb-1234')
await writeSetting('slack.channel', 'C123')
vi.stubGlobal('fetch', vi.fn(async () => new Response(
JSON.stringify({ ok: true, channel: 'C123', ts: '1785600000.000100' }),
{ headers: { 'content-type': 'application/json' } },
)))
const first = await runWeeklyReport({ origin, trigger: 'test' })
const second = await runWeeklyReport({ origin, trigger: 'test' })
expect(first.reason).toBe('sent')
expect(second.reason).toBe('nothing_published')
})
})
+22
View File
@@ -133,3 +133,25 @@ describe('Karten', () => {
expect(sections).toHaveLength(5)
})
})
describe('windowFor mit letztem Versand', () => {
it('beginnt beim letzten Versand, wenn der jünger ist', () => {
const { from } = windowFor(
new Date('2026-08-03T06:00:00.000Z'),
7,
new Date('2026-08-01T09:00:00.000Z'),
)
expect(from.toISOString()).toBe('2026-08-01T09:00:00.000Z')
})
it('bleibt bei sieben Tagen, wenn der letzte Versand älter ist', () => {
const { from } = windowFor(
new Date('2026-08-03T06:00:00.000Z'),
7,
new Date('2026-06-01T09:00:00.000Z'),
)
expect(from.toISOString()).toBe('2026-07-27T06:00:00.000Z')
})
})