From fa6f004b741299680bf21955796d9f074d043c07 Mon Sep 17 00:00:00 2001 From: Matthieu Sieben Date: Mon, 16 Dec 2024 13:51:26 +0100 Subject: [PATCH] fix types --- .../api/tests/moderation-mutewords.test.ts | 1 + packages/ozone/tests/_util.ts | 9 +++++++-- packages/ozone/tests/blob-divert.test.ts | 6 ++++-- packages/ozone/tests/moderation.test.ts | 19 +++++++++++++------ packages/pds/tests/preferences.test.ts | 1 + packages/pds/tests/seeds/basic.ts | 2 +- 6 files changed, 27 insertions(+), 11 deletions(-) diff --git a/packages/api/tests/moderation-mutewords.test.ts b/packages/api/tests/moderation-mutewords.test.ts index 681dddc73d8..bb43888f0d0 100644 --- a/packages/api/tests/moderation-mutewords.test.ts +++ b/packages/api/tests/moderation-mutewords.test.ts @@ -832,6 +832,7 @@ describe(`hasMutedWord`, () => { features: [ { $type: 'com.example.richtext.facet#other', + // @ts-expect-error foo: 'bar', }, { diff --git a/packages/ozone/tests/_util.ts b/packages/ozone/tests/_util.ts index ff44443867a..0d5b368f500 100644 --- a/packages/ozone/tests/_util.ts +++ b/packages/ozone/tests/_util.ts @@ -4,6 +4,7 @@ import { CID } from 'multiformats/cid' import { FeedViewPost, PostView, + ThreadViewPost, isPostView, isReasonRepost, isThreadViewPost, @@ -191,7 +192,9 @@ export const stripViewerFromPost = (postUnknown: object): PostView => { } // @NOTE mutates -export const stripViewerFromThread = (thread: T): T => { +export const stripViewerFromThread = ( + thread: T, +): Omit => { if (!isThreadViewPost(thread)) return thread // @ts-expect-error delete thread.viewer @@ -200,7 +203,9 @@ export const stripViewerFromThread = (thread: T): T => { thread.parent = stripViewerFromThread(thread.parent) } if (thread.replies) { - thread.replies = thread.replies.map(stripViewerFromThread) + thread.replies = thread.replies.map((r) => + isThreadViewPost(r) ? stripViewerFromThread(r) : r, + ) } return thread } diff --git a/packages/ozone/tests/blob-divert.test.ts b/packages/ozone/tests/blob-divert.test.ts index 9c335f20ec3..dc5828f1117 100644 --- a/packages/ozone/tests/blob-divert.test.ts +++ b/packages/ozone/tests/blob-divert.test.ts @@ -1,4 +1,5 @@ import assert from 'node:assert' +import { ToolsOzoneModerationDefs } from '@atproto/api' import { ModeratorClient, SeedClient, @@ -50,10 +51,11 @@ describe('blob divert', () => { modClient.emitEvent( { subject: getSubject(), - event: { + // @ts-expect-error modClient.emitEvent does not declare #modEventDivert + event: ((f: ToolsOzoneModerationDefs.ModEventDivert) => f)({ $type: 'tools.ozone.moderation.defs#modEventDivert', comment: 'Diverting for test', - }, + }), createdBy: sc.dids.alice, subjectBlobCids: sc.posts[sc.dids.carol][0].images.map((img) => img.image.ref.toString(), diff --git a/packages/ozone/tests/moderation.test.ts b/packages/ozone/tests/moderation.test.ts index 97e4b2e608e..0c70dce68ad 100644 --- a/packages/ozone/tests/moderation.test.ts +++ b/packages/ozone/tests/moderation.test.ts @@ -7,7 +7,11 @@ import { basicSeed, ModeratorClient, } from '@atproto/dev-env' -import { AtpAgent, ToolsOzoneModerationEmitEvent } from '@atproto/api' +import { + AtpAgent, + ChatBskyConvoDefs, + ToolsOzoneModerationEmitEvent, +} from '@atproto/api' import { AtUri } from '@atproto/syntax' import { forSnapshot } from './_util' import { @@ -157,23 +161,26 @@ describe('moderation', () => { const reportA = await sc.createReport({ reportedBy: sc.dids.alice, reasonType: REASONSPAM, - subject: { + // @ts-expect-error ComAtprotoModerationCreateReport.InputSchema['subject'] does not allow ChatBskyConvoDefs.MessageRef + subject: ((f: ChatBskyConvoDefs.MessageRef) => f)({ $type: 'chat.bsky.convo.defs#messageRef', did: sc.dids.carol, messageId: messageId1, convoId: 'testconvoid1', - }, + }), }) const reportB = await sc.createReport({ reportedBy: sc.dids.carol, reasonType: REASONOTHER, reason: 'defamation', - subject: { + // @ts-expect-error ComAtprotoModerationCreateReport.InputSchema['subject'] does not allow ChatBskyConvoDefs.MessageRef + subject: ((f: ChatBskyConvoDefs.MessageRef) => f)({ $type: 'chat.bsky.convo.defs#messageRef', did: sc.dids.carol, messageId: messageId2, - // @TODO convoId intentionally missing, restore once this behavior is deprecated - }, + // @ts-expect-error convoId intentionally missing, restore once this behavior is deprecated + convoId: undefined, + }), }) expect(forSnapshot([reportA, reportB])).toMatchSnapshot() const events = await ozone.ctx.db.db diff --git a/packages/pds/tests/preferences.test.ts b/packages/pds/tests/preferences.test.ts index cf3f2ebb6cc..99a028a8493 100644 --- a/packages/pds/tests/preferences.test.ts +++ b/packages/pds/tests/preferences.test.ts @@ -163,6 +163,7 @@ describe('user preferences', () => { { $type: 'app.bsky.actor.defs#adultContentPref', enabled: false }, { $type: 'com.atproto.server.defs#unknown', + // @ts-expect-error un-spec'ed prop hello: 'world', }, ], diff --git a/packages/pds/tests/seeds/basic.ts b/packages/pds/tests/seeds/basic.ts index aa843fcbaaa..dee78a8132a 100644 --- a/packages/pds/tests/seeds/basic.ts +++ b/packages/pds/tests/seeds/basic.ts @@ -61,7 +61,7 @@ export default async ( index: { byteStart: 0, byteEnd: 18 }, features: [ { - $type: `${ids.AppBskyRichtextFacet}#mention`, + $type: `${ids.AppBskyRichtextFacet}#mention` as const, did: alice, }, ],