From de42884796642fcda6a258d309c5defcf5ae50d1 Mon Sep 17 00:00:00 2001 From: f Date: Mon, 28 Oct 2024 17:53:26 -0300 Subject: [PATCH] chore: linting --- src/server/apsystem.test.ts | 43 ++++++++++++++++++------------------- src/server/apsystem.ts | 5 ++--- 2 files changed, 23 insertions(+), 25 deletions(-) diff --git a/src/server/apsystem.test.ts b/src/server/apsystem.test.ts index 2c7c276..960176b 100644 --- a/src/server/apsystem.test.ts +++ b/src/server/apsystem.test.ts @@ -12,7 +12,7 @@ import { MockFetch } from './fixtures/mockFetch.js' import { generateKeypair } from 'http-signed-fetch' // Helper function to create a new Store instance -function newStore(): Store { +function newStore (): Store { return new Store(new MemoryLevel({ valueEncoding: 'json' })) } @@ -34,7 +34,7 @@ const mockFetch: FetchLike = async (input: RequestInfo | URL, init?: RequestInit } const mockHooks = new HookSystem(mockStore, mockFetch) -function noop(): void { +function noop (): void { } const mockLog = { info: noop, @@ -393,7 +393,6 @@ test('ActivityPubSystem - Undo activity', async t => { await t.throwsAsync(async () => { return await store.forActor(actorMention).inbox.get(activity.id as string) }) - }) test('ActivityPubSystem - Interacted store', async t => { @@ -574,17 +573,17 @@ test('ActivityPubSystem - Handle Delete activity', async t => { mockFetch.fetch as FetchLike ) - const actorMention = '@user1@example.com'; - const actorUrl = 'https://example.com/actor/user1'; - const activityId = 'https://example.com/activity1'; + const actorMention = '@user1@example.com' + const actorUrl = 'https://example.com/actor/user1' + const activityId = 'https://example.com/activity1' await store.forActor(actorMention).setInfo({ keypair: { ...generateKeypair() }, - actorUrl: actorUrl, + actorUrl, publicKeyId: 'testAccount#main-key' - }); + }) - mockFetch.mockActor(actorMention); + mockFetch.mockActor(actorMention) const activity: APActivity = { '@context': 'https://www.w3.org/ns/activitystreams', @@ -593,8 +592,8 @@ test('ActivityPubSystem - Handle Delete activity', async t => { actor: actorUrl, object: 'https://example.com/note1', id: activityId - }; - await store.forActor(actorMention).inbox.add(activity); + } + await store.forActor(actorMention).inbox.add(activity) const deleteActivity: APActivity = { '@context': 'https://www.w3.org/ns/activitystreams', @@ -603,27 +602,27 @@ test('ActivityPubSystem - Handle Delete activity', async t => { actor: actorUrl, object: activityId, id: 'https://example.com/activity2' - }; + } - await aps.ingestActivity(actorMention, deleteActivity); + await aps.ingestActivity(actorMention, deleteActivity) try { - await store.forActor(actorMention).inbox.get(activityId); - t.fail('The activity should be deleted from the inbox'); + 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'); + t.true(error.message.includes('Activity not found'), 'The activity should be deleted from the inbox') } else { - t.fail('Unexpected error type'); + 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'); + 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`)); -}); + t.assert(mockFetch.history.includes('https://example.com/actor/user1/inbox')) +}) // After all tests, restore all sinon mocks test.afterEach(() => { diff --git a/src/server/apsystem.ts b/src/server/apsystem.ts index 7895dd4..91ed484 100644 --- a/src/server/apsystem.ts +++ b/src/server/apsystem.ts @@ -21,7 +21,6 @@ import { ModerationChecker, BLOCKED, ALLOWED } from './moderation.js' import type Store from './store/index.js' import { makeSigner } from '../keypair.js' import { Announcements } from './announcements.js' -import { ActivityStore } from './store/ActivityStore.js' export const DEFAULT_PUBLIC_KEY_FIELD = 'publicKey' @@ -545,10 +544,10 @@ export default class ActivityPubSystem { this.log.info({ activityId }, 'Deleted activity from index/collection') } catch (e) { this.log.error({ e, activityId }, 'Error while deleting activity') - throw createError(500, `Error deleting activity ${activityId} `, {e}) + throw createError(500, `Error deleting activity ${activityId} `, { e }) } - // Notify CMS that the activity was deleted + // Notify CMS that the activity was deleted await this.hookSystem.dispatchOnApproved(fromActor, activity) return }