mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-03 04:25:55 +01:00
test: new test file for feps
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
68
test/activitypub/feps.js
Normal file
68
test/activitypub/feps.js
Normal file
@@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user