mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-03-21 11:52:01 +01:00
test: ensure auto-cat and cat sync logic properly integrates with crossposts
This commit is contained in:
@@ -445,10 +445,19 @@ Actors.getLocalFollowers = async (id) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else if (isCategory) {
|
} else if (isCategory) {
|
||||||
|
// Internally, users are different, they follow via watch state instead
|
||||||
|
// Possibly refactor to store in followersRemote:${id} too??
|
||||||
const members = await db.getSortedSetRangeByScore(`cid:${id}:uid:watch:state`, 0, -1, categories.watchStates.tracking, categories.watchStates.watching);
|
const members = await db.getSortedSetRangeByScore(`cid:${id}:uid:watch:state`, 0, -1, categories.watchStates.tracking, categories.watchStates.watching);
|
||||||
members.forEach((uid) => {
|
members.forEach((uid) => {
|
||||||
response.uids.add(uid);
|
response.uids.add(uid);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const cids = await db.getSortedSetMembers(`followersRemote:${id}`);
|
||||||
|
cids.forEach((id) => {
|
||||||
|
if (id.startsWith('cid|') && utils.isNumber(id.slice(4))) {
|
||||||
|
response.cids.add(parseInt(id.slice(4), 10));
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
|
|||||||
@@ -348,6 +348,91 @@ describe('Crossposting (& related logic)', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('category sync; integration with', () => {
|
||||||
|
let cid;
|
||||||
|
let remoteCid;
|
||||||
|
let pid;
|
||||||
|
let post;
|
||||||
|
|
||||||
|
const helpers = require('../activitypub/helpers');
|
||||||
|
|
||||||
|
before(async () => {
|
||||||
|
({ cid } = await categories.create({ name: utils.generateUUID().slice(0, 8) }));
|
||||||
|
({ id: remoteCid } = helpers.mocks.group());
|
||||||
|
({ id: pid, note: post } = helpers.mocks.note({
|
||||||
|
audience: [remoteCid],
|
||||||
|
}));
|
||||||
|
|
||||||
|
// Mock a group follow/accept
|
||||||
|
const timestamp = Date.now();
|
||||||
|
console.log('saving', remoteCid);
|
||||||
|
await Promise.all([
|
||||||
|
db.sortedSetAdd(`cid:${cid}:following`, timestamp, remoteCid),
|
||||||
|
db.sortedSetAdd(`followersRemote:${remoteCid}`, timestamp, `cid|${cid}`),
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should automatically cross-post the topic when the remote category announces', async () => {
|
||||||
|
const { activity: body } = helpers.mocks.announce({
|
||||||
|
actor: remoteCid,
|
||||||
|
object: post,
|
||||||
|
});
|
||||||
|
|
||||||
|
await activitypub.inbox.announce({ body });
|
||||||
|
|
||||||
|
const tid = await posts.getPostField(pid, 'tid');
|
||||||
|
const crossposts = await topics.crossposts.get(tid);
|
||||||
|
|
||||||
|
assert.strictEqual(crossposts.length, 1);
|
||||||
|
assert.partialDeepStrictEqual(crossposts[0], {
|
||||||
|
uid: '0',
|
||||||
|
tid,
|
||||||
|
cid: String(cid),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('auto-categorization; integration with', () => {
|
||||||
|
let cid;
|
||||||
|
let remoteCid;
|
||||||
|
let pid;
|
||||||
|
let post;
|
||||||
|
|
||||||
|
const helpers = require('../activitypub/helpers');
|
||||||
|
|
||||||
|
before(async () => {
|
||||||
|
const preferredUsername = utils.generateUUID().slice(0, 8);
|
||||||
|
({ cid } = await categories.create({ name: utils.generateUUID().slice(0, 8) }));
|
||||||
|
({ id: remoteCid } = helpers.mocks.group({
|
||||||
|
preferredUsername,
|
||||||
|
}));
|
||||||
|
({ id: pid, note: post } = helpers.mocks.note({
|
||||||
|
audience: [remoteCid],
|
||||||
|
tag: [
|
||||||
|
{
|
||||||
|
type: 'Hashtag',
|
||||||
|
name: `#${preferredUsername}`,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}));
|
||||||
|
|
||||||
|
await activitypub.rules.add('hashtag', preferredUsername, cid);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('note assertion should automatically cross-post', async () => {
|
||||||
|
await activitypub.notes.assert(0, pid, { skipChecks: true });
|
||||||
|
|
||||||
|
const tid = await posts.getPostField(pid, 'tid');
|
||||||
|
const crossposts = await topics.crossposts.get(tid);
|
||||||
|
assert.strictEqual(crossposts.length, 1);
|
||||||
|
assert.partialDeepStrictEqual(crossposts[0], {
|
||||||
|
uid: '0',
|
||||||
|
tid,
|
||||||
|
cid: String(cid),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('ActivityPub effects (or lack thereof)', () => {
|
describe('ActivityPub effects (or lack thereof)', () => {
|
||||||
describe('local canonical category', () => {
|
describe('local canonical category', () => {
|
||||||
let tid;
|
let tid;
|
||||||
|
|||||||
Reference in New Issue
Block a user