]> Untitled Git - lemmy.git/blob - api_tests/src/community.spec.ts
Revert "Add pending, and change use specific API response for FollowCommunity…" ...
[lemmy.git] / api_tests / src / community.spec.ts
1 jest.setTimeout(120000);
2 import {
3   alpha,
4   beta,
5   setupLogins,
6   resolveCommunity,
7   createCommunity,
8   deleteCommunity,
9   removeCommunity,
10   getCommunity,
11   followCommunity,
12 } from './shared';
13 import { CommunityView } from 'lemmy-js-client';
14
15 beforeAll(async () => {
16   await setupLogins();
17 });
18
19 function assertCommunityFederation(
20   communityOne: CommunityView,
21   communityTwo: CommunityView
22 ) {
23   expect(communityOne.community.actor_id).toBe(communityTwo.community.actor_id);
24   expect(communityOne.community.name).toBe(communityTwo.community.name);
25   expect(communityOne.community.title).toBe(communityTwo.community.title);
26   expect(communityOne.community.description).toBe(
27     communityTwo.community.description
28   );
29   expect(communityOne.community.icon).toBe(communityTwo.community.icon);
30   expect(communityOne.community.banner).toBe(communityTwo.community.banner);
31   expect(communityOne.community.published).toBe(
32     communityTwo.community.published
33   );
34   expect(communityOne.community.nsfw).toBe(communityTwo.community.nsfw);
35   expect(communityOne.community.removed).toBe(communityTwo.community.removed);
36   expect(communityOne.community.deleted).toBe(communityTwo.community.deleted);
37 }
38
39 test('Create community', async () => {
40   let communityRes = await createCommunity(alpha);
41   expect(communityRes.community_view.community.name).toBeDefined();
42
43   // A dupe check
44   let prevName = communityRes.community_view.community.name;
45   let communityRes2: any = await createCommunity(alpha, prevName);
46   expect(communityRes2['error']).toBe('community_already_exists');
47
48   // Cache the community on beta, make sure it has the other fields
49   let searchShort = `!${prevName}@lemmy-alpha:8541`;
50   let betaCommunity = (await resolveCommunity(beta, searchShort)).community;
51   assertCommunityFederation(betaCommunity, communityRes.community_view);
52 });
53
54 test('Delete community', async () => {
55   let communityRes = await createCommunity(beta);
56
57   // Cache the community on Alpha
58   let searchShort = `!${communityRes.community_view.community.name}@lemmy-beta:8551`;
59   let alphaCommunity = (await resolveCommunity(alpha, searchShort)).community;
60   assertCommunityFederation(alphaCommunity, communityRes.community_view);
61
62   // Follow the community from alpha
63   let follow = await followCommunity(
64     alpha,
65     true,
66     alphaCommunity.community.id
67   );
68
69   // Make sure the follow response went through
70   expect(follow.community_view.community.local).toBe(false);
71
72   let deleteCommunityRes = await deleteCommunity(
73     beta,
74     true,
75     communityRes.community_view.community.id
76   );
77   expect(deleteCommunityRes.community_view.community.deleted).toBe(true);
78   expect(deleteCommunityRes.community_view.community.title).toBe(communityRes.community_view.community.title);
79
80   // Make sure it got deleted on A
81   let communityOnAlphaDeleted = await getCommunity(
82     alpha,
83     alphaCommunity.community.id
84   );
85   expect(communityOnAlphaDeleted.community_view.community.deleted).toBe(true);
86
87   // Undelete
88   let undeleteCommunityRes = await deleteCommunity(
89     beta,
90     false,
91     communityRes.community_view.community.id
92   );
93   expect(undeleteCommunityRes.community_view.community.deleted).toBe(false);
94
95   // Make sure it got undeleted on A
96   let communityOnAlphaUnDeleted = await getCommunity(
97     alpha,
98     alphaCommunity.community.id
99   );
100   expect(communityOnAlphaUnDeleted.community_view.community.deleted).toBe(
101     false
102   );
103 });
104
105 test('Remove community', async () => {
106   let communityRes = await createCommunity(beta);
107
108   // Cache the community on Alpha
109   let searchShort = `!${communityRes.community_view.community.name}@lemmy-beta:8551`;
110   let alphaCommunity = (await resolveCommunity(alpha, searchShort)).community;
111   assertCommunityFederation(alphaCommunity, communityRes.community_view);
112
113   // Follow the community from alpha
114   let follow = await followCommunity(
115     alpha,
116     true,
117     alphaCommunity.community.id
118   );
119
120   // Make sure the follow response went through
121   expect(follow.community_view.community.local).toBe(false);
122
123   let removeCommunityRes = await removeCommunity(
124     beta,
125     true,
126     communityRes.community_view.community.id
127   );
128   expect(removeCommunityRes.community_view.community.removed).toBe(true);
129   expect(removeCommunityRes.community_view.community.title).toBe(communityRes.community_view.community.title);
130
131   // Make sure it got Removed on A
132   let communityOnAlphaRemoved = await getCommunity(
133     alpha,
134     alphaCommunity.community.id
135   );
136   expect(communityOnAlphaRemoved.community_view.community.removed).toBe(true);
137
138   // unremove
139   let unremoveCommunityRes = await removeCommunity(
140     beta,
141     false,
142     communityRes.community_view.community.id
143   );
144   expect(unremoveCommunityRes.community_view.community.removed).toBe(false);
145
146   // Make sure it got undeleted on A
147   let communityOnAlphaUnRemoved = await getCommunity(
148     alpha,
149     alphaCommunity.community.id
150   );
151   expect(communityOnAlphaUnRemoved.community_view.community.removed).toBe(
152     false
153   );
154 });
155
156 test('Search for beta community', async () => {
157   let communityRes = await createCommunity(beta);
158   expect(communityRes.community_view.community.name).toBeDefined();
159
160   let searchShort = `!${communityRes.community_view.community.name}@lemmy-beta:8551`;
161   let alphaCommunity = (await resolveCommunity(alpha, searchShort)).community;
162   assertCommunityFederation(alphaCommunity, communityRes.community_view);
163 });