Changeset 544e9c2 in Klonkt for test/messages.test.js


Ignore:
Timestamp:
07/19/2026 11:58:47 PM (7 weeks ago)
Author:
Robin <roboburr@…>
Branches:
main
Children:
162c7a7
Parents:
8ed65a6
Message:

Feature: Messages "poll finished" notification (klonkt-demo-93o)

Closed own polls surface a poll_done item in Messages with the final tally (bar+pct per option, voter count), derived read-time from poll_json.closed via ownPollView. i18n msg.poll_done/msg.poll_total (NL/EN/DE). Tests in messages.test.js.

Co-Authored-By: Claude Opus 4.8 <noreply@…>

File:
1 edited

Legend:

Unmodified
Added
Removed
  • test/messages.test.js

    r8ed65a6 r544e9c2  
    6969  assert.ok(AP.notificationsSeenAt('me') > 0);
    7070});
     71
     72// ── Poll afgelopen → "resultaten zijn binnen"-item met tally ─────────────
     73test('een afgelopen eigen peiling levert een poll_done-item met tally', () => {
     74  db.prepare(`INSERT INTO posts (id, site_id, slug, author_id, title, content, status, type, poll_json, created_at, updated_at, published_at)
     75    VALUES ('pp','s1','fav','u1','Favoriet?','<p>kies</p>','published','post',?,datetime('now'),datetime('now'),datetime('now'))`)
     76    .run(JSON.stringify({ multiple: false, options: [{ name: 'A' }, { name: 'B' }], endTime: '2026-07-19T00:00:00Z', closed: true }));
     77  const iv = db.prepare('INSERT OR IGNORE INTO poll_votes (post_id, actor_uri, choice) VALUES (?,?,?)');
     78  iv.run('pp', 'https://r.test/u/x', 'A');
     79  iv.run('pp', 'https://r.test/u/y', 'A');
     80  iv.run('pp', 'https://r.test/u/z', 'B');
     81
     82  const fresh = AP.getMessages('me', 50);
     83  const done = fresh.find((m) => m.type === 'poll_done');
     84  assert.ok(done, 'poll_done-item ontbreekt');
     85  assert.equal(done.post_slug, 'fav');
     86  assert.equal(done.poll.voters, 3);
     87  const a = done.poll.options.find((o) => o.name === 'A');
     88  assert.equal(a.count, 2);
     89  assert.equal(a.pct, 67); // round(2/3*100)
     90});
     91
     92// Een nog lopende peiling (closed != 1) verschijnt NIET.
     93test('een lopende peiling levert géén poll_done', () => {
     94  db.prepare(`INSERT INTO posts (id, site_id, slug, author_id, title, content, status, type, poll_json, created_at, updated_at, published_at)
     95    VALUES ('pp2','s1','open','u1','Open?','<p>kies</p>','published','post',?,datetime('now'),datetime('now'),datetime('now'))`)
     96    .run(JSON.stringify({ multiple: false, options: [{ name: 'A' }, { name: 'B' }], endTime: '2030-01-01T00:00:00Z', closed: false }));
     97  const fresh = AP.getMessages('me', 50);
     98  assert.ok(!fresh.some((m) => m.type === 'poll_done' && m.post_slug === 'open'), 'lopende peiling hoort niet als poll_done te tonen');
     99});
Note: See TracChangeset for help on using the changeset viewer.