test: more out.announce tests

This commit is contained in:
Julian Lam
2026-01-06 12:08:39 -05:00
parent 27d511ff92
commit cfdbbb048d
2 changed files with 43 additions and 7 deletions

View File

@@ -323,9 +323,11 @@ Out.announce.topic = enabledCheck(async (tid) => {
const { to, cc, targets } = await activitypub.buildRecipients({ const { to, cc, targets } = await activitypub.buildRecipients({
id: pid, id: pid,
to: [activitypub._constants.publicAddress], to: [activitypub._constants.publicAddress],
cc: [authorUid],
}, { cid }); }, { cid });
targets.add(authorUid); if (!utils.isNumber(authorUid)) {
cc.push(authorUid);
targets.add(authorUid);
}
await activitypub.send('cid', cid, Array.from(targets), { await activitypub.send('cid', cid, Array.from(targets), {
id: `${nconf.get('url')}/post/${encodeURIComponent(pid)}#activity/announce/cid/${cid}`, id: `${nconf.get('url')}/post/${encodeURIComponent(pid)}#activity/announce/cid/${cid}`,
@@ -333,7 +335,7 @@ Out.announce.topic = enabledCheck(async (tid) => {
actor: `${nconf.get('url')}/category/${cid}`, actor: `${nconf.get('url')}/category/${cid}`,
to, to,
cc, cc,
object: pid, object: utils.isNumber(pid) ? `${nconf.get('url')}/post/${pid}` : pid,
}); });
}); });

View File

@@ -4,7 +4,9 @@ const assert = require('assert');
const nconf = require('nconf'); const nconf = require('nconf');
const db = require('../mocks/databasemock'); const db = require('../mocks/databasemock');
const user = require('../../src/user');
const categories = require('../../src/categories'); const categories = require('../../src/categories');
const topics = require('../../src/topics');
const posts = require('../../src/posts'); const posts = require('../../src/posts');
const meta = require('../../src/meta'); const meta = require('../../src/meta');
const install = require('../../src/install'); const install = require('../../src/install');
@@ -48,6 +50,11 @@ describe('Outbound activities module', () => {
assert.strictEqual(payload.type, 'Announce'); assert.strictEqual(payload.type, 'Announce');
}); });
it('should contain the main post\'s pid in object', () => {
const { payload } = Array.from(activitypub._sent).pop()[1];
assert.strictEqual(payload.object, pid);
});
it('should include the category\'s followers collection in cc', () => { it('should include the category\'s followers collection in cc', () => {
const { payload } = Array.from(activitypub._sent).pop()[1]; const { payload } = Array.from(activitypub._sent).pop()[1];
assert(payload.cc.includes(`${nconf.get('url')}/category/${cid}/followers`)); assert(payload.cc.includes(`${nconf.get('url')}/category/${cid}/followers`));
@@ -63,9 +70,36 @@ describe('Outbound activities module', () => {
assert(targets.includes(note.attributedTo)); assert(targets.includes(note.attributedTo));
}); });
}); });
describe('.topic() (local topic; by cid)', () => {
let uid;
let tid;
let cid;
before(async () => {
uid = await user.create({ username: utils.generateUUID().slice(0, 10) });
({ cid } = await categories.create({ name: utils.generateUUID() }));
const { topicData } = await topics.post({
cid, uid,
title: utils.generateUUID(),
content: utils.generateUUID(),
});
({ tid } = topicData);
});
after(() => {
activitypub._sent.clear();
});
it('should not error when called', async () => {
await activitypub.out.announce.topic(tid);
});
it('should include the topic\'s mainPid in object', async () => {
const mainPid = await topics.getTopicField(tid, 'mainPid');
const { payload } = Array.from(activitypub._sent).pop()[1];
assert.strictEqual(payload.object, `${nconf.get('url')}/post/${mainPid}`);
});
});
}); });
// let uid;
// uid = await user.create({ username: utils.generateUUID().slice(0, 10) });
}); });