This commit is contained in:
phiresky 2024-05-31 11:56:43 +02:00
parent 3784b7f3d6
commit c2d18d3ca3
3 changed files with 57 additions and 17 deletions

View file

@ -26,14 +26,22 @@ test("Follow local community", async () => {
// Make sure the follow response went through // Make sure the follow response went through
expect(follow.community_view.community.local).toBe(true); expect(follow.community_view.community.local).toBe(true);
expect(follow.community_view.subscribed).toBe("Subscribed"); expect(follow.community_view.subscribed).toBe("Subscribed");
expect(follow.community_view.counts.subscribers).toBe(community.counts.subscribers + 1); expect(follow.community_view.counts.subscribers).toBe(
expect(follow.community_view.counts.subscribers_local).toBe(community.counts.subscribers_local + 1); community.counts.subscribers + 1,
);
expect(follow.community_view.counts.subscribers_local).toBe(
community.counts.subscribers_local + 1,
);
// Test an unfollow // Test an unfollow
let unfollow = await followCommunity(user, false, community.community.id); let unfollow = await followCommunity(user, false, community.community.id);
expect(unfollow.community_view.subscribed).toBe("NotSubscribed"); expect(unfollow.community_view.subscribed).toBe("NotSubscribed");
expect(unfollow.community_view.counts.subscribers).toBe(community.counts.subscribers); expect(unfollow.community_view.counts.subscribers).toBe(
expect(unfollow.community_view.counts.subscribers_local).toBe(community.counts.subscribers_local); community.counts.subscribers,
);
expect(unfollow.community_view.counts.subscribers_local).toBe(
community.counts.subscribers_local,
);
}); });
test("Follow federated community", async () => { test("Follow federated community", async () => {
@ -41,14 +49,17 @@ test("Follow federated community", async () => {
const betaCommunityInitial = ( const betaCommunityInitial = (
await waitUntil( await waitUntil(
() => resolveBetaCommunity(alpha), () => resolveBetaCommunity(alpha),
c => c => !!c.community && c.community?.counts.subscribers >= 1,
!!c.community && (c.community?.counts.subscribers >= 1)
) )
).community; ).community;
if (!betaCommunityInitial) { if (!betaCommunityInitial) {
throw "Missing beta community"; throw "Missing beta community";
} }
let follow = await followCommunity(alpha, true, betaCommunityInitial.community.id); let follow = await followCommunity(
alpha,
true,
betaCommunityInitial.community.id,
);
expect(follow.community_view.subscribed).toBe("Pending"); expect(follow.community_view.subscribed).toBe("Pending");
const betaCommunity = ( const betaCommunity = (
await waitUntil( await waitUntil(
@ -61,16 +72,22 @@ test("Follow federated community", async () => {
expect(betaCommunity?.community.local).toBe(false); expect(betaCommunity?.community.local).toBe(false);
expect(betaCommunity?.community.name).toBe("main"); expect(betaCommunity?.community.name).toBe("main");
expect(betaCommunity?.subscribed).toBe("Subscribed"); expect(betaCommunity?.subscribed).toBe("Subscribed");
expect(betaCommunity?.counts.subscribers_local).toBe(betaCommunityInitial.counts.subscribers_local + 1); expect(betaCommunity?.counts.subscribers_local).toBe(
betaCommunityInitial.counts.subscribers_local + 1,
);
// check that unfollow was federated // check that unfollow was federated
let communityOnBeta1 = await resolveBetaCommunity(beta); let communityOnBeta1 = await resolveBetaCommunity(beta);
expect(communityOnBeta1.community?.counts.subscribers).toBe(betaCommunityInitial.counts.subscribers + 1); expect(communityOnBeta1.community?.counts.subscribers).toBe(
betaCommunityInitial.counts.subscribers + 1,
);
// Check it from local // Check it from local
let site = await getSite(alpha); let site = await getSite(alpha);
let remoteCommunityId = site.my_user?.follows.find( let remoteCommunityId = site.my_user?.follows.find(
c => c.community.local == false && c.community.id === betaCommunityInitial.community.id, c =>
c.community.local == false &&
c.community.id === betaCommunityInitial.community.id,
)?.community.id; )?.community.id;
expect(remoteCommunityId).toBeDefined(); expect(remoteCommunityId).toBeDefined();
@ -84,10 +101,21 @@ test("Follow federated community", async () => {
// Make sure you are unsubbed locally // Make sure you are unsubbed locally
let siteUnfollowCheck = await getSite(alpha); let siteUnfollowCheck = await getSite(alpha);
expect(siteUnfollowCheck.my_user?.follows.find(c => c.community.id === betaCommunityInitial.community.id)).toBe(undefined); expect(
siteUnfollowCheck.my_user?.follows.find(
c => c.community.id === betaCommunityInitial.community.id,
),
).toBe(undefined);
// check that unfollow was federated // check that unfollow was federated
let communityOnBeta2 = await waitUntil(() => resolveBetaCommunity(beta), c => c.community?.counts.subscribers === betaCommunityInitial.counts.subscribers); let communityOnBeta2 = await waitUntil(
expect(communityOnBeta2.community?.counts.subscribers).toBe(betaCommunityInitial.counts.subscribers); () => resolveBetaCommunity(beta),
c =>
c.community?.counts.subscribers ===
betaCommunityInitial.counts.subscribers,
);
expect(communityOnBeta2.community?.counts.subscribers).toBe(
betaCommunityInitial.counts.subscribers,
);
expect(communityOnBeta2.community?.counts.subscribers_local).toBe(1); expect(communityOnBeta2.community?.counts.subscribers_local).toBe(1);
}); });

View file

@ -52,10 +52,14 @@ beforeAll(async () => {
afterAll(unfollows); afterAll(unfollows);
async function assertPostFederation(postOne: PostView, postTwo: PostView, waitForMeta = true) { async function assertPostFederation(
postOne: PostView,
postTwo: PostView,
waitForMeta = true,
) {
// Link metadata is generated in background task and may not be ready yet at this time, // Link metadata is generated in background task and may not be ready yet at this time,
// so wait for it explicitly. For removed posts we cant refetch anything. // so wait for it explicitly. For removed posts we cant refetch anything.
if(waitForMeta) { if (waitForMeta) {
postOne = await waitForPost(beta, postOne.post, res => { postOne = await waitForPost(beta, postOne.post, res => {
return res === null || !!res?.post.embed_title; return res === null || !!res?.post.embed_title;
}); });
@ -410,7 +414,11 @@ test("Remove a post from admin and community on same instance", async () => {
p => p?.post_view.post.removed ?? false, p => p?.post_view.post.removed ?? false,
); );
expect(alphaPost?.post_view.post.removed).toBe(true); expect(alphaPost?.post_view.post.removed).toBe(true);
await assertPostFederation(alphaPost.post_view, removePostRes.post_view, false); await assertPostFederation(
alphaPost.post_view,
removePostRes.post_view,
false,
);
// Undelete // Undelete
let undeletedPost = await removePost(beta, false, betaPost.post); let undeletedPost = await removePost(beta, false, betaPost.post);

View file

@ -130,7 +130,11 @@ test("Requests with invalid auth should be treated as unauthenticated", async ()
}); });
test("Create user with Arabic name", async () => { test("Create user with Arabic name", async () => {
let user = await registerUser(alpha, alphaUrl, "تجريب" + Math.random().toString().slice(2, 5)); let user = await registerUser(
alpha,
alphaUrl,
"تجريب" + Math.random().toString().slice(2, 5),
);
let site = await getSite(user); let site = await getSite(user);
expect(site.my_user).toBeDefined(); expect(site.my_user).toBeDefined();