test: introduce overrides into person and group mocks

This commit is contained in:
Julian Lam
2025-03-18 11:06:10 -04:00
parent 80069a198c
commit 4f7481582c

View File

@@ -8,17 +8,21 @@ const Helpers = module.exports;
Helpers.mocks = {}; Helpers.mocks = {};
Helpers.mocks.person = () => { Helpers.mocks.person = (override = {}) => {
const baseUrl = 'https://example.org'; const baseUrl = 'https://example.org';
const uuid = utils.generateUUID(); const uuid = utils.generateUUID();
const id = `${baseUrl}/${uuid}`; let id = `${baseUrl}/${uuid}`;
if (override.hasOwnProperty('id')) {
id = override.id;
}
const actor = { const actor = {
'@context': [ '@context': [
'https://www.w3.org/ns/activitystreams', 'https://www.w3.org/ns/activitystreams',
'https://w3id.org/security/v1', 'https://w3id.org/security/v1',
], ],
id: `${id}`, id,
url: `${id}`, url: `${id}`,
inbox: `${id}/inbox`, inbox: `${id}/inbox`,
outbox: `${id}/outbox`, outbox: `${id}/outbox`,
@@ -32,6 +36,7 @@ Helpers.mocks.person = () => {
owner: `${id}`, owner: `${id}`,
publicKeyPem: 'todo', publicKeyPem: 'todo',
}, },
...override,
}; };
activitypub._cache.set(`0;${id}`, actor); activitypub._cache.set(`0;${id}`, actor);
@@ -39,9 +44,11 @@ Helpers.mocks.person = () => {
return { id, actor }; return { id, actor };
}; };
Helpers.mocks.group = () => { Helpers.mocks.group = (override = {}) => {
const { id, actor } = Helpers.mocks.person(); const { id, actor } = Helpers.mocks.person({
actor.type = 'Group'; type: 'Group',
...override,
});
activitypub._cache.set(`0;${id}`, actor); activitypub._cache.set(`0;${id}`, actor);