]> Untitled Git - lemmy.git/blob - api_tests/src/follow.spec.ts
routes.api: fix get_captcha endpoint (#1135)
[lemmy.git] / api_tests / src / follow.spec.ts
1 jest.setTimeout(120000);
2 import {
3   alpha,
4   setupLogins,
5   searchForBetaCommunity,
6   followCommunity,
7   checkFollowedCommunities,
8   unfollowRemotes,
9   delay,
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 search = await searchForBetaCommunity(alpha); // TODO sometimes this is returning null?
22   let follow = await followCommunity(alpha, true, search.communities[0].id);
23
24   // Make sure the follow response went through
25   expect(follow.community.local).toBe(false);
26   expect(follow.community.name).toBe('main');
27   await delay();
28
29   // Check it from local
30   let followCheck = await checkFollowedCommunities(alpha);
31   let remoteCommunityId = followCheck.communities.filter(
32     c => c.community_local == false
33   )[0].community_id;
34   expect(remoteCommunityId).toBeDefined();
35
36   // Test an unfollow
37   let unfollow = await followCommunity(alpha, false, remoteCommunityId);
38   expect(unfollow.community.local).toBe(false);
39   await delay();
40
41   // Make sure you are unsubbed locally
42   let unfollowCheck = await checkFollowedCommunities(alpha);
43   expect(unfollowCheck.communities.length).toBeGreaterThanOrEqual(1);
44 });