mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
test: a few additional tests for announce handling
This commit is contained in:
@@ -7,7 +7,7 @@ const utils = require('../utils');
|
|||||||
const intFields = [
|
const intFields = [
|
||||||
'uid', 'pid', 'tid', 'deleted', 'timestamp',
|
'uid', 'pid', 'tid', 'deleted', 'timestamp',
|
||||||
'upvotes', 'downvotes', 'deleterUid', 'edited',
|
'upvotes', 'downvotes', 'deleterUid', 'edited',
|
||||||
'replies', 'bookmarks',
|
'replies', 'bookmarks', 'announces',
|
||||||
];
|
];
|
||||||
|
|
||||||
module.exports = function (Posts) {
|
module.exports = function (Posts) {
|
||||||
|
|||||||
@@ -162,6 +162,8 @@ Helpers.mocks.announce = (override = {}) => {
|
|||||||
if (!object) {
|
if (!object) {
|
||||||
({ id: object } = Helpers.mocks.note());
|
({ id: object } = Helpers.mocks.note());
|
||||||
}
|
}
|
||||||
|
delete override.actor;
|
||||||
|
delete override.object;
|
||||||
|
|
||||||
const activity = {
|
const activity = {
|
||||||
'@context': 'https://www.w3.org/ns/activitystreams',
|
'@context': 'https://www.w3.org/ns/activitystreams',
|
||||||
@@ -171,6 +173,7 @@ Helpers.mocks.announce = (override = {}) => {
|
|||||||
cc: [`${actor}/followers`],
|
cc: [`${actor}/followers`],
|
||||||
actor,
|
actor,
|
||||||
object,
|
object,
|
||||||
|
...override,
|
||||||
};
|
};
|
||||||
|
|
||||||
return { activity };
|
return { activity };
|
||||||
|
|||||||
@@ -493,6 +493,83 @@ describe('Notes', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('(Create) or (Note) referencing local post', () => {
|
||||||
|
let uid;
|
||||||
|
let topicData;
|
||||||
|
let postData;
|
||||||
|
let localNote;
|
||||||
|
let announces = 0;
|
||||||
|
|
||||||
|
before(async () => {
|
||||||
|
uid = await user.create({ username: utils.generateUUID().slice(0, 10) });
|
||||||
|
({ topicData, postData } = await topics.post({
|
||||||
|
cid,
|
||||||
|
uid,
|
||||||
|
title: utils.generateUUID(),
|
||||||
|
content: utils.generateUUID(),
|
||||||
|
}));
|
||||||
|
localNote = await activitypub.mocks.notes.public(postData);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should increment announces counter when a remote user shares', async () => {
|
||||||
|
const { id } = helpers.mocks.person();
|
||||||
|
const { activity } = helpers.mocks.announce({
|
||||||
|
actor: id,
|
||||||
|
object: localNote,
|
||||||
|
cc: [`${nconf.get('url')}/uid/${topicData.uid}`],
|
||||||
|
});
|
||||||
|
|
||||||
|
await activitypub.inbox.announce({ body: activity });
|
||||||
|
announces += 1;
|
||||||
|
|
||||||
|
const count = await posts.getPostField(topicData.mainPid, 'announces');
|
||||||
|
assert.strictEqual(count, announces);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should contain the remote user announcer id in the post announces zset', async () => {
|
||||||
|
const { id } = helpers.mocks.person();
|
||||||
|
const { activity } = helpers.mocks.announce({
|
||||||
|
actor: id,
|
||||||
|
object: localNote,
|
||||||
|
cc: [`${nconf.get('url')}/uid/${topicData.uid}`],
|
||||||
|
});
|
||||||
|
|
||||||
|
await activitypub.inbox.announce({ body: activity });
|
||||||
|
announces += 1;
|
||||||
|
|
||||||
|
const exists = await db.isSortedSetMember(`pid:${topicData.mainPid}:announces`, id);
|
||||||
|
assert(exists);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should NOT increment announces counter when a remote category shares', async () => {
|
||||||
|
const { id } = helpers.mocks.group();
|
||||||
|
const { activity } = helpers.mocks.announce({
|
||||||
|
actor: id,
|
||||||
|
object: localNote,
|
||||||
|
cc: [`${nconf.get('url')}/uid/${topicData.uid}`],
|
||||||
|
});
|
||||||
|
|
||||||
|
await activitypub.inbox.announce({ body: activity });
|
||||||
|
|
||||||
|
const count = await posts.getPostField(topicData.mainPid, 'announces');
|
||||||
|
assert.strictEqual(count, announces);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should NOT contain the remote category announcer id in the post announces zset', async () => {
|
||||||
|
const { id } = helpers.mocks.group();
|
||||||
|
const { activity } = helpers.mocks.announce({
|
||||||
|
actor: id,
|
||||||
|
object: localNote,
|
||||||
|
cc: [`${nconf.get('url')}/uid/${topicData.uid}`],
|
||||||
|
});
|
||||||
|
|
||||||
|
await activitypub.inbox.announce({ body: activity });
|
||||||
|
|
||||||
|
const exists = await db.isSortedSetMember(`pid:${topicData.mainPid}:announces`, id);
|
||||||
|
assert(!exists);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('(Note)', () => {
|
describe('(Note)', () => {
|
||||||
it('should create a new topic in cid -1 if category not addressed', async () => {
|
it('should create a new topic in cid -1 if category not addressed', async () => {
|
||||||
const { note } = helpers.mocks.note();
|
const { note } = helpers.mocks.note();
|
||||||
|
|||||||
Reference in New Issue
Block a user