| 1 | // Een markering op een hulpvraag draagt zijn context (26-8).
|
|---|
| 2 | //
|
|---|
| 3 | // Barts vraag: in Berichten staat "Ik kijk hiernaar." maar een tik erop geeft
|
|---|
| 4 | // niets -- welke context heeft dat bericht? Geen, bleek: de verwijzing reisde
|
|---|
| 5 | // alleen als shaer:-veld, en dat veld haalt de berichtenlezing niet. De
|
|---|
| 6 | // tik-route van de clients volgt inReplyTo, en die stond er niet op.
|
|---|
| 7 | //
|
|---|
| 8 | // Deze toets legt het contract vast op de plek die alle wegen delen:
|
|---|
| 9 | // deliverDirectNote. De guardian-knop en het C2S-pad komen daar allebei doorheen.
|
|---|
| 10 | import { test } from 'node:test';
|
|---|
| 11 | import assert from 'node:assert/strict';
|
|---|
| 12 |
|
|---|
| 13 | process.env.DATABASE_PATH = ':memory:';
|
|---|
| 14 | process.env.PUBLIC_BASE_URL = 'https://test.example';
|
|---|
| 15 |
|
|---|
| 16 | const dbMod = await import('../src/config/database.js');
|
|---|
| 17 | const db = dbMod.default;
|
|---|
| 18 | dbMod.initializeDatabase();
|
|---|
| 19 | const AP = (await import('../src/services/ActivityPubService.js')).default;
|
|---|
| 20 | const help = (await import('../src/services/guardianship/help.js')).default;
|
|---|
| 21 |
|
|---|
| 22 | const BASE = 'https://test.example';
|
|---|
| 23 | db.prepare('INSERT INTO users (id, username, email, password_hash, role) VALUES (?,?,?,?,?)')
|
|---|
| 24 | .run('u1', 'u1', 'u1@t', 'x', 'god');
|
|---|
| 25 | db.prepare('INSERT INTO sites (id, slug, title, owner_id, is_primary) VALUES (?,?,?,?,1)')
|
|---|
| 26 | .run('s1', 'oppas', 'Oppas', 'u1');
|
|---|
| 27 | db.prepare('INSERT INTO sites (id, slug, title, owner_id, is_primary) VALUES (?,?,?,?,0)')
|
|---|
| 28 | .run('s2', 'kind', 'Kind', 'u1');
|
|---|
| 29 | const site = db.prepare('SELECT * FROM sites WHERE slug = ?').get('oppas');
|
|---|
| 30 |
|
|---|
| 31 | const HULPVRAAG = 'https://elders.test/notes/help-123';
|
|---|
| 32 |
|
|---|
| 33 | test('de oppak-markering is een antwoord op de hulpvraag', async () => {
|
|---|
| 34 | // Naar een LOKALE ontvanger: dan loopt de bezorging over de loopback en
|
|---|
| 35 | // raakt deze toets geen netwerk.
|
|---|
| 36 | const r = await AP.deliverDirectNote(site, {
|
|---|
| 37 | recipients: [`${BASE}/ap/users/kind`],
|
|---|
| 38 | text: 'Ik kijk hiernaar.',
|
|---|
| 39 | helpMark: { kind: 'pickup', noteUri: HULPVRAAG },
|
|---|
| 40 | });
|
|---|
| 41 | assert.ok(r && r.id, 'bezorging levert een id');
|
|---|
| 42 |
|
|---|
| 43 | // De outbox-rij: inReplyTo hoort op de hulpvraag te staan, ook al gaf de
|
|---|
| 44 | // aanroeper hem niet mee. Dat is de hele reparatie.
|
|---|
| 45 | const rij = db.prepare('SELECT in_reply_to FROM ap_outbox WHERE id = ?').get(r.id);
|
|---|
| 46 | assert.equal(rij.in_reply_to, HULPVRAAG);
|
|---|
| 47 |
|
|---|
| 48 | // En de note die de deur uit gaat zegt het in gewoon AS2.
|
|---|
| 49 | const note = AP.buildReplyNote(BASE, site, db.prepare('SELECT * FROM ap_outbox WHERE id = ?').get(r.id));
|
|---|
| 50 | assert.equal(note.inReplyTo, HULPVRAAG);
|
|---|
| 51 | });
|
|---|
| 52 |
|
|---|
| 53 | test('een meegegeven inReplyTo wint van de markering', async () => {
|
|---|
| 54 | // Wie expliciet ergens op antwoordt, antwoordt daarop. De markering vult
|
|---|
| 55 | // alleen het gat.
|
|---|
| 56 | const r = await AP.deliverDirectNote(site, {
|
|---|
| 57 | recipients: [`${BASE}/ap/users/kind`],
|
|---|
| 58 | text: 'Deze hulpvraag is afgehandeld.',
|
|---|
| 59 | inReplyTo: 'https://elders.test/notes/iets-anders',
|
|---|
| 60 | helpMark: { kind: 'handled', noteUri: HULPVRAAG },
|
|---|
| 61 | });
|
|---|
| 62 | const rij = db.prepare('SELECT in_reply_to FROM ap_outbox WHERE id = ?').get(r.id);
|
|---|
| 63 | assert.equal(rij.in_reply_to, 'https://elders.test/notes/iets-anders');
|
|---|
| 64 | });
|
|---|
| 65 |
|
|---|
| 66 | test('een gewoon bericht krijgt er geen inReplyTo bij', async () => {
|
|---|
| 67 | const r = await AP.deliverDirectNote(site, {
|
|---|
| 68 | recipients: [`${BASE}/ap/users/kind`],
|
|---|
| 69 | text: 'gewoon een berichtje',
|
|---|
| 70 | });
|
|---|
| 71 | const rij = db.prepare('SELECT in_reply_to FROM ap_outbox WHERE id = ?').get(r.id);
|
|---|
| 72 | assert.equal(rij.in_reply_to, null);
|
|---|
| 73 | });
|
|---|
| 74 |
|
|---|
| 75 | test('markerNote zelf draagt de verwijzing ook als inReplyTo', () => {
|
|---|
| 76 | const n = help.markerNote({ id: 'x', me: 'https://g/u/a', noteUri: HULPVRAAG, kind: 'pickup', to: ['https://w/u/k'] });
|
|---|
| 77 | assert.equal(n.inReplyTo, HULPVRAAG);
|
|---|
| 78 | assert.equal(n['shaer:helpPickup'], HULPVRAAG);
|
|---|
| 79 | });
|
|---|