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,
|
2024-06-03 21:41:38 +00:00
|
|
|
delay,
|
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!;
|
|
|
|
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");
|
2024-05-31 09:56:43 +00:00
|
|
|
expect(follow.community_view.counts.subscribers).toBe(
|
|
|
|
community.counts.subscribers + 1,
|
|
|
|
);
|
|
|
|
expect(follow.community_view.counts.subscribers_local).toBe(
|
|
|
|
community.counts.subscribers_local + 1,
|
|
|
|
);
|
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");
|
2024-05-31 09:56:43 +00:00
|
|
|
expect(unfollow.community_view.counts.subscribers).toBe(
|
|
|
|
community.counts.subscribers,
|
|
|
|
);
|
|
|
|
expect(unfollow.community_view.counts.subscribers_local).toBe(
|
|
|
|
community.counts.subscribers_local,
|
|
|
|
);
|
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
|
2024-06-03 21:41:38 +00:00
|
|
|
await delay(2000); // if this is the second test run, we don't have a way to wait for the correct number of subscribers
|
2024-05-31 09:12:53 +00:00
|
|
|
const betaCommunityInitial = (
|
2024-01-24 15:22:05 +00:00
|
|
|
await waitUntil(
|
|
|
|
() => resolveBetaCommunity(alpha),
|
2024-05-31 09:56:43 +00:00
|
|
|
c => !!c.community && c.community?.counts.subscribers >= 1,
|
2024-01-24 15:22:05 +00:00
|
|
|
)
|
|
|
|
).community;
|
2024-05-31 09:12:53 +00:00
|
|
|
if (!betaCommunityInitial) {
|
2023-01-04 15:59:26 +00:00
|
|
|
throw "Missing beta community";
|
|
|
|
}
|
2024-05-31 09:56:43 +00:00
|
|
|
let follow = await followCommunity(
|
|
|
|
alpha,
|
|
|
|
true,
|
|
|
|
betaCommunityInitial.community.id,
|
|
|
|
);
|
2023-11-17 09:55:26 +00:00
|
|
|
expect(follow.community_view.subscribed).toBe("Pending");
|
2024-05-31 09:12:53 +00:00
|
|
|
const betaCommunity = (
|
2023-09-09 16:25:03 +00:00
|
|
|
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-05-31 09:56:43 +00:00
|
|
|
expect(betaCommunity?.counts.subscribers_local).toBe(
|
|
|
|
betaCommunityInitial.counts.subscribers_local + 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);
|
2024-05-31 09:56:43 +00:00
|
|
|
expect(communityOnBeta1.community?.counts.subscribers).toBe(
|
|
|
|
betaCommunityInitial.counts.subscribers + 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(
|
2024-05-31 09:56:43 +00:00
|
|
|
c =>
|
|
|
|
c.community.local == false &&
|
|
|
|
c.community.id === betaCommunityInitial.community.id,
|
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
|
|
|
|
|
|
|
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);
|
2024-05-31 09:56:43 +00:00
|
|
|
expect(
|
|
|
|
siteUnfollowCheck.my_user?.follows.find(
|
|
|
|
c => c.community.id === betaCommunityInitial.community.id,
|
|
|
|
),
|
|
|
|
).toBe(undefined);
|
2023-11-17 09:55:26 +00:00
|
|
|
|
|
|
|
// check that unfollow was federated
|
2024-05-31 09:56:43 +00:00
|
|
|
let communityOnBeta2 = await waitUntil(
|
|
|
|
() => resolveBetaCommunity(beta),
|
|
|
|
c =>
|
|
|
|
c.community?.counts.subscribers ===
|
|
|
|
betaCommunityInitial.counts.subscribers,
|
|
|
|
);
|
|
|
|
expect(communityOnBeta2.community?.counts.subscribers).toBe(
|
|
|
|
betaCommunityInitial.counts.subscribers,
|
|
|
|
);
|
2024-01-24 15:22:05 +00:00
|
|
|
expect(communityOnBeta2.community?.counts.subscribers_local).toBe(1);
|
2020-08-04 14:57:37 +00:00
|
|
|
});
|