Skip to content

Node.js based forum software built for the modern web

fix: #13129, serve category backgroundImage as actor `icon`, not `image`

Julian Lamb8200095c011
diff --git a/src/activitypub/mocks.js b/src/activitypub/mocks.js
index 003d392333..223d1a8cbd 100644
--- a/src/activitypub/mocks.js
+++ b/src/activitypub/mocks.js
@@ -341,23 +341,24 @@ Mocks.actors.category = async (cid) => {
} = await categories.getCategoryData(cid);
const publicKey = await activitypub.getPublicKey('cid', cid);
- let image;
+ let icon;
if (backgroundImage) {
const filename = path.basename(utils.decodeHTMLEntities(backgroundImage));
- image = {
+ icon = {
type: 'Image',
mediaType: mime.getType(filename),
url: `${nconf.get('url')}${utils.decodeHTMLEntities(backgroundImage)}`,
};
+ } else {
+ icon = await categories.icons.get(cid);
+ icon = icon.get('png');
+ icon = {
+ type: 'Image',
+ mediaType: 'image/png',
+ url: `${nconf.get('url')}${icon}`,
+ };
}
- let icon = await categories.icons.get(cid);
- icon = icon.get('png');
- icon = {
- type: 'Image',
- mediaType: 'image/png',
- url: `${nconf.get('url')}${icon}`,
- };
return {
'@context': [
@@ -375,7 +376,7 @@ Mocks.actors.category = async (cid) => {
name,
preferredUsername,
summary,
- image,
+ // image, // todo once categories have cover photos
icon,
publicKey: {
diff --git a/test/activitypub.js b/test/activitypub.js
index aee20d8037..d2c2334140 100644
--- a/test/activitypub.js
+++ b/test/activitypub.js
@@ -350,6 +350,79 @@ describe('ActivityPub integration', () => {
});
});
+ describe.only('Category Actor endpoint', () => {
+ let cid;
+ let slug;
+ let description;
+
+ beforeEach(async () => {
+ slug = slugify(utils.generateUUID().slice(0, 8));
+ description = utils.generateUUID();
+ ({ cid } = await categories.create({
+ name: slug,
+ description,
+ }));
+ });
+
+ it('should return a valid ActivityPub Actor JSON-LD payload', async () => {
+ const { response, body } = await request.get(`${nconf.get('url')}/category/${cid}`, {
+ headers: {
+ Accept: 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"',
+ },
+ });
+
+ assert(response);
+ assert.strictEqual(response.statusCode, 200);
+ assert(body.hasOwnProperty('@context'));
+ assert(body['@context'].includes('https://www.w3.org/ns/activitystreams'));
+
+ ['id', 'url', /* 'followers', 'following', */ 'inbox', 'outbox'].forEach((prop) => {
+ assert(body.hasOwnProperty(prop));
+ assert(body[prop]);
+ });
+
+ assert.strictEqual(body.id, `${nconf.get('url')}/category/${cid}`);
+ assert.strictEqual(body.type, 'Group');
+ assert.strictEqual(body.summary, description);
+ assert.deepStrictEqual(body.icon, {
+ type: 'Image',
+ mediaType: 'image/png',
+ url: `${nconf.get('url')}/assets/uploads/category/category-${cid}-icon.png`,
+ });
+ });
+
+ it('should contain a `publicKey` property with a public key', async () => {
+ const { body } = await request.get(`${nconf.get('url')}/category/${cid}`, {
+ headers: {
+ Accept: 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"',
+ },
+ });
+
+ assert(body.hasOwnProperty('publicKey'));
+ assert(['id', 'owner', 'publicKeyPem'].every(prop => body.publicKey.hasOwnProperty(prop)));
+ });
+
+ it('should serve the the backgroundImage in `icon` if set', async () => {
+ const payload = {};
+ payload[cid] = {
+ backgroundImage: `/assets/uploads/files/test.png`,
+ };
+ await categories.update(payload);
+
+ const { body } = await request.get(`${nconf.get('url')}/category/${cid}`, {
+ headers: {
+ Accept: 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"',
+ },
+ });
+
+ assert.deepStrictEqual(body.icon, {
+ type: 'Image',
+ mediaType: 'image/png',
+ url: `${nconf.get('url')}/assets/uploads/files/test.png`,
+ });
+ });
+ });
+
describe('Instance Actor endpoint', () => {
let response;
let body;