]> Untitled Git - lemmy.git/blob - api_tests/src/follow.spec.ts
Changing unit tests to api v2.
[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   longDelay,
11 } from './shared';
12
13 beforeAll(async () => {
14   await setupLogins();
15 });
16
17 afterAll(async () => {
18   await unfollowRemotes(alpha);
19 });
20
21 test('Follow federated community', async () => {
22   let search = await searchForBetaCommunity(alpha); // TODO sometimes this is returning null?
23   let follow = await followCommunity(
24     alpha,
25     true,
26     search.communities[0].community.id
27   );
28
29   // Make sure the follow response went through
30   expect(follow.community_view.community.local).toBe(false);
31   expect(follow.community_view.community.name).toBe('main');
32   await longDelay();
33
34   // Check it from local
35   let followCheck = await checkFollowedCommunities(alpha);
36   await delay();
37   let remoteCommunityId = followCheck.communities.find(
38     c => c.community.local == false
39   ).community.id;
40   expect(remoteCommunityId).toBeDefined();
41
42   // Test an unfollow
43   let unfollow = await followCommunity(alpha, false, remoteCommunityId);
44   expect(unfollow.community_view.community.local).toBe(false);
45   await delay();
46
47   // Make sure you are unsubbed locally
48   let unfollowCheck = await checkFollowedCommunities(alpha);
49   expect(unfollowCheck.communities.length).toBeGreaterThanOrEqual(1);
50 });