source: Klonkt/test/messages.test.js@ f1a23b8

main
Last change on this file since f1a23b8 was f1a23b8, checked in by Robin <roboburr@…>, 8 weeks ago

Feature: Messages merges Replies + Notifications into one inbox

/messages replaces /fediverse (manage own replies) and /notifications with a
single stream, per the Robin+Bart decision. getMessages() merges notifications
with your outbound replies ('sent' items, edit/delete via their outbox routes)
and collapses consecutive likes/boosts on the same post into one grouped item.
Design refresh: filter chips (All/Conversations/Activity/Sent, client-side),
avatars with a type-dot overlay, sent items with a direction indicator and
accent border, a lock badge on private replies (visibility now flows through
getNotifications along with actor icons), and unread dots via the existing
seen-watermark (read before marking seen). The two tabs collapse into one
Messages tab carrying the badge; the bookmarklet moved to /messages; old routes
redirect. Also fixes a latent NaN-unsafe date sort in getNotifications that
scrambled ordering when a row had a garbled created_at (seen live). i18n
NL/EN/DE. 4 new tests (67 green); verified in a browser incl. grouping, chips,
private badge, edit/delete forms. Beads: klonkt-demo-pkg. Old
fedi-notifications.ejs and the authorize-interaction manage block are now
unreachable; cleanup tracked in klonkt-demo-bk8.

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

  • Property mode set to 100644
File size: 3.5 KB
Line 
1// Messages-centrum: getMessages voegt notificaties + eigen outbound replies samen
2// in één stroom, groepeert opeenvolgende likes/boosts op dezelfde post, en geeft
3// visibility door (voor de privé-badge). Besluit Robin+Bart 2026-07-16.
4//
5// Run: npm test (= node --test)
6
7import { test } from 'node:test';
8import assert from 'node:assert/strict';
9
10process.env.DATABASE_PATH = ':memory:';
11process.env.PUBLIC_BASE_URL = 'https://klonkt.test';
12
13const dbMod = await import('../src/config/database.js');
14const db = dbMod.default;
15const AP = await import('../src/services/ActivityPubService.js');
16
17dbMod.initializeDatabase();
18
19// ── Seed: site + post + interacties + eigen reply ────────────────────────
20db.prepare('INSERT INTO users (id, username, email, password_hash, role) VALUES (?,?,?,?,?)')
21 .run('u1', 'u1', 'u1@test', 'x', 'god');
22db.prepare('INSERT INTO sites (id, slug, title, owner_id) VALUES (?,?,?,?)').run('s1', 'me', 'Me', 'u1');
23db.prepare(`INSERT INTO posts (id, site_id, slug, author_id, title, content, status, type, created_at, updated_at, published_at)
24 VALUES ('p1','s1','mijn-post','u1','Mijn post','<p>x</p>','published','post',datetime('now'),datetime('now'),datetime('now'))`).run();
25
26function addInter(kind, actor, createdAt, extra = {}) {
27 db.prepare(`INSERT INTO ap_interactions (kind, post_id, object_uri, actor_uri, actor_name, actor_icon, content, visibility, created_at)
28 VALUES (?,?,?,?,?,?,?,?,?)`)
29 .run(kind, 'p1', extra.object_uri || '', 'https://r.test/u/' + actor, actor, extra.icon || null,
30 extra.content || null, extra.visibility || 'public', createdAt);
31}
32// drie likes kort na elkaar (zelfde post) → moeten groeperen tot één item
33addInter('like', 'Anna', '2026-07-18 10:00:00');
34addInter('like', 'Ben', '2026-07-18 10:01:00');
35addInter('like', 'Cas', '2026-07-18 10:02:00');
36// een privé-reply (direct) ertussen, later
37addInter('reply', 'Dana', '2026-07-18 11:00:00', { object_uri: 'https://r.test/n/1', content: '<p>psst geheim</p>', visibility: 'direct' });
38// eigen outbound reply, nog later
39db.prepare(`INSERT INTO ap_outbox (id, site_slug, post_id, post_slug, in_reply_to, to_actor, to_handle, content, created_at)
40 VALUES ('out1','me','p1','mijn-post','https://r.test/n/1','https://r.test/u/Dana','@dana@r.test','<p>mijn antwoord</p>','2026-07-18 12:00:00')`).run();
41
42const msgs = AP.getMessages('me', 50);
43
44test('eigen outbound reply zit als "sent" in de stroom (nieuwste eerst)', () => {
45 const sent = msgs.find((m) => m.type === 'sent');
46 assert.ok(sent, 'sent-item ontbreekt');
47 assert.equal(sent.outboxId, 'out1');
48 assert.equal(sent.to_handle, '@dana@r.test');
49 assert.equal(msgs[0].type, 'sent', 'nieuwste item hoort bovenaan');
50});
51
52test('opeenvolgende likes op dezelfde post groeperen tot één item met count', () => {
53 const likes = msgs.filter((m) => m.type === 'like');
54 assert.equal(likes.length, 1, 'likes horen gegroepeerd te zijn');
55 assert.equal(likes[0].count, 3);
56 assert.equal(likes[0].actors.length, 3);
57});
58
59test('privé-reply draagt visibility voor de badge en heeft post-context', () => {
60 const reply = msgs.find((m) => m.type === 'reply');
61 assert.equal(reply.visibility, 'direct');
62 assert.equal(reply.post_slug, 'mijn-post');
63 assert.equal(reply.post_title, 'Mijn post');
64});
65
66test('notificationsSeenAt: 0 zonder watermark, daarna > 0', () => {
67 assert.equal(AP.notificationsSeenAt('me'), 0);
68 AP.markNotificationsSeen('me');
69 assert.ok(AP.notificationsSeenAt('me') > 0);
70});
Note: See TracBrowser for help on using the repository browser.