From 68e0289739b0c17f40272fe9e7dd064697c01dc8 Mon Sep 17 00:00:00 2001 From: tomcasaburi Date: Wed, 11 Mar 2026 20:35:28 +0800 Subject: [PATCH] fix: restore CI after address refactor follow-ups --- src/hooks/accounts/accounts.test.ts | 27 ++++++------ src/hooks/accounts/accounts.ts | 1 + .../communities/communities-store.test.ts | 42 ++++++++++++------- test/test-server/index.js | 2 +- 4 files changed, 44 insertions(+), 28 deletions(-) diff --git a/src/hooks/accounts/accounts.test.ts b/src/hooks/accounts/accounts.test.ts index 970bf91..04cb197 100644 --- a/src/hooks/accounts/accounts.test.ts +++ b/src/hooks/accounts/accounts.test.ts @@ -1316,10 +1316,11 @@ describe("accounts", () => { test("useEditedComment has edited comment", async () => { const rendered2 = renderHook(() => { const comment = useComment({ commentCid: "Qm..." }); - const editedComment = useEditedComment({ comment }); - return editedComment; + return { comment, ...useEditedComment({ comment }) }; }); - await waitFor(() => rendered2.result.current.editedComment); + const waitForEditedComment = testUtils.createWaitFor(rendered2); + await waitForEditedComment(() => rendered2.result.current.comment.cid === "Qm..."); + await waitForEditedComment(() => rendered2.result.current.editedComment); expect(rendered2.result.current.editedComment).not.toBe(undefined); expect( rendered2.result.current.pendingEdits.spoiler || @@ -2292,10 +2293,10 @@ describe("accounts", () => { beforeEach(async () => { rendered = renderHook(() => { - const { accountCommunities } = useAccountCommunities(); + const { accountCommunities, state, error, errors } = useAccountCommunities(); const account = useAccount(); const { setAccount } = accountsActions; - return { accountCommunities, setAccount, account }; + return { accountCommunities, state, error, errors, setAccount, account }; }); waitFor = testUtils.createWaitFor(rendered); @@ -2382,7 +2383,7 @@ describe("accounts", () => { test("useAccountCommunities reflects in-flight community fetches", async () => { await waitFor(() => rendered.result.current.accountCommunities["community address 1"]); const { account, setAccount } = rendered.result.current; - const createCommunityOrig = account.plebbit.createCommunity; + const createCommunityOrig = Plebbit.prototype.createCommunity; const slowCommunity = await createCommunityOrig.call(account.plebbit, { address: "slow community address", }); @@ -2390,11 +2391,11 @@ describe("accounts", () => { const slowCommunityPromise = new Promise((resolve) => { resolveSlowCommunity = resolve; }); - account.plebbit.createCommunity = vi.fn(async (options: any) => { + Plebbit.prototype.createCommunity = vi.fn(async function (options: any) { if (options.address === "slow community address") { return slowCommunityPromise; } - return createCommunityOrig.call(account.plebbit, options); + return createCommunityOrig.call(this, options); }); try { @@ -2418,19 +2419,19 @@ describe("accounts", () => { resolveSlowCommunity?.(slowCommunity); await waitFor(() => rendered.result.current.state === "succeeded"); } finally { - account.plebbit.createCommunity = createCommunityOrig; + Plebbit.prototype.createCommunity = createCommunityOrig; } }); test("useAccountCommunities propagates failed community fetches", async () => { await waitFor(() => rendered.result.current.accountCommunities["community address 1"]); const { account, setAccount } = rendered.result.current; - const createCommunityOrig = account.plebbit.createCommunity; - account.plebbit.createCommunity = vi.fn(async (options: any) => { + const createCommunityOrig = Plebbit.prototype.createCommunity; + Plebbit.prototype.createCommunity = vi.fn(async function (options: any) { if (options.address === "failing community address") { throw new Error("community fetch failed"); } - return createCommunityOrig.call(account.plebbit, options); + return createCommunityOrig.call(this, options); }); try { @@ -2450,7 +2451,7 @@ describe("accounts", () => { "community fetch failed", ); } finally { - account.plebbit.createCommunity = createCommunityOrig; + Plebbit.prototype.createCommunity = createCommunityOrig; } }); }); diff --git a/src/hooks/accounts/accounts.ts b/src/hooks/accounts/accounts.ts index 73a5292..a6f398b 100644 --- a/src/hooks/accounts/accounts.ts +++ b/src/hooks/accounts/accounts.ts @@ -602,6 +602,7 @@ export function useEditedComment(options?: UseEditedCommentOptions): UseEditedCo "signer", "commentCid", "communityAddress", + "subplebbitAddress", "timestamp", ]); diff --git a/src/stores/communities/communities-store.test.ts b/src/stores/communities/communities-store.test.ts index fb6dbb3..6bc5cb4 100644 --- a/src/stores/communities/communities-store.test.ts +++ b/src/stores/communities/communities-store.test.ts @@ -137,22 +137,36 @@ describe("communities store", () => { const address = "owner-retry-address"; const createOrig = mockAccount.plebbit.createCommunity; const communitiesOrig = mockAccount.plebbit.communities; + const ownCommunitiesDescriptor = Object.getOwnPropertyDescriptor( + mockAccount.plebbit, + "communities", + ); const resolvedCommunity = await createOrig.call(mockAccount.plebbit, { address }); - mockAccount.plebbit.createCommunity = vi - .fn() - .mockRejectedValueOnce(new Error("owner create failed")) - .mockRejectedValueOnce(new Error("fetch create failed")) - .mockResolvedValueOnce(resolvedCommunity); - mockAccount.plebbit.communities = [...communitiesOrig, address]; - - await expect( - communitiesStore.getState().addCommunityToStore(address, mockAccount), - ).rejects.toThrow("fetch create failed"); - await communitiesStore.getState().addCommunityToStore(address, mockAccount); + try { + mockAccount.plebbit.createCommunity = vi + .fn() + .mockRejectedValueOnce(new Error("owner create failed")) + .mockRejectedValueOnce(new Error("fetch create failed")) + .mockResolvedValueOnce(resolvedCommunity); + Object.defineProperty(mockAccount.plebbit, "communities", { + configurable: true, + get: () => [...communitiesOrig, address], + }); + + await expect( + communitiesStore.getState().addCommunityToStore(address, mockAccount), + ).rejects.toThrow("fetch create failed"); + await communitiesStore.getState().addCommunityToStore(address, mockAccount); - expect(communitiesStore.getState().communities[address]).toBeDefined(); - mockAccount.plebbit.createCommunity = createOrig; - mockAccount.plebbit.communities = communitiesOrig; + expect(communitiesStore.getState().communities[address]).toBeDefined(); + } finally { + mockAccount.plebbit.createCommunity = createOrig; + if (ownCommunitiesDescriptor) { + Object.defineProperty(mockAccount.plebbit, "communities", ownCommunitiesDescriptor); + } else { + delete (mockAccount.plebbit as any).communities; + } + } }); test("addCommunityToStore throws generic Error when community is undefined without thrown error", async () => { diff --git a/test/test-server/index.js b/test/test-server/index.js index a2ff389..3ec46e5 100644 --- a/test/test-server/index.js +++ b/test/test-server/index.js @@ -67,7 +67,7 @@ const plebbitDataPath = getTmpFolderPath(); const comment = await plebbit2.createComment({ title: "comment title", content: "comment content", - communityAddress: signer.address, + subplebbitAddress: signer.address, signer, author: { address: signer.address }, });