test: add tests for topics slotting into remote categories if addressed

This commit is contained in:
Julian Lam
2025-03-17 12:02:43 -04:00
parent ca9a5b6dfb
commit 804052f272
3 changed files with 49 additions and 3 deletions

View File

@@ -9,6 +9,7 @@ const user = require('../user');
const notifications = require('../notifications');
const translator = require('../translator');
const batch = require('../batch');
const utils = require('../utils');
module.exports = function (Categories) {
Categories.getCategoryTopics = async function (data) {
@@ -186,7 +187,7 @@ module.exports = function (Categories) {
}
const promises = [
db.sortedSetAdd(`cid:${cid}:pids`, postData.timestamp, postData.pid),
db.incrObjectField(`category:${cid}`, 'post_count'),
db.incrObjectField(`${utils.isNumber(cid) ? 'category' : 'categoryRemote'}:${cid}`, 'post_count'),
];
if (!pinned) {
promises.push(db.sortedSetIncrBy(`cid:${cid}:tids:posts`, 1, postData.tid));

View File

@@ -67,7 +67,7 @@ module.exports = function (Topics) {
db.sortedSetsAdd(timestampedSortedSetKeys, timestamp, topicData.tid),
db.sortedSetsAdd(countedSortedSetKeys, 0, topicData.tid),
user.addTopicIdToUser(topicData.uid, topicData.tid, timestamp),
db.incrObjectField(`category:${topicData.cid}`, 'topic_count'),
db.incrObjectField(`${utils.isNumber(topicData.cid) ? 'category' : 'categoryRemote'}:${topicData.cid}`, 'topic_count'),
utils.isNumber(tid) ? db.incrObjectField('global', 'topicCount') : null,
Topics.createTags(data.tags, topicData.tid, timestamp),
scheduled ? Promise.resolve() : categories.updateRecentTid(topicData.cid, topicData.tid),

View File

@@ -22,7 +22,7 @@ describe('Notes', () => {
await install.giveWorldPrivileges();
});
describe('Public objects', () => {
describe.only('Public objects', () => {
it('should pull a remote root-level object by its id and create a new topic', async () => {
const { id } = helpers.mocks.note();
const assertion = await activitypub.notes.assert(0, id, { skipChecks: true });
@@ -63,6 +63,51 @@ describe('Notes', () => {
const exists = await topics.exists(tid);
assert(exists);
});
it('should slot newly created topic in local category if addressed', async () => {
const { cid } = await categories.create({ name: utils.generateUUID() });
const { id } = helpers.mocks.note({
cc: ['https://example.org/user/foobar/followers', `${nconf.get('url')}/category/${cid}`],
});
const assertion = await activitypub.notes.assert(0, id);
assert(assertion);
const { tid, count } = assertion;
assert(tid);
assert.strictEqual(count, 1);
const topic = await topics.getTopicData(tid);
assert.strictEqual(topic.cid, cid);
});
it('should slot newly created topic in remote category if addressed', async () => {
const { id: cid, actor } = helpers.mocks.group();
activitypub._cache.set(`0;${cid}`, actor);
await activitypub.actors.assertGroup([cid]);
const { id } = helpers.mocks.note({
cc: ['https://example.org/user/foobar/followers', cid],
});
const assertion = await activitypub.notes.assert(0, id);
assert(assertion);
const { tid, count } = assertion;
assert(tid);
assert.strictEqual(count, 1);
const topic = await topics.getTopicData(tid);
assert.strictEqual(topic.cid, cid);
const tids = await db.getSortedSetMembers(`cid:${cid}:tids`);
assert(tids.includes(tid));
const category = await categories.getCategoryData(cid);
['topic_count', 'post_count', 'totalPostCount', 'totalTopicCount'].forEach((prop) => {
assert.strictEqual(category[prop], 1);
});
});
});
describe('Private objects', () => {