mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-01-21 15:03:12 +01:00
test: update activitypub._sent to save targets as well, updated tests to accommodate format change
This commit is contained in:
@@ -418,15 +418,15 @@ ActivityPub.send = async (type, id, targets, payload) => {
|
|||||||
|
|
||||||
ActivityPub.helpers.log(`[activitypub/send] ${payload.id}`);
|
ActivityPub.helpers.log(`[activitypub/send] ${payload.id}`);
|
||||||
|
|
||||||
if (process.env.hasOwnProperty('CI')) {
|
|
||||||
ActivityPub._sent.set(payload.id, payload);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!Array.isArray(targets)) {
|
if (!Array.isArray(targets)) {
|
||||||
targets = [targets];
|
targets = [targets];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (process.env.hasOwnProperty('CI')) {
|
||||||
|
ActivityPub._sent.set(payload.id, { payload, targets });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const inboxes = await ActivityPub.resolveInboxes(targets);
|
const inboxes = await ActivityPub.resolveInboxes(targets);
|
||||||
|
|
||||||
const actor = ActivityPub.helpers.resolveActor(type, id);
|
const actor = ActivityPub.helpers.resolveActor(type, id);
|
||||||
|
|||||||
@@ -364,8 +364,8 @@ describe('as:Group', () => {
|
|||||||
assert.strictEqual(activitypub._sent.size, 1);
|
assert.strictEqual(activitypub._sent.size, 1);
|
||||||
|
|
||||||
const activity = Array.from(activitypub._sent.values()).pop();
|
const activity = Array.from(activitypub._sent.values()).pop();
|
||||||
assert.strictEqual(activity.type, 'Follow');
|
assert.strictEqual(activity.payload.type, 'Follow');
|
||||||
assert.strictEqual(activity.object, cid);
|
assert.strictEqual(activity.payload.object, cid);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should send out a Follow activity when the watch state changes to "watching"', async () => {
|
it('should send out a Follow activity when the watch state changes to "watching"', async () => {
|
||||||
@@ -374,9 +374,9 @@ describe('as:Group', () => {
|
|||||||
assert.strictEqual(activitypub._sent.size, 1);
|
assert.strictEqual(activitypub._sent.size, 1);
|
||||||
|
|
||||||
const activity = Array.from(activitypub._sent.values()).pop();
|
const activity = Array.from(activitypub._sent.values()).pop();
|
||||||
assert(activity && activity.object && typeof activity.object === 'string');
|
assert(activity && activity.payload.object && typeof activity.payload.object === 'string');
|
||||||
assert.strictEqual(activity.type, 'Follow');
|
assert.strictEqual(activity.payload.type, 'Follow');
|
||||||
assert.strictEqual(activity.object, cid);
|
assert.strictEqual(activity.payload.object, cid);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not show up in the user\'s following list', async () => {
|
it('should not show up in the user\'s following list', async () => {
|
||||||
@@ -432,11 +432,11 @@ describe('as:Group', () => {
|
|||||||
assert.strictEqual(activitypub._sent.size, 1);
|
assert.strictEqual(activitypub._sent.size, 1);
|
||||||
|
|
||||||
const activity = Array.from(activitypub._sent.values()).pop();
|
const activity = Array.from(activitypub._sent.values()).pop();
|
||||||
assert(activity && activity.object && typeof activity.object === 'object');
|
assert(activity && activity.payload && activity.payload.object && typeof activity.payload.object === 'object');
|
||||||
assert.strictEqual(activity.type, 'Undo');
|
assert.strictEqual(activity.payload.type, 'Undo');
|
||||||
assert.strictEqual(activity.object.type, 'Follow');
|
assert.strictEqual(activity.payload.object.type, 'Follow');
|
||||||
assert.strictEqual(activity.object.actor, `${nconf.get('url')}/uid/${uid}`);
|
assert.strictEqual(activity.payload.object.actor, `${nconf.get('url')}/uid/${uid}`);
|
||||||
assert.strictEqual(activity.object.object, cid);
|
assert.strictEqual(activity.payload.object.object, cid);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -68,15 +68,15 @@ describe('FEPs', () => {
|
|||||||
|
|
||||||
const test1 = activities.some((activity) => {
|
const test1 = activities.some((activity) => {
|
||||||
[, activity] = activity;
|
[, activity] = activity;
|
||||||
return activity.type === 'Announce' &&
|
return activity.payload.type === 'Announce' &&
|
||||||
activity.object && activity.object.type === 'Create' &&
|
activity.payload.object && activity.payload.object.type === 'Create' &&
|
||||||
activity.object.object && activity.object.object.type === 'Note';
|
activity.payload.object.object && activity.payload.object.object.type === 'Note';
|
||||||
});
|
});
|
||||||
|
|
||||||
const test2 = activities.some((activity) => {
|
const test2 = activities.some((activity) => {
|
||||||
[, activity] = activity;
|
[, activity] = activity;
|
||||||
return activity.type === 'Announce' &&
|
return activity.payload.type === 'Announce' &&
|
||||||
activity.object && activity.object.type === 'Note';
|
activity.payload.object && activity.payload.object.type === 'Note';
|
||||||
});
|
});
|
||||||
|
|
||||||
assert(test1 && test2);
|
assert(test1 && test2);
|
||||||
@@ -92,9 +92,9 @@ describe('FEPs', () => {
|
|||||||
|
|
||||||
assert(activities.some((activity) => {
|
assert(activities.some((activity) => {
|
||||||
[, activity] = activity;
|
[, activity] = activity;
|
||||||
return activity.type === 'Announce' &&
|
return activity.payload.type === 'Announce' &&
|
||||||
activity.object && activity.object.type === 'Create' &&
|
activity.payload.object && activity.payload.object.type === 'Create' &&
|
||||||
activity.object.object && activity.object.object.type === 'Note';
|
activity.payload.object.object && activity.payload.object.object.type === 'Note';
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -108,7 +108,7 @@ describe('FEPs', () => {
|
|||||||
|
|
||||||
assert(activities.every((activity) => {
|
assert(activities.every((activity) => {
|
||||||
[, activity] = activity;
|
[, activity] = activity;
|
||||||
if (activity.type === 'Announce' && activity.object && activity.object.type === 'Note') {
|
if (activity.payload.type === 'Announce' && activity.payload.object && activity.payload.object.type === 'Note') {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -123,8 +123,8 @@ describe('FEPs', () => {
|
|||||||
|
|
||||||
assert(activities.some((activity) => {
|
assert(activities.some((activity) => {
|
||||||
[, activity] = activity;
|
[, activity] = activity;
|
||||||
return activity.type === 'Announce' &&
|
return activity.payload.type === 'Announce' &&
|
||||||
activity.object && activity.object.type === 'Like';
|
activity.payload.object && activity.payload.object.type === 'Like';
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -164,22 +164,20 @@ describe('FEPs', () => {
|
|||||||
});
|
});
|
||||||
pid = id;
|
pid = id;
|
||||||
({ activity } = await helpers.mocks.create(note));
|
({ activity } = await helpers.mocks.create(note));
|
||||||
console.log('before inbox create', activitypub._sent);
|
|
||||||
await activitypub.inbox.create({ body: activity });
|
await activitypub.inbox.create({ body: activity });
|
||||||
console.log('after inbox create', activitypub._sent);
|
|
||||||
const activities = Array.from(activitypub._sent);
|
const activities = Array.from(activitypub._sent);
|
||||||
|
|
||||||
const test1 = activities.some((activity) => {
|
const test1 = activities.some((activity) => {
|
||||||
[, activity] = activity;
|
[, activity] = activity;
|
||||||
return activity.type === 'Announce' &&
|
return activity.payload.type === 'Announce' &&
|
||||||
activity.object && activity.object.type === 'Create' &&
|
activity.payload.object && activity.payload.object.type === 'Create' &&
|
||||||
activity.object.object && activity.object.object.type === 'Note';
|
activity.payload.object.object && activity.payload.object.object.type === 'Note';
|
||||||
});
|
});
|
||||||
assert(test1);
|
assert(test1);
|
||||||
const test2 = activities.some((activity) => {
|
const test2 = activities.some((activity) => {
|
||||||
[, activity] = activity;
|
[, activity] = activity;
|
||||||
return activity.type === 'Announce' &&
|
return activity.payload.type === 'Announce' &&
|
||||||
activity.object && activity.object.type === 'Note';
|
activity.payload.object && activity.payload.object.type === 'Note';
|
||||||
});
|
});
|
||||||
assert(test2);
|
assert(test2);
|
||||||
});
|
});
|
||||||
@@ -197,9 +195,9 @@ describe('FEPs', () => {
|
|||||||
|
|
||||||
assert(activities.some((activity) => {
|
assert(activities.some((activity) => {
|
||||||
[, activity] = activity;
|
[, activity] = activity;
|
||||||
return activity.type === 'Announce' &&
|
return activity.payload.type === 'Announce' &&
|
||||||
activity.object && activity.object.type === 'Create' &&
|
activity.payload.object && activity.payload.object.type === 'Create' &&
|
||||||
activity.object.object && activity.object.object.type === 'Note';
|
activity.payload.object.object && activity.payload.object.object.type === 'Note';
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -214,8 +212,8 @@ describe('FEPs', () => {
|
|||||||
const activities = Array.from(activitypub._sent);
|
const activities = Array.from(activitypub._sent);
|
||||||
assert(activities.some((activity) => {
|
assert(activities.some((activity) => {
|
||||||
[, activity] = activity;
|
[, activity] = activity;
|
||||||
return activity.type === 'Announce' &&
|
return activity.payload.type === 'Announce' &&
|
||||||
activity.object && activity.object.type === 'Like';
|
activity.payload.object && activity.payload.object.type === 'Like';
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -240,8 +238,8 @@ describe('FEPs', () => {
|
|||||||
const key = Array.from(activitypub._sent.keys())[0];
|
const key = Array.from(activitypub._sent.keys())[0];
|
||||||
const activity = activitypub._sent.get(key);
|
const activity = activitypub._sent.get(key);
|
||||||
|
|
||||||
assert(activity && activity.object && typeof activity.object === 'object');
|
assert(activity && activity.payload && activity.payload.object && typeof activity.payload.object === 'object');
|
||||||
assert.strictEqual(activity.object.id, `${nconf.get('url')}/post/${reply1Pid}`);
|
assert.strictEqual(activity.payload.object.id, `${nconf.get('url')}/post/${reply1Pid}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should be called when a post is moved to another topic', async () => {
|
it('should be called when a post is moved to another topic', async () => {
|
||||||
@@ -268,11 +266,11 @@ describe('FEPs', () => {
|
|||||||
const activities = Array.from(activitypub._sent.keys()).map(key => activitypub._sent.get(key));
|
const activities = Array.from(activitypub._sent.keys()).map(key => activitypub._sent.get(key));
|
||||||
|
|
||||||
const activity = activities.pop();
|
const activity = activities.pop();
|
||||||
assert.strictEqual(activity.type, 'Announce');
|
assert.strictEqual(activity.payload.type, 'Announce');
|
||||||
assert(activity.object && activity.object.type);
|
assert(activity.payload.object && activity.payload.object.type);
|
||||||
assert.strictEqual(activity.object.type, 'Create');
|
assert.strictEqual(activity.payload.object.type, 'Create');
|
||||||
assert(activity.object.object && activity.object.object.type);
|
assert(activity.payload.object.object && activity.payload.object.object.type);
|
||||||
assert.strictEqual(activity.object.object.type, 'Note');
|
assert.strictEqual(activity.payload.object.object.type, 'Note');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -255,26 +255,26 @@ describe('Notes', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should federate out a Create activity', () => {
|
it('should federate out a Create activity', () => {
|
||||||
assert(activity && activity.to);
|
assert(activity && activity.payload && activity.payload.to);
|
||||||
assert.strictEqual(activity.type, 'Create');
|
assert.strictEqual(activity.payload.type, 'Create');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should have the local category addressed', () => {
|
it('should have the local category addressed', () => {
|
||||||
const addressees = new Set([
|
const addressees = new Set([
|
||||||
...(activity.to || []),
|
...(activity.payload.to || []),
|
||||||
...(activity.cc || []),
|
...(activity.payload.cc || []),
|
||||||
...(activity.bcc || []),
|
...(activity.payload.bcc || []),
|
||||||
...(activity.object.to || []),
|
...(activity.payload.object.to || []),
|
||||||
...(activity.object.cc || []),
|
...(activity.payload.object.cc || []),
|
||||||
...(activity.object.bcc || []),
|
...(activity.payload.object.bcc || []),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
assert(addressees.has(`${nconf.get('url')}/category/${cid}`));
|
assert(addressees.has(`${nconf.get('url')}/category/${cid}`));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should federate out an activity with object of type "Article"', () => {
|
it('should federate out an activity with object of type "Article"', () => {
|
||||||
assert(activity.object && activity.object.type);
|
assert(activity.payload.object && activity.payload.object.type);
|
||||||
assert.strictEqual(activity.object.type, 'Article');
|
assert.strictEqual(activity.payload.object.type, 'Article');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -299,8 +299,8 @@ describe('Notes', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should federate out an activity with object of type "Note"', () => {
|
it('should federate out an activity with object of type "Note"', () => {
|
||||||
assert(activity.object && activity.object.type);
|
assert(activity.payload && activity.payload.object && activity.payload.object.type);
|
||||||
assert.strictEqual(activity.object.type, 'Note');
|
assert.strictEqual(activity.payload.object.type, 'Note');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -330,16 +330,16 @@ describe('Notes', () => {
|
|||||||
|
|
||||||
const key = Array.from(activitypub._sent.keys())[0];
|
const key = Array.from(activitypub._sent.keys())[0];
|
||||||
const activity = activitypub._sent.get(key);
|
const activity = activitypub._sent.get(key);
|
||||||
assert(activity && activity.to);
|
assert(activity && activity.payload && activity.payload.to);
|
||||||
assert.strictEqual(activity.type, 'Create');
|
assert.strictEqual(activity.payload.type, 'Create');
|
||||||
|
|
||||||
const addressees = new Set([
|
const addressees = new Set([
|
||||||
...(activity.to || []),
|
...(activity.payload.to || []),
|
||||||
...(activity.cc || []),
|
...(activity.payload.cc || []),
|
||||||
...(activity.bcc || []),
|
...(activity.payload.bcc || []),
|
||||||
...(activity.object.to || []),
|
...(activity.payload.object.to || []),
|
||||||
...(activity.object.cc || []),
|
...(activity.payload.object.cc || []),
|
||||||
...(activity.object.bcc || []),
|
...(activity.payload.object.bcc || []),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
assert(addressees.has(cid));
|
assert(addressees.has(cid));
|
||||||
@@ -366,16 +366,16 @@ describe('Notes', () => {
|
|||||||
|
|
||||||
const key = Array.from(activitypub._sent.keys())[0];
|
const key = Array.from(activitypub._sent.keys())[0];
|
||||||
const activity = activitypub._sent.get(key);
|
const activity = activitypub._sent.get(key);
|
||||||
assert(activity && activity.to);
|
assert(activity && activity.payload && activity.payload.to);
|
||||||
assert.strictEqual(activity.type, 'Create');
|
assert.strictEqual(activity.payload.type, 'Create');
|
||||||
|
|
||||||
const addressees = new Set([
|
const addressees = new Set([
|
||||||
...(activity.to || []),
|
...(activity.payload.to || []),
|
||||||
...(activity.cc || []),
|
...(activity.payload.cc || []),
|
||||||
...(activity.bcc || []),
|
...(activity.payload.bcc || []),
|
||||||
...(activity.object.to || []),
|
...(activity.payload.object.to || []),
|
||||||
...(activity.object.cc || []),
|
...(activity.payload.object.cc || []),
|
||||||
...(activity.object.bcc || []),
|
...(activity.payload.object.bcc || []),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
assert(addressees.has(cid));
|
assert(addressees.has(cid));
|
||||||
|
|||||||
Reference in New Issue
Block a user