| 1 | // Owner followers/following carry display (name + avatar), not bare URIs
|
|---|
| 2 | // (shaer-aa3): name -> preferredUsername -> id.
|
|---|
| 3 | import { test } from 'node:test';
|
|---|
| 4 | import assert from 'node:assert/strict';
|
|---|
| 5 |
|
|---|
| 6 | process.env.DATABASE_PATH = ':memory:';
|
|---|
| 7 | process.env.PUBLIC_BASE_URL = 'https://test.example';
|
|---|
| 8 |
|
|---|
| 9 | const dbMod = await import('../src/config/database.js');
|
|---|
| 10 | const db = dbMod.default;
|
|---|
| 11 | dbMod.initializeDatabase();
|
|---|
| 12 | const AP = (await import('../src/services/ActivityPubService.js')).default;
|
|---|
| 13 |
|
|---|
| 14 | test('a followed account resolves to its cached name + icon', () => {
|
|---|
| 15 | db.prepare(`INSERT INTO ap_following (slug, actor_uri, handle, name, icon, status) VALUES (?,?,?,?,?,?)`)
|
|---|
| 16 | .run('me', 'https://r.test/u/anna', '@anna@r.test', 'Anna de Vries', 'https://r.test/anna.png', 'accepted');
|
|---|
| 17 | const ref = AP.buildActorRef('me', 'https://r.test/u/anna');
|
|---|
| 18 | assert.equal(ref.id, 'https://r.test/u/anna');
|
|---|
| 19 | assert.equal(ref.name, 'Anna de Vries');
|
|---|
| 20 | assert.equal(ref.preferredUsername, 'anna');
|
|---|
| 21 | assert.equal(ref.icon.url, 'https://r.test/anna.png');
|
|---|
| 22 | });
|
|---|
| 23 |
|
|---|
| 24 | test('a follower with cached display shows it', () => {
|
|---|
| 25 | db.prepare(`INSERT INTO ap_followers (slug, actor_uri, name, handle, icon) VALUES (?,?,?,?,?)`)
|
|---|
| 26 | .run('me', 'https://q.test/u/ben', 'Ben', '@ben@q.test', 'https://q.test/ben.png');
|
|---|
| 27 | const ref = AP.buildActorRef('me', 'https://q.test/u/ben');
|
|---|
| 28 | assert.equal(ref.name, 'Ben');
|
|---|
| 29 | assert.equal(ref.preferredUsername, 'ben');
|
|---|
| 30 | });
|
|---|
| 31 |
|
|---|
| 32 | test('an unknown actor falls back to id + derived username, no name', () => {
|
|---|
| 33 | const ref = AP.buildActorRef('me', 'https://x.test/users/cas');
|
|---|
| 34 | assert.equal(ref.id, 'https://x.test/users/cas');
|
|---|
| 35 | assert.equal(ref.name, undefined); // no invented name
|
|---|
| 36 | assert.equal(ref.preferredUsername, 'cas'); // from the handle
|
|---|
| 37 | });
|
|---|
| 38 |
|
|---|
| 39 | test('interaction cache is used when a follower has no own display row', () => {
|
|---|
| 40 | db.prepare(`INSERT INTO ap_followers (slug, actor_uri) VALUES ('me','https://r.test/u/dana')`).run();
|
|---|
| 41 | db.prepare(`INSERT INTO ap_interactions (kind, post_id, actor_uri, actor_name, actor_handle, actor_icon, created_at)
|
|---|
| 42 | VALUES ('like','p','https://r.test/u/dana','Dana','@dana@r.test','https://r.test/dana.png',CURRENT_TIMESTAMP)`).run();
|
|---|
| 43 | const ref = AP.buildActorRef('me', 'https://r.test/u/dana');
|
|---|
| 44 | assert.equal(ref.name, 'Dana');
|
|---|
| 45 | });
|
|---|
| 46 |
|
|---|
| 47 | test('prefersEnriched detects the Prefer opt-in (FEP-9876)', () => {
|
|---|
| 48 | assert.equal(AP.prefersEnriched('return=representation'), true);
|
|---|
| 49 | assert.equal(AP.prefersEnriched('return=representation; handling=lenient'), true);
|
|---|
| 50 | assert.equal(AP.prefersEnriched('foo, return=representation'), true);
|
|---|
| 51 | assert.equal(AP.prefersEnriched('return=minimal'), false);
|
|---|
| 52 | assert.equal(AP.prefersEnriched('returnx=representation'), false);
|
|---|
| 53 | assert.equal(AP.prefersEnriched(''), false);
|
|---|
| 54 | assert.equal(AP.prefersEnriched(undefined), false);
|
|---|
| 55 | });
|
|---|