| [4407c67] | 1 | // C2S owner collections: followers/following are count-only by default, but
|
|---|
| 2 | // carry the real actor URIs when the account owner asks (klonkt-demo-6kc).
|
|---|
| 3 | // The route-level bearer gate is verified live; here we cover the builders.
|
|---|
| 4 |
|
|---|
| 5 | import { test } from 'node:test';
|
|---|
| 6 | import assert from 'node:assert/strict';
|
|---|
| 7 |
|
|---|
| 8 | process.env.DATABASE_PATH = ':memory:';
|
|---|
| 9 | process.env.PUBLIC_BASE_URL = 'https://klonkt.test';
|
|---|
| 10 |
|
|---|
| 11 | const dbMod = await import('../src/config/database.js');
|
|---|
| 12 | dbMod.initializeDatabase();
|
|---|
| 13 | const AP = await import('../src/services/ActivityPubService.js');
|
|---|
| 14 |
|
|---|
| 15 | const base = 'https://klonkt.test';
|
|---|
| 16 | const site = { slug: 'me', primary_slug: 'me' };
|
|---|
| 17 |
|
|---|
| 18 | test('followers/following are count-only when no items are passed', () => {
|
|---|
| 19 | const f = AP.buildFollowers(base, site, 7);
|
|---|
| 20 | assert.equal(f.type, 'OrderedCollection');
|
|---|
| 21 | assert.equal(f.totalItems, 7);
|
|---|
| 22 | assert.deepEqual(f.orderedItems, []);
|
|---|
| 23 |
|
|---|
| 24 | const g = AP.buildFollowing(base, site, 3);
|
|---|
| 25 | assert.equal(g.totalItems, 3);
|
|---|
| 26 | assert.deepEqual(g.orderedItems, []);
|
|---|
| 27 | });
|
|---|
| 28 |
|
|---|
| 29 | test('the owner view carries the real actor URIs', () => {
|
|---|
| 30 | const uris = ['https://a.test/actor', 'https://b.test/actor'];
|
|---|
| 31 | const f = AP.buildFollowers(base, site, 999, uris);
|
|---|
| 32 | assert.deepEqual(f.orderedItems, uris);
|
|---|
| 33 | assert.equal(f.totalItems, 2); // reflects the items, not the passed count
|
|---|
| 34 |
|
|---|
| 35 | const g = AP.buildFollowing(base, site, 0, uris);
|
|---|
| 36 | assert.deepEqual(g.orderedItems, uris);
|
|---|
| 37 | assert.equal(g.totalItems, 2);
|
|---|
| 38 | });
|
|---|
| 39 |
|
|---|
| 40 | test('an empty owner list is a valid empty collection, not count-only fallback', () => {
|
|---|
| 41 | const f = AP.buildFollowers(base, site, 5, []);
|
|---|
| 42 | assert.equal(f.totalItems, 0);
|
|---|
| 43 | assert.deepEqual(f.orderedItems, []);
|
|---|
| 44 | });
|
|---|