2020-09-15 19:26:47 +00:00
|
|
|
jest.setTimeout(120000);
|
2022-10-27 09:24:07 +00:00
|
|
|
|
2020-08-04 14:57:37 +00:00
|
|
|
import {
|
|
|
|
alpha,
|
|
|
|
setupLogins,
|
2021-08-23 15:25:39 +00:00
|
|
|
resolveBetaCommunity,
|
2020-08-04 14:57:37 +00:00
|
|
|
followCommunity,
|
2021-08-19 20:54:15 +00:00
|
|
|
getSite,
|
2023-09-09 16:25:03 +00:00
|
|
|
waitUntil,
|
2023-11-17 09:55:26 +00:00
|
|
|
beta,
|
|
|
|
betaUrl,
|
2023-11-22 15:15:06 +00:00
|
|
|
registerUser,
|
2024-03-26 16:06:11 +00:00
|
|
|
unfollows,
|
2022-10-27 09:24:07 +00:00
|
|
|
} from "./shared";
|
2020-08-04 14:57:37 +00:00
|
|
|
|
2023-11-17 04:43:40 +00:00
|
|
|
beforeAll(setupLogins);
|
2020-08-04 14:57:37 +00:00
|
|
|
|
2024-04-10 14:59:46 +00:00
|
|
|
afterAll(unfollows);
|
2020-08-04 14:57:37 +00:00
|
|
|
|
2023-11-17 09:55:26 +00:00
|
|
|
test("Follow local community", async () => {
|
2023-11-22 15:15:06 +00:00
|
|
|
let user = await registerUser(beta, betaUrl);
|
2023-11-17 09:55:26 +00:00
|
|
|
|
|
|
|
let community = (await resolveBetaCommunity(user)).community!;
|
|
|
|
expect(community.counts.subscribers).toBe(1);
|
2024-01-24 15:22:05 +00:00
|
|
|
expect(community.counts.subscribers_local).toBe(1);
|
2023-11-17 09:55:26 +00:00
|
|
|
let follow = await followCommunity(user, true, community.community.id);
|
|
|
|
|
|
|
|
// Make sure the follow response went through
|
|
|
|
expect(follow.community_view.community.local).toBe(true);
|
|
|
|
expect(follow.community_view.subscribed).toBe("Subscribed");
|
|
|
|
expect(follow.community_view.counts.subscribers).toBe(2);
|
2024-01-24 15:22:05 +00:00
|
|
|
expect(follow.community_view.counts.subscribers_local).toBe(2);
|
2023-11-17 09:55:26 +00:00
|
|
|
|
|
|
|
// Test an unfollow
|
|
|
|
let unfollow = await followCommunity(user, false, community.community.id);
|
|
|
|
expect(unfollow.community_view.subscribed).toBe("NotSubscribed");
|
|
|
|
expect(unfollow.community_view.counts.subscribers).toBe(1);
|
2024-01-24 15:22:05 +00:00
|
|
|
expect(unfollow.community_view.counts.subscribers_local).toBe(1);
|
2023-11-17 09:55:26 +00:00
|
|
|
});
|
|
|
|
|
2022-10-27 09:24:07 +00:00
|
|
|
test("Follow federated community", async () => {
|
2024-01-24 15:22:05 +00:00
|
|
|
// It takes about 1 second for the community aggregates to federate
|
|
|
|
let betaCommunity = (
|
|
|
|
await waitUntil(
|
|
|
|
() => resolveBetaCommunity(alpha),
|
|
|
|
c =>
|
|
|
|
c.community?.counts.subscribers === 1 &&
|
|
|
|
c.community.counts.subscribers_local === 0,
|
|
|
|
)
|
|
|
|
).community;
|
2023-01-04 15:59:26 +00:00
|
|
|
if (!betaCommunity) {
|
|
|
|
throw "Missing beta community";
|
|
|
|
}
|
2023-11-17 09:55:26 +00:00
|
|
|
let follow = await followCommunity(alpha, true, betaCommunity.community.id);
|
|
|
|
expect(follow.community_view.subscribed).toBe("Pending");
|
2023-09-09 16:25:03 +00:00
|
|
|
betaCommunity = (
|
|
|
|
await waitUntil(
|
|
|
|
() => resolveBetaCommunity(alpha),
|
|
|
|
c => c.community?.subscribed === "Subscribed",
|
|
|
|
)
|
|
|
|
).community;
|
2020-08-04 14:57:37 +00:00
|
|
|
|
|
|
|
// Make sure the follow response went through
|
2023-01-04 15:59:26 +00:00
|
|
|
expect(betaCommunity?.community.local).toBe(false);
|
|
|
|
expect(betaCommunity?.community.name).toBe("main");
|
2023-04-26 04:26:10 +00:00
|
|
|
expect(betaCommunity?.subscribed).toBe("Subscribed");
|
2024-01-24 15:22:05 +00:00
|
|
|
expect(betaCommunity?.counts.subscribers_local).toBe(1);
|
2020-08-04 14:57:37 +00:00
|
|
|
|
2023-11-17 09:55:26 +00:00
|
|
|
// check that unfollow was federated
|
|
|
|
let communityOnBeta1 = await resolveBetaCommunity(beta);
|
|
|
|
expect(communityOnBeta1.community?.counts.subscribers).toBe(2);
|
2024-01-24 15:22:05 +00:00
|
|
|
expect(communityOnBeta1.community?.counts.subscribers_local).toBe(1);
|
2023-11-17 09:55:26 +00:00
|
|
|
|
2020-08-04 14:57:37 +00:00
|
|
|
// Check it from local
|
2021-08-19 20:54:15 +00:00
|
|
|
let site = await getSite(alpha);
|
2023-01-04 15:59:26 +00:00
|
|
|
let remoteCommunityId = site.my_user?.follows.find(
|
2023-07-06 13:10:38 +00:00
|
|
|
c => c.community.local == false,
|
2023-01-04 15:59:26 +00:00
|
|
|
)?.community.id;
|
2020-08-04 14:57:37 +00:00
|
|
|
expect(remoteCommunityId).toBeDefined();
|
2023-01-04 15:59:26 +00:00
|
|
|
expect(site.my_user?.follows.length).toBe(2);
|
|
|
|
|
|
|
|
if (!remoteCommunityId) {
|
|
|
|
throw "Missing remote community id";
|
|
|
|
}
|
2020-08-04 14:57:37 +00:00
|
|
|
|
|
|
|
// Test an unfollow
|
|
|
|
let unfollow = await followCommunity(alpha, false, remoteCommunityId);
|
2023-04-26 04:26:10 +00:00
|
|
|
expect(unfollow.community_view.subscribed).toBe("NotSubscribed");
|
2020-08-04 14:57:37 +00:00
|
|
|
|
|
|
|
// Make sure you are unsubbed locally
|
2021-08-19 20:54:15 +00:00
|
|
|
let siteUnfollowCheck = await getSite(alpha);
|
2023-01-04 15:59:26 +00:00
|
|
|
expect(siteUnfollowCheck.my_user?.follows.length).toBe(1);
|
2023-11-17 09:55:26 +00:00
|
|
|
|
|
|
|
// check that unfollow was federated
|
|
|
|
let communityOnBeta2 = await resolveBetaCommunity(beta);
|
|
|
|
expect(communityOnBeta2.community?.counts.subscribers).toBe(1);
|
2024-01-24 15:22:05 +00:00
|
|
|
expect(communityOnBeta2.community?.counts.subscribers_local).toBe(1);
|
2020-08-04 14:57:37 +00:00
|
|
|
});
|