source: Klonkt/test/c2s-block.test.js@ 4c70ecb

main
Last change on this file since 4c70ecb was 4c70ecb, checked in by Robin Genis <roboburr@…>, 7 weeks ago

C2S Block and Undo(Block): Shaer's Orbit becomes a real server block

Putting someone "in Orbit" in Shaer was client-side only. The C2S outbox
now accepts Block and Undo(Block), wired onto the same blockTarget/unblock
the web UI uses: the actor lands in ap_blocks, shows up in the Block tab,
and their cached content is purged. Releasing from Orbit undoes it.

Changed files:
src/services/ActivityPubService.js

  • ingestOutboxActivity: case 'Block' -> blockTarget(site, uri), 202
  • Undo with inner Block -> unblock(site, uri), 202

New file:
test/c2s-block.test.js

  • Block lands in ap_blocks, Undo releases, missing object is 400

Changed files:
test/c2s-outbox.test.js

  • the unsupported-Undo example was Block; that is real now, the test uses Move instead

151 tests, all green.

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

  • Property mode set to 100644
File size: 1.7 KB
Line 
1// C2S Block / Undo(Block): Shaer "in Orbit" is a real server-side block.
2// The activity lands in ap_blocks (the Block tab) via the same blockTarget
3// the web UI uses; Undo(Block) releases it.
4import { test } from 'node:test';
5import assert from 'node:assert/strict';
6
7process.env.DATABASE_PATH = ':memory:';
8process.env.PUBLIC_BASE_URL = 'https://test.example';
9
10const dbMod = await import('../src/config/database.js');
11const db = dbMod.default;
12dbMod.initializeDatabase();
13const AP = (await import('../src/services/ActivityPubService.js')).default;
14
15db.prepare('INSERT INTO users (id, username, email, password_hash, role) VALUES (?,?,?,?,?)').run('u1', 'u1', 'u1@test', 'x', 'god');
16db.prepare('INSERT INTO sites (id, slug, title, owner_id, is_primary) VALUES (?,?,?,?,?)').run('s1', 'me', 'Me', 'u1', 1);
17const site = db.prepare('SELECT * FROM sites WHERE id = ?').get('s1');
18const user = { id: 'u1', username: 'u1' };
19
20const BULLY = 'https://r.test/u/bully';
21
22test('C2S Block lands in ap_blocks (the Block tab)', async () => {
23 const out = await AP.ingestOutboxActivity(site, user, { type: 'Block', object: BULLY });
24 assert.equal(out.status, 202);
25 assert.equal(out.url, BULLY);
26 const rows = AP.listBlocks('me');
27 assert.equal(rows.length, 1);
28 assert.equal(rows[0].target, BULLY);
29 assert.equal(rows[0].kind, 'actor');
30});
31
32test('C2S Undo(Block) releases it again', async () => {
33 const out = await AP.ingestOutboxActivity(site, user, {
34 type: 'Undo',
35 object: { type: 'Block', object: BULLY },
36 });
37 assert.equal(out.status, 202);
38 assert.equal(AP.listBlocks('me').length, 0);
39});
40
41test('Block without an object is a clean 400', async () => {
42 const out = await AP.ingestOutboxActivity(site, user, { type: 'Block' });
43 assert.equal(out.status, 400);
44});
Note: See TracBrowser for help on using the repository browser.