Skip to content

Commit

Permalink
fix(apsystem.test): add test to check auto-accept remote deletes
Browse files Browse the repository at this point in the history
  • Loading branch information
magush27 committed Oct 25, 2024
1 parent 671e782 commit bd7489c
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions src/server/apsystem.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,70 @@ test('ActivityPubSystem - Interacted store', async t => {
}
})

test('ActivityPubSystem - Handle Delete activity', async t => {
const store = newStore()
const mockFetch = new MockFetch()
const hookSystem = new HookSystem(store, mockFetch.fetch as FetchLike)
const aps = new ActivityPubSystem(
'http://localhost',
store,
mockModCheck,
hookSystem,
mockLog,
mockFetch.fetch as FetchLike
)

const actorMention = '@[email protected]';
const actorUrl = 'https://example.com/actor/user1';
const activityId = 'https://example.com/activity1';

await store.forActor(actorMention).setInfo({
keypair: { ...generateKeypair() },
actorUrl: actorUrl,
publicKeyId: 'testAccount#main-key'
});

mockFetch.mockActor(actorMention);

const activity: APActivity = {
'@context': 'https://www.w3.org/ns/activitystreams',
type: 'Like',
published: new Date().toISOString(),
actor: actorUrl,
object: 'https://example.com/note1',
id: activityId
};
await store.forActor(actorMention).inbox.add(activity);

const deleteActivity: APActivity = {
'@context': 'https://www.w3.org/ns/activitystreams',
type: 'Delete',
published: new Date().toISOString(),
actor: actorUrl,
object: activityId,
id: 'https://example.com/activity2'
};

await aps.ingestActivity(actorMention, deleteActivity);

try {
await store.forActor(actorMention).inbox.get(activityId);
t.fail('The activity should be deleted from the inbox');
} catch (error) {
if (error instanceof Error) {
t.true(error.message.includes('Activity not found'), 'The activity should be deleted from the inbox');
} else {
t.fail('Unexpected error type');
}
}

const storedActivities = await store.forActor(actorMention).inbox.list({ object: activityId });
const isActivityPresent = storedActivities.some((a) => a.id === activityId);
t.falsy(isActivityPresent, 'The activity should be removed from the index/collection');

t.assert(mockFetch.history.includes(`https://example.com/actor/user1/inbox`));
});

// After all tests, restore all sinon mocks
test.afterEach(() => {
// Restore all sinon mocks
Expand Down

0 comments on commit bd7489c

Please sign in to comment.