]> Untitled Git - lemmy.git/blob - api_tests/src/follow.spec.ts
First pass at adding comment trees. (#2362)
[lemmy.git] / api_tests / src / follow.spec.ts
1 jest.setTimeout(120000);
2 import {SubscribedType} from 'lemmy-js-client';
3 import {
4   alpha,
5   setupLogins,
6   resolveBetaCommunity,
7   followCommunity,
8   unfollowRemotes,
9   getSite,
10   delay,
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 betaCommunity = (await resolveBetaCommunity(alpha)).community.unwrap();
23   let follow = await followCommunity(
24     alpha,
25     true,
26     betaCommunity.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   expect(follow.community_view.subscribed).toBe(SubscribedType.Subscribed);
33
34   // Check it from local
35   let site = await getSite(alpha);
36   let remoteCommunityId = site.my_user.unwrap().follows.find(
37     c => c.community.local == false
38   ).community.id;
39   expect(remoteCommunityId).toBeDefined();
40   expect(site.my_user.unwrap().follows.length).toBe(1);
41
42   // Test an unfollow
43   let unfollow = await followCommunity(alpha, false, remoteCommunityId);
44   expect(unfollow.community_view.subscribed).toBe(SubscribedType.NotSubscribed);
45
46   // Make sure you are unsubbed locally
47   let siteUnfollowCheck = await getSite(alpha);
48   expect(siteUnfollowCheck.my_user.unwrap().follows.length).toBe(0);
49 });