]> Untitled Git - lemmy.git/blob - api_tests/src/follow.spec.ts
Update Dockerfile to run process as non-privileged user. (#3709)
[lemmy.git] / api_tests / src / follow.spec.ts
1 jest.setTimeout(120000);
2
3 import {
4   alpha,
5   setupLogins,
6   resolveBetaCommunity,
7   followCommunity,
8   unfollowRemotes,
9   getSite,
10 } from "./shared";
11
12 beforeAll(async () => {
13   await setupLogins();
14 });
15
16 afterAll(async () => {
17   await unfollowRemotes(alpha);
18 });
19
20 test("Follow federated community", async () => {
21   let betaCommunity = (await resolveBetaCommunity(alpha)).community;
22   if (!betaCommunity) {
23     throw "Missing beta community";
24   }
25   await followCommunity(alpha, true, betaCommunity.community.id);
26   betaCommunity = (await resolveBetaCommunity(alpha)).community;
27
28   // Make sure the follow response went through
29   expect(betaCommunity?.community.local).toBe(false);
30   expect(betaCommunity?.community.name).toBe("main");
31   expect(betaCommunity?.subscribed).toBe("Subscribed");
32
33   // Check it from local
34   let site = await getSite(alpha);
35   let remoteCommunityId = site.my_user?.follows.find(
36     c => c.community.local == false,
37   )?.community.id;
38   expect(remoteCommunityId).toBeDefined();
39   expect(site.my_user?.follows.length).toBe(2);
40
41   if (!remoteCommunityId) {
42     throw "Missing remote community id";
43   }
44
45   // Test an unfollow
46   let unfollow = await followCommunity(alpha, false, remoteCommunityId);
47   expect(unfollow.community_view.subscribed).toBe("NotSubscribed");
48
49   // Make sure you are unsubbed locally
50   let siteUnfollowCheck = await getSite(alpha);
51   expect(siteUnfollowCheck.my_user?.follows.length).toBe(1);
52 });