| 1 | // A Shaer detail-view Reply is followers-only: buildNote(isReply) with
|
|---|
| 2 | // visibility 'friends' addresses the parent author + followers, but NOT Public.
|
|---|
| 3 | import { test } from 'node:test';
|
|---|
| 4 | import assert from 'node:assert/strict';
|
|---|
| 5 | process.env.DATABASE_PATH = ':memory:';
|
|---|
| 6 | process.env.PUBLIC_BASE_URL = 'https://test.example';
|
|---|
| 7 | const dbMod = await import('../src/config/database.js');
|
|---|
| 8 | dbMod.initializeDatabase();
|
|---|
| 9 | const { buildNote } = await import('../src/services/ActivityPubService.js');
|
|---|
| 10 |
|
|---|
| 11 | const PUBLIC = 'https://www.w3.org/ns/activitystreams#Public';
|
|---|
| 12 | const base = 'https://test.example';
|
|---|
| 13 | const site = { slug: 'kid' };
|
|---|
| 14 | const row = (visibility) => ({
|
|---|
| 15 | id: 'reply-1', in_reply_to: 'https://mastodon.social/@alice/1',
|
|---|
| 16 | content: '<p>hi</p>', to_actor: 'https://mastodon.social/users/alice', visibility,
|
|---|
| 17 | });
|
|---|
| 18 |
|
|---|
| 19 | test('followers-only reply: author in to, followers in cc, NO Public', () => {
|
|---|
| 20 | const note = buildNote(base, site, row('friends'), { isReply: true });
|
|---|
| 21 | assert.deepEqual(note.to, ['https://mastodon.social/users/alice']);
|
|---|
| 22 | assert.deepEqual(note.cc, [`${base}/ap/users/kid/followers`]);
|
|---|
| 23 | assert.ok(!note.cc.includes(PUBLIC));
|
|---|
| 24 | assert.equal(note.inReplyTo, 'https://mastodon.social/@alice/1');
|
|---|
| 25 | });
|
|---|
| 26 |
|
|---|
| 27 | test('default reply stays quiet-public: author in to, Public + followers in cc', () => {
|
|---|
| 28 | const note = buildNote(base, site, row(null), { isReply: true });
|
|---|
| 29 | assert.deepEqual(note.to, ['https://mastodon.social/users/alice']);
|
|---|
| 30 | assert.ok(note.cc.includes(PUBLIC));
|
|---|
| 31 | assert.ok(note.cc.includes(`${base}/ap/users/kid/followers`));
|
|---|
| 32 | });
|
|---|
| 33 |
|
|---|
| 34 | test('direct note addresses only its recipients (no Public/followers)', () => {
|
|---|
| 35 | const note = buildNote(base, site, {
|
|---|
| 36 | id: 'dm-1', content: '<p>x</p>', visibility: 'direct',
|
|---|
| 37 | to_actors: JSON.stringify(['https://s/u/bob']),
|
|---|
| 38 | }, { isReply: true });
|
|---|
| 39 | assert.deepEqual(note.to, ['https://s/u/bob']);
|
|---|
| 40 | assert.deepEqual(note.cc, []);
|
|---|
| 41 | });
|
|---|