Skip to content

Node.js based forum software built for the modern web

test: new test file for feps

Julian Lame510e826334e
diff --git a/src/activitypub/feps.js b/src/activitypub/feps.js
index d22731fd79..3611ad805a 100644
--- a/src/activitypub/feps.js
+++ b/src/activitypub/feps.js
@@ -3,6 +3,7 @@
const nconf = require('nconf');
const posts = require('../posts');
+const utils = require('../utils');
const activitypub = module.parent.exports;
const Feps = module.exports;
@@ -69,7 +70,7 @@ Feps.announceObject = async function announceObject(id) {
}
const author = await posts.getPostField(id, 'uid');
- if (!author.startsWith(nconf.get('url'))) {
+ if (!utils.isNumber(author) && !author.startsWith(nconf.get('url'))) {
followers.unshift(author);
}
diff --git a/test/activitypub/feps.js b/test/activitypub/feps.js
new file mode 100644
index 0000000000..e8a826e4e2
--- /dev/null
+++ b/test/activitypub/feps.js
@@ -0,0 +1,68 @@
+'use strict';
+
+const assert = require('assert');
+const nconf = require('nconf');
+
+const db = require('../mocks/databasemock');
+const activitypub = require('../../src/activitypub');
+const utils = require('../../src/utils');
+const meta = require('../../src/meta');
+const install = require('../../src/install');
+const user = require('../../src/user');
+const groups = require('../../src/groups');
+const categories = require('../../src/categories');
+const topics = require('../../src/topics');
+const api = require('../../src/api');
+
+const helpers = require('./helpers');
+
+describe('FEPs', () => {
+ before(async () => {
+ meta.config.activitypubEnabled = 1;
+ await install.giveWorldPrivileges();
+ });
+
+ describe('1b12', () => {
+ describe('announceObject()', () => {
+ let cid;
+ let uid;
+ let adminUid;
+
+ before(async () => {
+ const name = utils.generateUUID();
+ const description = utils.generateUUID();
+ ({ cid } = await categories.create({ name, description }));
+
+ adminUid = await user.create({ username: utils.generateUUID() });
+ await groups.join('administrators', adminUid);
+ uid = await user.create({ username: utils.generateUUID() });
+
+ const { id: followerId, actor } = helpers.mocks.actor();
+ activitypub._cache.set(`0;${followerId}`, actor);
+ user.setCategoryWatchState(followerId, [cid], categories.watchStates.tracking);
+
+ activitypub._sent.clear();
+ });
+
+ it('should be called when a topic is moved from uncategorized to another category', async () => {
+ const { topicData } = await topics.post({
+ uid,
+ cid: -1,
+ title: utils.generateUUID(),
+ content: utils.generateUUID(),
+ });
+
+ assert(topicData);
+
+ await api.topics.move({ uid: adminUid }, {
+ tid: topicData.tid,
+ cid,
+ });
+
+ setTimeout(() => {
+ assert.strictEqual(activitypub._sent.size, 1);
+ }, 250);
+ });
+ });
+ });
+});
diff --git a/test/activitypub/helpers.js b/test/activitypub/helpers.js
index 23fc29be14..9df1222144 100644
--- a/test/activitypub/helpers.js
+++ b/test/activitypub/helpers.js
@@ -1,12 +1,42 @@
'use strict';
-const utils = require('../../src/utils');
const activitypub = require('../../src/activitypub');
+const utils = require('../../src/utils');
+const slugify = require('../../src/slugify');
const Helpers = module.exports;
Helpers.mocks = {};
+Helpers.mocks.actor = () => {
+ const baseUrl = 'https://example.org';
+ const uuid = utils.generateUUID();
+ const id = `${baseUrl}/${uuid}`;
+
+ const actor = {
+ '@context': [
+ 'https://www.w3.org/ns/activitystreams',
+ 'https://w3id.org/security/v1',
+ ],
+ id: `${id}`,
+ url: `${id}`,
+ inbox: `${id}/inbox`,
+ outbox: `${id}/outbox`,
+
+ type: 'Person',
+ name: slugify(uuid),
+ preferredUsername: uuid,
+
+ publicKey: {
+ id: `${id}#key`,
+ owner: `${id}`,
+ publicKeyPem: 'todo',
+ },
+ };
+
+ return { id, actor };
+};
+
Helpers.mocks.note = (override = {}) => {
const baseUrl = 'https://example.org';
const uuid = utils.generateUUID();