mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-01-21 15:03:12 +01:00
test: more out.announce tests
This commit is contained in:
@@ -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,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -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) });
|
|
||||||
|
|
||||||
});
|
});
|
||||||
Reference in New Issue
Block a user