|
| 1 | +import { |
| 2 | + mockPKC, |
| 3 | + createSubWithNoChallenge, |
| 4 | + generateMockPost, |
| 5 | + generateMockComment, |
| 6 | + publishWithExpectedResult, |
| 7 | + mockPKCNoDataPathWithOnlyKuboClient, |
| 8 | + resolveWhenConditionIsTrue, |
| 9 | + publishRandomPost |
| 10 | +} from "../../../../dist/node/test/test-util.js"; |
| 11 | +import { messages } from "../../../../dist/node/errors.js"; |
| 12 | +import { describe, it, beforeAll, afterAll } from "vitest"; |
| 13 | +import type { PKC } from "../../../../dist/node/pkc/pkc.js"; |
| 14 | +import type { LocalCommunity } from "../../../../dist/node/runtime/node/community/local-community.js"; |
| 15 | +import type { RpcLocalCommunity } from "../../../../dist/node/community/rpc-local-community.js"; |
| 16 | +import type { Comment } from "../../../../dist/node/publications/comment/comment.js"; |
| 17 | +import type { CommentIpfsWithCidDefined } from "../../../../dist/node/publications/comment/types.js"; |
| 18 | + |
| 19 | +describe.concurrent(`community.features.noReplyLinks`, async () => { |
| 20 | + let pkc: PKC; |
| 21 | + let remotePKC: PKC; |
| 22 | + let community: LocalCommunity | RpcLocalCommunity; |
| 23 | + let publishedPost: Comment; |
| 24 | + |
| 25 | + beforeAll(async () => { |
| 26 | + pkc = await mockPKC(); |
| 27 | + remotePKC = await mockPKCNoDataPathWithOnlyKuboClient(); |
| 28 | + community = await createSubWithNoChallenge({}, pkc); |
| 29 | + await community.start(); |
| 30 | + await resolveWhenConditionIsTrue({ toUpdate: community, predicate: async () => typeof community.updatedAt === "number" }); |
| 31 | + |
| 32 | + // Publish a post first (before enabling the feature) |
| 33 | + publishedPost = await publishRandomPost({ communityAddress: community.address, pkc: remotePKC }); |
| 34 | + }); |
| 35 | + |
| 36 | + afterAll(async () => { |
| 37 | + await community.delete(); |
| 38 | + await pkc.destroy(); |
| 39 | + await remotePKC.destroy(); |
| 40 | + }); |
| 41 | + |
| 42 | + it.sequential(`Feature is updated correctly in props`, async () => { |
| 43 | + expect(community.features).to.be.undefined; |
| 44 | + await community.edit({ features: { ...community.features, noReplyLinks: true } }); |
| 45 | + expect(community.features?.noReplyLinks).to.be.true; |
| 46 | + |
| 47 | + const remoteCommunity = await remotePKC.getCommunity({ address: community.address }); |
| 48 | + await remoteCommunity.update(); |
| 49 | + await resolveWhenConditionIsTrue({ |
| 50 | + toUpdate: remoteCommunity, |
| 51 | + predicate: async () => remoteCommunity.features?.noReplyLinks === true |
| 52 | + }); |
| 53 | + expect(remoteCommunity.features?.noReplyLinks).to.be.true; |
| 54 | + await remoteCommunity.stop(); |
| 55 | + }); |
| 56 | + |
| 57 | + it(`Can publish a post with link (noReplyLinks only blocks replies)`, async () => { |
| 58 | + const post = await generateMockPost({ |
| 59 | + communityAddress: community.address, |
| 60 | + pkc: remotePKC, |
| 61 | + postProps: { |
| 62 | + link: "https://example.com/article", |
| 63 | + content: "Just text" |
| 64 | + } |
| 65 | + }); |
| 66 | + await publishWithExpectedResult({ publication: post, expectedChallengeSuccess: true }); |
| 67 | + }); |
| 68 | + |
| 69 | + it(`Can't publish a reply with a non-media link`, async () => { |
| 70 | + const reply = await generateMockComment(publishedPost as CommentIpfsWithCidDefined, remotePKC, false, { |
| 71 | + link: "https://example.com/article" |
| 72 | + }); |
| 73 | + await publishWithExpectedResult({ |
| 74 | + publication: reply, |
| 75 | + expectedChallengeSuccess: false, |
| 76 | + expectedReason: messages.ERR_REPLY_HAS_LINK |
| 77 | + }); |
| 78 | + }); |
| 79 | + |
| 80 | + it(`Can't publish a reply with a media link`, async () => { |
| 81 | + const reply = await generateMockComment(publishedPost as CommentIpfsWithCidDefined, remotePKC, false, { |
| 82 | + link: "https://example.com/photo.jpg" |
| 83 | + }); |
| 84 | + await publishWithExpectedResult({ |
| 85 | + publication: reply, |
| 86 | + expectedChallengeSuccess: false, |
| 87 | + expectedReason: messages.ERR_REPLY_HAS_LINK |
| 88 | + }); |
| 89 | + }); |
| 90 | + |
| 91 | + it(`Can publish a reply without a link`, async () => { |
| 92 | + const reply = await generateMockComment(publishedPost as CommentIpfsWithCidDefined, remotePKC, false, { |
| 93 | + content: "Just text reply" |
| 94 | + }); |
| 95 | + await publishWithExpectedResult({ publication: reply, expectedChallengeSuccess: true }); |
| 96 | + }); |
| 97 | +}); |
0 commit comments