From ce013f99041c1929a306b74bde797efb3316ec64 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Mon, 18 Nov 2024 11:48:22 +0100 Subject: [PATCH] fmt --- api_tests/src/private_community.spec.ts | 71 +++++++++++++------------ 1 file changed, 38 insertions(+), 33 deletions(-) diff --git a/api_tests/src/private_community.spec.ts b/api_tests/src/private_community.spec.ts index 564fed196..1b2405dbe 100644 --- a/api_tests/src/private_community.spec.ts +++ b/api_tests/src/private_community.spec.ts @@ -1,6 +1,6 @@ jest.setTimeout(120000); -import { FollowCommunity } from "lemmy-js-client"; +import { FollowCommunity, LemmyHttp } from "lemmy-js-client"; import { alpha, setupLogins, @@ -50,7 +50,7 @@ test("Follow a private community", async () => { await resolveCommunity(user, community.community_view.community.actor_id) ).community; expect(betaCommunity).toBeDefined(); - expect(betaCommunity?.community.visibility).toBe('Private'); + expect(betaCommunity?.community.visibility).toBe("Private"); const betaCommunityId = betaCommunity!.community.id; const follow_form: FollowCommunity = { community_id: betaCommunityId, @@ -224,9 +224,8 @@ test("Follow a private community and receive activities", async () => { const alphaCommunityId = community.community_view.community.id; // follow with users from beta and gamma - const user = await registerUser(beta, betaUrl); const betaCommunity = ( - await resolveCommunity(user, community.community_view.community.actor_id) + await resolveCommunity(beta, community.community_view.community.actor_id) ).community; expect(betaCommunity).toBeDefined(); const betaCommunityId = betaCommunity!.community.id; @@ -234,7 +233,8 @@ test("Follow a private community and receive activities", async () => { community_id: betaCommunityId, follow: true, }; - await user.followCommunity(follow_form_beta); + await beta.followCommunity(follow_form_beta); + await approveFollower(alpha, alphaCommunityId); const gammaCommunityId = ( await resolveCommunity(gamma, community.community_view.community.actor_id) @@ -244,31 +244,11 @@ test("Follow a private community and receive activities", async () => { follow: true, }; await gamma.followCommunity(follow_form_gamma); + await approveFollower(alpha, alphaCommunityId); - // Wait for follow to federate, shown as pending - let pendingFollows1 = await waitUntil( - () => listCommunityPendingFollows(alpha), - f => f.items.length == 2, - ); - - // Approve the follow - const approve1 = await approveCommunityPendingFollow( - alpha, - alphaCommunityId, - pendingFollows1.items[0].person.id, - ); - expect(approve1.success).toBe(true); - const approve2 = await approveCommunityPendingFollow( - alpha, - alphaCommunityId, - pendingFollows1.items[1].person.id, - ); - expect(approve2.success).toBe(true); - - // Follow is confirmed // Follow is confirmed await waitUntil( - () => getCommunity(user, betaCommunityId), + () => getCommunity(beta, betaCommunityId), c => c.community_view.subscribed == "Subscribed", ); await waitUntil( @@ -286,17 +266,21 @@ test("Follow a private community and receive activities", async () => { // post and comment were federated to beta let posts = await waitUntil( - () => getPosts(user, 'All', betaCommunityId), + () => getPosts(beta, "All", betaCommunityId), c => c.posts.length == 1, ); expect(posts.posts[0].post.ap_id).toBe(post.post_view.post.ap_id); expect(posts.posts[0].post.name).toBe(post.post_view.post.name); let comments = await waitUntil( - () => getComments(user, posts.posts[0].post.id), + () => getComments(beta, posts.posts[0].post.id), c => c.comments.length == 1, ); - expect(comments.comments[0].comment.ap_id).toBe(comment.comment_view.comment.ap_id); - expect(comments.comments[0].comment.content).toBe(comment.comment_view.comment.content); + expect(comments.comments[0].comment.ap_id).toBe( + comment.comment_view.comment.ap_id, + ); + expect(comments.comments[0].comment.content).toBe( + comment.comment_view.comment.content, + ); }); test("Fetch remote content in private community", async () => { @@ -305,10 +289,16 @@ test("Fetch remote content in private community", async () => { expect(community.community_view.community.visibility).toBe("Private"); const alphaCommunityId = community.community_view.community.id; - // create post and comment const betaCommunityId = ( await resolveCommunity(beta, community.community_view.community.actor_id) ).community!.community.id; + const follow_form_beta: FollowCommunity = { + community_id: betaCommunityId, + follow: true, + }; + await beta.followCommunity(follow_form_beta); + + // beta creates post and comment const post = await createPost(beta, betaCommunityId); const post_id = post.post_view.post.id; expect(post_id).toBeDefined(); @@ -316,7 +306,7 @@ test("Fetch remote content in private community", async () => { const comment_id = comment.comment_view.comment.id; expect(comment_id).toBeDefined(); - // user is not following the community and cannot view nor create posts + // gamma is not following the community and cannot view nor create posts const user = await registerUser(gamma, betaUrl); const gammaCommunityId = ( await resolveCommunity(user, community.community_view.community.actor_id) @@ -340,12 +330,27 @@ test("Fetch remote content in private community", async () => { expect(approve.success).toBe(true); // now user can fetch posts and comments in community (using signed fetch), and create posts + console.log(1); await waitUntil( () => resolvePost(user, post.post_view.post), p => p?.post?.post.id != undefined, ); + console.log(2); const resolvedComment = ( await resolveComment(user, comment.comment_view.comment) ).comment; expect(resolvedComment?.comment.id).toBeDefined(); }); + +async function approveFollower(user: LemmyHttp, community_id: number) { + let pendingFollows1 = await waitUntil( + () => listCommunityPendingFollows(user), + f => f.items.length == 1, + ); + const approve = await approveCommunityPendingFollow( + alpha, + community_id, + pendingFollows1.items[0].person.id, + ); + expect(approve.success).toBe(true); +}