mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-12-24 01:10:31 +01:00
test: add tests for topics slotting into remote categories if addressed
This commit is contained in:
@@ -9,6 +9,7 @@ const user = require('../user');
|
|||||||
const notifications = require('../notifications');
|
const notifications = require('../notifications');
|
||||||
const translator = require('../translator');
|
const translator = require('../translator');
|
||||||
const batch = require('../batch');
|
const batch = require('../batch');
|
||||||
|
const utils = require('../utils');
|
||||||
|
|
||||||
module.exports = function (Categories) {
|
module.exports = function (Categories) {
|
||||||
Categories.getCategoryTopics = async function (data) {
|
Categories.getCategoryTopics = async function (data) {
|
||||||
@@ -186,7 +187,7 @@ module.exports = function (Categories) {
|
|||||||
}
|
}
|
||||||
const promises = [
|
const promises = [
|
||||||
db.sortedSetAdd(`cid:${cid}:pids`, postData.timestamp, postData.pid),
|
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) {
|
if (!pinned) {
|
||||||
promises.push(db.sortedSetIncrBy(`cid:${cid}:tids:posts`, 1, postData.tid));
|
promises.push(db.sortedSetIncrBy(`cid:${cid}:tids:posts`, 1, postData.tid));
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ module.exports = function (Topics) {
|
|||||||
db.sortedSetsAdd(timestampedSortedSetKeys, timestamp, topicData.tid),
|
db.sortedSetsAdd(timestampedSortedSetKeys, timestamp, topicData.tid),
|
||||||
db.sortedSetsAdd(countedSortedSetKeys, 0, topicData.tid),
|
db.sortedSetsAdd(countedSortedSetKeys, 0, topicData.tid),
|
||||||
user.addTopicIdToUser(topicData.uid, topicData.tid, timestamp),
|
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,
|
utils.isNumber(tid) ? db.incrObjectField('global', 'topicCount') : null,
|
||||||
Topics.createTags(data.tags, topicData.tid, timestamp),
|
Topics.createTags(data.tags, topicData.tid, timestamp),
|
||||||
scheduled ? Promise.resolve() : categories.updateRecentTid(topicData.cid, topicData.tid),
|
scheduled ? Promise.resolve() : categories.updateRecentTid(topicData.cid, topicData.tid),
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ describe('Notes', () => {
|
|||||||
await install.giveWorldPrivileges();
|
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 () => {
|
it('should pull a remote root-level object by its id and create a new topic', async () => {
|
||||||
const { id } = helpers.mocks.note();
|
const { id } = helpers.mocks.note();
|
||||||
const assertion = await activitypub.notes.assert(0, id, { skipChecks: true });
|
const assertion = await activitypub.notes.assert(0, id, { skipChecks: true });
|
||||||
@@ -63,6 +63,51 @@ describe('Notes', () => {
|
|||||||
const exists = await topics.exists(tid);
|
const exists = await topics.exists(tid);
|
||||||
assert(exists);
|
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', () => {
|
describe('Private objects', () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user