Skip to content

Node.js based forum software built for the modern web

test: a few additional tests for announce handling

Julian Lam61f6806b6a69
diff --git a/src/posts/data.js b/src/posts/data.js
index 688c131b8a..d74a22e69d 100644
--- a/src/posts/data.js
+++ b/src/posts/data.js
@@ -7,7 +7,7 @@ const utils = require('../utils');
const intFields = [
'uid', 'pid', 'tid', 'deleted', 'timestamp',
'upvotes', 'downvotes', 'deleterUid', 'edited',
- 'replies', 'bookmarks',
+ 'replies', 'bookmarks', 'announces',
];
module.exports = function (Posts) {
diff --git a/test/activitypub/helpers.js b/test/activitypub/helpers.js
index a995866838..2690910e06 100644
--- a/test/activitypub/helpers.js
+++ b/test/activitypub/helpers.js
@@ -162,6 +162,8 @@ Helpers.mocks.announce = (override = {}) => {
if (!object) {
({ id: object } = Helpers.mocks.note());
}
+ delete override.actor;
+ delete override.object;
const activity = {
'@context': 'https://www.w3.org/ns/activitystreams',
@@ -171,6 +173,7 @@ Helpers.mocks.announce = (override = {}) => {
cc: [`${actor}/followers`],
actor,
object,
+ ...override,
};
return { activity };
diff --git a/test/activitypub/notes.js b/test/activitypub/notes.js
index f079076215..afd24081c5 100644
--- a/test/activitypub/notes.js
+++ b/test/activitypub/notes.js
@@ -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)', () => {
it('should create a new topic in cid -1 if category not addressed', async () => {
const { note } = helpers.mocks.note();