Node.js based forum software built for the modern web
test: more out.announce tests
Julian Lamcfdbbb048d97
diff --git a/src/activitypub/out.js b/src/activitypub/out.jsindex 4fb71b4870..b49cf62630 100644--- a/src/activitypub/out.js+++ b/src/activitypub/out.js@@ -323,9 +323,11 @@ Out.announce.topic = enabledCheck(async (tid) => {const { to, cc, targets } = await activitypub.buildRecipients({id: pid,to: [activitypub._constants.publicAddress],- cc: [authorUid],}, { cid });- targets.add(authorUid);+ if (!utils.isNumber(authorUid)) {+ cc.push(authorUid);+ targets.add(authorUid);+ }await activitypub.send('cid', cid, Array.from(targets), {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}`,to,cc,- object: pid,+ object: utils.isNumber(pid) ? `${nconf.get('url')}/post/${pid}` : pid,});});diff --git a/test/activitypub/out.js b/test/activitypub/out.jsindex 228c7a2b72..673b86416f 100644--- a/test/activitypub/out.js+++ b/test/activitypub/out.js@@ -4,7 +4,9 @@ const assert = require('assert');const nconf = require('nconf');const db = require('../mocks/databasemock');+const user = require('../../src/user');const categories = require('../../src/categories');+const topics = require('../../src/topics');const posts = require('../../src/posts');const meta = require('../../src/meta');const install = require('../../src/install');@@ -48,6 +50,11 @@ describe('Outbound activities module', () => {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', () => {const { payload } = Array.from(activitypub._sent).pop()[1];assert(payload.cc.includes(`${nconf.get('url')}/category/${cid}/followers`));@@ -63,9 +70,36 @@ describe('Outbound activities module', () => {assert(targets.includes(note.attributedTo));});});- });- // let uid;- // uid = await user.create({ username: utils.generateUUID().slice(0, 10) });+ 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}`);+ });+ });+ });});\ No newline at end of file