diff --git a/core/src/events/content-tagger.test.ts b/core/src/events/content-tagger.test.ts index 2d51d7342..993dfab18 100644 --- a/core/src/events/content-tagger.test.ts +++ b/core/src/events/content-tagger.test.ts @@ -1,3 +1,4 @@ +import { describe, expect, it } from "vitest"; import { generateContentTags } from "./content-tagger"; import type { ContentTaggingOptions, NDKEvent, NDKTag } from "./index.js"; @@ -199,7 +200,7 @@ describe("await generateContentTags", () => { ]); }); - it("copies p-tags from target event when copyPTagsFromTarget is true", async () => { + it("do not copy p-tags from target event when copyPTagsFromTarget is true but pubkeys are invalid", async () => { const content = "Reply to event"; const opts: ContentTaggingOptions = { copyPTagsFromTarget: true }; const mockEvent = { @@ -216,9 +217,29 @@ describe("await generateContentTags", () => { const { tags: processedTags } = await generateContentTags(content, [], opts, mockEvent); + expect(processedTags).toEqual([]); + }); + + it("copies p-tags from target event when copyPTagsFromTarget is true and pubkeys are valid", async () => { + const content = "Reply to event"; + const opts: ContentTaggingOptions = { copyPTagsFromTarget: true }; + const mockEvent = { + getMatchingTags: (tag: string) => { + if (tag === "p") { + return [ + ["p", "fa984bd7dbb282f07e16e7ae87b26a2a7b9b90b7246a44771f0cf5ae58018f52"], + ["p", "b190175cef407c593f17c155480eda1a2ee7f6c84378eef0e97353f87ee59300"], + ]; + } + return []; + }, + } as unknown as NDKEvent; + + const { tags: processedTags } = await generateContentTags(content, [], opts, mockEvent); + expect(processedTags).toEqual([ - ["p", "pubkey1"], - ["p", "pubkey2"], + ["p", "fa984bd7dbb282f07e16e7ae87b26a2a7b9b90b7246a44771f0cf5ae58018f52"], + ["p", "b190175cef407c593f17c155480eda1a2ee7f6c84378eef0e97353f87ee59300"], ]); }); diff --git a/core/src/events/encryption.test.ts b/core/src/events/encryption.test.ts index af1323c08..c8c873f91 100644 --- a/core/src/events/encryption.test.ts +++ b/core/src/events/encryption.test.ts @@ -25,12 +25,12 @@ class MockCacheAdapter implements NDKCacheAdapter { return Promise.resolve(); } - getDecryptedEvent(eventId: string): NDKEvent | null { - return this.decryptedEvents.get(eventId) || null; + getDecryptedEvent(wrapperId: string): NDKEvent | null { + return this.decryptedEvents.get(wrapperId) || null; } - addDecryptedEvent(event: NDKEvent): void { - this.decryptedEvents.set(event.id, event); + addDecryptedEvent(wrapperId: string, decryptedEvent: NDKEvent): void { + this.decryptedEvents.set(wrapperId, decryptedEvent); } } @@ -369,8 +369,7 @@ describe("NDKEvent encryption (Nip44 & Nip59)", () => { vi.spyOn(giftWrappingModule, "giftWrap").mockImplementation(async (event, _recipient, _signer, params = {}) => { const method = params.scheme === "nip04" ? "nip04_encrypt" : "nip44_encrypt"; mockSendRequest("", method, {}, 0, () => {}); - const wrapped = new NDKEvent(event.ndk); - return wrapped; + return new NDKEvent(event.ndk); }); await giftWrappingModule.giftWrap(message, receiveUser, send46Signer); @@ -407,12 +406,11 @@ describe("NDKEvent encryption (Nip44 & Nip59)", () => { // Set up mock cache adapter const mockCache = new MockCacheAdapter(); - mockCache.addDecryptedEvent(decryptedEvent); + mockCache.addDecryptedEvent(encryptedEvent.id, decryptedEvent); fixture.ndk.cacheAdapter = mockCache; // Spy on cache methods const getDecryptedEventSpy = vi.spyOn(mockCache, "getDecryptedEvent"); - const _addDecryptedEventSpy = vi.spyOn(mockCache, "addDecryptedEvent"); // Mock the decrypt function for signer to verify it's not called const decryptSpy = vi.spyOn(receiveSigner, "decrypt"); @@ -465,7 +463,7 @@ describe("NDKEvent encryption (Nip44 & Nip59)", () => { expect(getDecryptedEventSpy).toHaveBeenCalledWith(encryptedEvent.id); // Verify the decrypted event was cached - expect(addDecryptedEventSpy).toHaveBeenCalledWith(encryptedEvent); + expect(addDecryptedEventSpy).toHaveBeenCalledWith(encryptedEvent.id, encryptedEvent); // Verify content is correct expect(encryptedEvent.content).toBe(original); diff --git a/core/src/events/gift-wrapping.test.ts b/core/src/events/gift-wrapping.test.ts index fcc1c08f1..472eafe34 100644 --- a/core/src/events/gift-wrapping.test.ts +++ b/core/src/events/gift-wrapping.test.ts @@ -1,24 +1,24 @@ import { beforeEach, describe, expect, it } from "vitest"; -import { NDK } from "../ndk/index.js"; -import { NDKPrivateKeySigner } from "../signers/private-key/index.js"; -import type { NDKCacheAdapter, NDKEventId } from "../cache/index.js"; +import type { NDKCacheAdapter } from "../cache"; +import { NDK } from "../ndk"; +import { NDKPrivateKeySigner } from "../signers/private-key"; +import { giftUnwrap, giftWrap } from "./gift-wrapping.js"; import { NDKEvent } from "./index.js"; -import { NDKKind } from "./kinds/index.js"; -import { giftWrap, giftUnwrap } from "./gift-wrapping.js"; +import { NDKKind } from "./kinds"; // Mock cache adapter to track cache operations class MockCacheAdapter implements Partial { public locking = false; - private cache = new Map(); + private cache = new Map(); public getDecryptedEventCalls: string[] = []; public addDecryptedEventCalls: Array<{ wrapperId: string; rumorId: string }> = []; - async getDecryptedEvent(wrapperId: NDKEventId): Promise { + async getDecryptedEvent(wrapperId: NDKEvent["id"]): Promise { this.getDecryptedEventCalls.push(wrapperId); return this.cache.get(wrapperId) ?? null; } - async addDecryptedEvent(wrapperId: NDKEventId, decryptedEvent: NDKEvent): Promise { + async addDecryptedEvent(wrapperId: NDKEvent["id"], decryptedEvent: NDKEvent): Promise { this.addDecryptedEventCalls.push({ wrapperId, rumorId: decryptedEvent.id }); this.cache.set(wrapperId, decryptedEvent); } diff --git a/core/src/events/kinds/follow-pack.test.ts b/core/src/events/kinds/follow-pack.test.ts index 143bcf651..160e96041 100644 --- a/core/src/events/kinds/follow-pack.test.ts +++ b/core/src/events/kinds/follow-pack.test.ts @@ -90,12 +90,26 @@ describe("NDKFollowPack", () => { }); }); - it("should get/set pubkeys and manipulate p tags", () => { + it("should get/set pubkeys and manipulate p tags if pubkeys are invalid", () => { const fp = new NDKFollowPack(); expect(fp.pubkeys).toEqual([]); fp.pubkeys = ["pk1", "pk2"]; - expect(fp.pubkeys).toEqual(["pk1", "pk2"]); + expect(fp.pubkeys).toEqual([]); + }); + + it("should get/set pubkeys and manipulate p tags are valid", () => { + const fp = new NDKFollowPack(); + expect(fp.pubkeys).toEqual([]); + + fp.pubkeys = [ + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", + ]; + expect(fp.pubkeys).toEqual([ + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", + ]); expect(fp.tags.filter((t) => t[0] === "p").length).toBe(2); fp.pubkeys = []; diff --git a/core/src/events/kinds/interest-list.test.ts b/core/src/events/kinds/interest-list.test.ts index 8dbb49846..d02626fc6 100644 --- a/core/src/events/kinds/interest-list.test.ts +++ b/core/src/events/kinds/interest-list.test.ts @@ -1,6 +1,6 @@ -import { beforeEach, describe, expect, test } from "bun:test"; -import { NDKEvent } from "../../events/index.js"; -import { NDK } from "../../ndk/index.js"; +import { beforeEach, describe, expect, test } from "vitest"; +import { NDK } from "../../ndk"; +import { NDKEvent } from "../index"; import { NDKKind } from "./index.js"; import { NDKInterestList } from "./interest-list.js"; @@ -29,6 +29,18 @@ describe("NDKInterestList", () => { expect(interests).toEqual(["nostr", "bitcoin", "technology"]); }); + test("filters out falsy interest tag values", () => { + const list = new NDKInterestList(ndk); + list.tags = [ + ["t", "nostr"], + ["t", ""], + ["t", undefined as any], + ["t", "bitcoin"], + ]; + + expect(list.interests).toEqual(["nostr", "bitcoin"]); + }); + test("sets interests replacing existing ones", () => { const list = new NDKInterestList(ndk); list.tags = [ @@ -51,6 +63,35 @@ describe("NDKInterestList", () => { expect(list.interests).toEqual(["nostr", "bitcoin"]); }); + test("removeInterest is a no-op when interest does not exist", () => { + const list = new NDKInterestList(ndk); + list.tags = [ + ["t", "nostr"], + ["title", "My Interests"], + ["t", "bitcoin"], + ]; + + const beforeTags = list.tags.map((t) => [...t]); + + list.removeInterest("technology"); + + expect(list.tags).toEqual(beforeTags); + expect(list.interests).toEqual(["nostr", "bitcoin"]); + }); + + test("removes only the first matching interest tag", () => { + const list = new NDKInterestList(ndk); + list.tags = [ + ["t", "nostr"], + ["t", "nostr"], + ["t", "bitcoin"], + ]; + + list.removeInterest("nostr"); + + expect(list.interests).toEqual(["nostr", "bitcoin"]); + }); + test("removes interest", () => { const list = new NDKInterestList(ndk); list.interests = ["nostr", "bitcoin", "technology"]; @@ -99,22 +140,32 @@ describe("NDKInterestList", () => { expect(list.interestSetReferences).toEqual([]); }); - test("updates created_at when adding interest", () => { + test("does not set created_at when adding interest (local mutation only)", () => { const list = new NDKInterestList(ndk); - const before = Math.floor(Date.now() / 1000); + expect(list.created_at).toBeUndefined(); list.addInterest("nostr"); - expect(list.created_at).toBeGreaterThanOrEqual(before); + expect(list.created_at).toBeUndefined(); }); - test("updates created_at when removing interest", () => { + test("does not set created_at when removing interest (local mutation only)", () => { const list = new NDKInterestList(ndk); list.interests = ["nostr", "bitcoin"]; - const before = Math.floor(Date.now() / 1000); + expect(list.created_at).toBeUndefined(); list.removeInterest("nostr"); - expect(list.created_at).toBeGreaterThanOrEqual(before); + expect(list.created_at).toBeUndefined(); + }); + + test("does not set created_at when removing a missing interest (no-op)", () => { + const list = new NDKInterestList(ndk); + list.interests = ["nostr", "bitcoin"]; + expect(list.created_at).toBeUndefined(); + + list.removeInterest("technology"); + + expect(list.created_at).toBeUndefined(); }); }); diff --git a/core/src/events/kinds/nutzap/validation.test.ts b/core/src/events/kinds/nutzap/validation.test.ts index 7eb96e24c..be4d548d8 100644 --- a/core/src/events/kinds/nutzap/validation.test.ts +++ b/core/src/events/kinds/nutzap/validation.test.ts @@ -1,7 +1,7 @@ -import { describe, it, expect, beforeAll } from "bun:test"; -import { NDK } from "../../../ndk/index.js"; -import { NDKPrivateKeySigner } from "../../../signers/private-key/index.js"; -import { mockNutzap, mockProof } from "../../../../test/mocks/nutzaps.js"; +import { beforeAll, describe, expect, it } from "vitest"; +import { mockNutzap, mockProof } from "../../../../test"; +import { NDK } from "../../../ndk"; +import { NDKPrivateKeySigner } from "../../../signers/private-key"; import { NDKNutzap } from "./index.js"; import { NutzapValidationCode, NutzapValidationSeverity } from "./validation.js"; @@ -64,7 +64,7 @@ describe("NIP-61 Nutzap Validation", () => { expect.objectContaining({ code: NutzapValidationCode.NO_PROOFS, severity: NutzapValidationSeverity.ERROR, - }) + }), ); }); @@ -80,7 +80,7 @@ describe("NIP-61 Nutzap Validation", () => { expect.objectContaining({ code: NutzapValidationCode.NO_RECIPIENT, severity: NutzapValidationSeverity.ERROR, - }) + }), ); }); @@ -100,7 +100,7 @@ describe("NIP-61 Nutzap Validation", () => { expect.objectContaining({ code: NutzapValidationCode.MULTIPLE_RECIPIENTS, severity: NutzapValidationSeverity.ERROR, - }) + }), ); }); @@ -116,7 +116,7 @@ describe("NIP-61 Nutzap Validation", () => { expect.objectContaining({ code: NutzapValidationCode.NO_MINT, severity: NutzapValidationSeverity.ERROR, - }) + }), ); }); @@ -137,7 +137,7 @@ describe("NIP-61 Nutzap Validation", () => { expect.objectContaining({ code: NutzapValidationCode.MULTIPLE_MINTS, severity: NutzapValidationSeverity.ERROR, - }) + }), ); }); @@ -156,7 +156,7 @@ describe("NIP-61 Nutzap Validation", () => { expect.objectContaining({ code: NutzapValidationCode.MULTIPLE_EVENT_TAGS, severity: NutzapValidationSeverity.ERROR, - }) + }), ); }); @@ -181,7 +181,7 @@ describe("NIP-61 Nutzap Validation", () => { code: NutzapValidationCode.MALFORMED_PROOF_SECRET, severity: NutzapValidationSeverity.ERROR, proofIndex: 0, - }) + }), ); }); }); @@ -206,7 +206,7 @@ describe("NIP-61 Nutzap Validation", () => { code: NutzapValidationCode.MISSING_EVENT_TAG_IN_PROOF, severity: NutzapValidationSeverity.WARNING, proofIndex: 0, - }) + }), ); }); @@ -216,7 +216,12 @@ describe("NIP-61 Nutzap Validation", () => { nutzap.recipientPubkey = recipientPubkey; nutzap.tags.push(["e", "event1"]); // Create proof with different e tag - nutzap.proofs = [mockProof("mint", 100, recipientPubkey, [["e", "event2"], ["P", senderPubkey]])]; + nutzap.proofs = [ + mockProof("mint", 100, recipientPubkey, [ + ["e", "event2"], + ["P", senderPubkey], + ]), + ]; await nutzap.sign(senderSigner); const result = nutzap.validateNIP61(); @@ -228,7 +233,7 @@ describe("NIP-61 Nutzap Validation", () => { code: NutzapValidationCode.MISMATCHED_EVENT_TAG_IN_PROOF, severity: NutzapValidationSeverity.WARNING, proofIndex: 0, - }) + }), ); }); @@ -251,7 +256,7 @@ describe("NIP-61 Nutzap Validation", () => { code: NutzapValidationCode.MISSING_SENDER_TAG_IN_PROOF, severity: NutzapValidationSeverity.WARNING, proofIndex: 0, - }) + }), ); }); @@ -262,7 +267,12 @@ describe("NIP-61 Nutzap Validation", () => { nutzap.recipientPubkey = recipientPubkey; nutzap.tags.push(["e", eventId]); // Create proof with wrong P tag - nutzap.proofs = [mockProof("mint", 100, recipientPubkey, [["e", eventId], ["P", "wrong_pubkey"]])]; + nutzap.proofs = [ + mockProof("mint", 100, recipientPubkey, [ + ["e", eventId], + ["P", "wrong_pubkey"], + ]), + ]; await nutzap.sign(senderSigner); const result = nutzap.validateNIP61(); @@ -274,7 +284,7 @@ describe("NIP-61 Nutzap Validation", () => { code: NutzapValidationCode.MISMATCHED_SENDER_TAG_IN_PROOF, severity: NutzapValidationSeverity.WARNING, proofIndex: 0, - }) + }), ); }); @@ -293,7 +303,7 @@ describe("NIP-61 Nutzap Validation", () => { expect.objectContaining({ code: NutzapValidationCode.NO_EVENT_TAG_IN_EVENT, severity: NutzapValidationSeverity.WARNING, - }) + }), ); }); }); diff --git a/core/src/events/kinds/relay-feed-list.test.ts b/core/src/events/kinds/relay-feed-list.test.ts index 29daaac1d..d822ad228 100644 --- a/core/src/events/kinds/relay-feed-list.test.ts +++ b/core/src/events/kinds/relay-feed-list.test.ts @@ -1,6 +1,6 @@ -import { describe, expect, test } from "bun:test"; -import { NDK } from "../../ndk/index.js"; -import { NDKPrivateKeySigner } from "../../signers/private-key/index.js"; +import { describe, expect, test } from "vitest"; +import { NDK } from "../../ndk"; +import { NDKPrivateKeySigner } from "../../signers/private-key"; import { NDKKind } from "./index.js"; import { NDKRelayFeedList } from "./relay-feed-list.js"; @@ -18,8 +18,7 @@ describe("NDKRelayFeedList", () => { }); test("adds relay URLs", async () => { - const signer = NDKPrivateKeySigner.generate(); - ndk.signer = signer; + ndk.signer = NDKPrivateKeySigner.generate(); const list = new NDKRelayFeedList(ndk); await list.addRelay("wss://relay.damus.io"); diff --git a/core/src/events/nip19.test.ts b/core/src/events/nip19.test.ts index a777628bc..f9cbdf702 100644 --- a/core/src/events/nip19.test.ts +++ b/core/src/events/nip19.test.ts @@ -1,6 +1,7 @@ -import { NDKEvent } from "src"; +import { beforeAll, describe, expect, it } from "vitest"; import { TestFixture } from "../../test"; import { NDKRelay } from "../relay"; +import { NDKEvent } from "./index"; let fixture: TestFixture; @@ -24,7 +25,7 @@ describe("NDKEvent", () => { const event = new NDKEvent(fixture.ndk, { kind: 30000, pubkey }); event.tags.push(["d", "1234"]); // Cast to any to avoid type issues with NDKRelay - event.relay = new NDKRelay("wss://relay.f7z.io/", undefined, fixture.ndk) as any; + event.relay = new NDKRelay("wss://relay.f7z.io/", undefined, fixture.ndk); const a = event.encode(); expect(a).toBe( @@ -37,7 +38,7 @@ describe("NDKEvent", () => { const event = new NDKEvent(fixture.ndk, { kind: 1, pubkey }); event.tags.push(["e", "1234"]); // Cast to any to avoid type issues with NDKRelay - event.relay = new NDKRelay("wss://relay.f7z.io/", undefined, fixture.ndk) as any; + event.relay = new NDKRelay("wss://relay.f7z.io/", undefined, fixture.ndk); const a = event.encode(); expect(a).toBe( diff --git a/core/src/events/repost.test.ts b/core/src/events/repost.test.ts index 0ddb10a10..a14167a80 100644 --- a/core/src/events/repost.test.ts +++ b/core/src/events/repost.test.ts @@ -1,7 +1,8 @@ -import { EventGenerator } from "../../test"; -import { NDK } from "../ndk"; -import { NDKPrivateKeySigner } from "../signers/private-key"; -import { NDKEvent } from "."; +import {beforeEach, describe, expect, it} from "vitest"; +import {EventGenerator} from "../../test"; +import {NDK} from "../ndk"; +import {NDKPrivateKeySigner} from "../signers/private-key"; +import {NDKEvent} from "."; const ndk = new NDK({ signer: NDKPrivateKeySigner.generate(), diff --git a/core/src/events/serializer.test.ts b/core/src/events/serializer.test.ts index 6e50e5179..73fc8c443 100644 --- a/core/src/events/serializer.test.ts +++ b/core/src/events/serializer.test.ts @@ -1,4 +1,4 @@ -import { describe, expect, it } from "bun:test"; +import { describe, expect, it } from "vitest"; import { NDKEvent } from "./index.js"; import { serialize } from "./serializer.js"; @@ -24,7 +24,7 @@ describe("Event Serializer Validation", () => { created_at: Math.floor(Date.now() / 1000), pubkey: "a".repeat(64), tags: [], - } as any; + }; expect(() => serialize.call(rawEvent)).toThrow( "Can't serialize event with invalid properties: kind (must be number, got undefined)", @@ -33,7 +33,8 @@ describe("Event Serializer Validation", () => { it("should throw detailed error for invalid kind type", () => { const event = new NDKEvent(undefined, { - kind: "1" as any, + // @ts-expect-error intentional + kind: "1", content: "test content", created_at: Math.floor(Date.now() / 1000), pubkey: "a".repeat(64), @@ -52,7 +53,7 @@ describe("Event Serializer Validation", () => { created_at: Math.floor(Date.now() / 1000), pubkey: "a".repeat(64), tags: [], - } as any; + }; expect(() => serialize.call(rawEvent)).toThrow( "Can't serialize event with invalid properties: content (must be string, got undefined)", @@ -62,7 +63,8 @@ describe("Event Serializer Validation", () => { it("should throw detailed error for invalid content type", () => { const event = new NDKEvent(undefined, { kind: 1, - content: 123 as any, + // @ts-expect-error intentional + content: 123, created_at: Math.floor(Date.now() / 1000), pubkey: "a".repeat(64), tags: [], @@ -80,7 +82,7 @@ describe("Event Serializer Validation", () => { content: "test", pubkey: "a".repeat(64), tags: [], - } as any; + }; expect(() => serialize.call(rawEvent)).toThrow( "Can't serialize event with invalid properties: created_at (must be number, got undefined)", @@ -93,7 +95,7 @@ describe("Event Serializer Validation", () => { content: "test", created_at: Math.floor(Date.now() / 1000), tags: [], - } as any; + }; expect(() => serialize.call(rawEvent)).toThrow( "Can't serialize event with invalid properties: pubkey (must be string, got undefined)", @@ -106,7 +108,8 @@ describe("Event Serializer Validation", () => { content: "test", created_at: Math.floor(Date.now() / 1000), pubkey: "a".repeat(64), - tags: "not-an-array" as any, + // @ts-expect-error intentional + tags: "not-an-array", }); expect(() => serialize.call(event)).toThrow( @@ -120,7 +123,8 @@ describe("Event Serializer Validation", () => { content: "test", created_at: Math.floor(Date.now() / 1000), pubkey: "a".repeat(64), - tags: ["invalid" as any], + // @ts-expect-error intentional + tags: ["invalid"], }); expect(() => serialize.call(event)).toThrow( @@ -134,7 +138,8 @@ describe("Event Serializer Validation", () => { content: "test", created_at: Math.floor(Date.now() / 1000), pubkey: "a".repeat(64), - tags: [["p", 123 as any]], + // @ts-expect-error intentional + tags: [["p", 123]], }); expect(() => serialize.call(event)).toThrow( @@ -146,11 +151,11 @@ describe("Event Serializer Validation", () => { // Test with a raw event object that bypasses NDKEvent defaults // The validation fails fast, so only the first error is reported const rawEvent = { - kind: "invalid" as any, - content: 123 as any, + kind: "invalid", + content: 123, pubkey: "a".repeat(64), tags: [], - } as any; + }; expect(() => serialize.call(rawEvent)).toThrow("kind (must be number, got string)"); }); @@ -162,7 +167,7 @@ describe("Event Serializer Validation", () => { created_at: Math.floor(Date.now() / 1000), pubkey: "a".repeat(64), tags: [], - } as any; + }; expect(() => serialize.call(rawEvent)).toThrow(/"kind":"invalid-kind"/); }); diff --git a/core/src/events/signed-event-types.test.ts b/core/src/events/signed-event-types.test.ts index ba3cdb9f8..3b66c15e1 100644 --- a/core/src/events/signed-event-types.test.ts +++ b/core/src/events/signed-event-types.test.ts @@ -1,5 +1,5 @@ import { describe, expect, it } from "vitest"; -import { NDK } from "../ndk/index.js"; +import { NDK } from "../ndk"; import { assertSignedEvent, createSignedEvent, diff --git a/core/src/events/wrap.test.ts b/core/src/events/wrap.test.ts index 80403ea12..9579ebf63 100644 --- a/core/src/events/wrap.test.ts +++ b/core/src/events/wrap.test.ts @@ -1,4 +1,5 @@ import { beforeEach, describe, expect, it } from "vitest"; +import type { NDK } from "../ndk"; import type { NostrEvent } from "./index.js"; import { NDKEvent } from "./index.js"; import { getRegisteredEventClasses, registerEventClass, unregisterEventClass, wrapEvent } from "./wrap.js"; @@ -10,7 +11,7 @@ class TestCustomEvent extends NDKEvent { return new TestCustomEvent(event.ndk, event); } - constructor(ndk: any, rawEvent?: NostrEvent | NDKEvent) { + constructor(ndk: NDK, rawEvent?: NostrEvent | NDKEvent) { super(ndk, rawEvent); this.kind ??= 99999; } @@ -18,11 +19,6 @@ class TestCustomEvent extends NDKEvent { get customProperty(): string | undefined { return this.tagValue("custom"); } - - set customProperty(value: string | undefined) { - this.removeTag("custom"); - if (value) this.tags.push(["custom", value]); - } } class TestMultiKindEvent extends NDKEvent { @@ -32,7 +28,7 @@ class TestMultiKindEvent extends NDKEvent { return new TestMultiKindEvent(event.ndk, event); } - constructor(ndk: any, rawEvent?: NostrEvent | NDKEvent) { + constructor(ndk: NDK, rawEvent?: NostrEvent | NDKEvent) { super(ndk, rawEvent); this.kind ??= 88888; } @@ -42,9 +38,9 @@ describe("Event Class Registration", () => { beforeEach(() => { // Clean up any registered classes const registered = getRegisteredEventClasses(); - for (const klass of registered) { + registered.forEach((klass) => { unregisterEventClass(klass); - } + }); }); it("should register and use custom event class", () => {