]> Untitled Git - lemmy.git/blob - api_tests/src/community.spec.ts
Merge branch 'drone-io-dess' into move_views_to_diesel_drone
[lemmy.git] / api_tests / src / community.spec.ts
1 jest.setTimeout(120000);
2 import {
3   alpha,
4   beta,
5   setupLogins,
6   searchForCommunity,
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.creator.actor_id).toBe(communityTwo.creator.actor_id);
35   expect(communityOne.community.nsfw).toBe(communityTwo.community.nsfw);
36   expect(communityOne.community.category_id).toBe(
37     communityTwo.community.category_id
38   );
39   expect(communityOne.community.removed).toBe(communityTwo.community.removed);
40   expect(communityOne.community.deleted).toBe(communityTwo.community.deleted);
41 }
42
43 test('Create community', async () => {
44   let communityRes = await createCommunity(alpha);
45   expect(communityRes.community_view.community.name).toBeDefined();
46
47   // A dupe check
48   let prevName = communityRes.community_view.community.name;
49   let communityRes2: any = await createCommunity(alpha, prevName);
50   expect(communityRes2['error']).toBe('community_already_exists');
51
52   // Cache the community on beta, make sure it has the other fields
53   let searchShort = `!${prevName}@lemmy-alpha:8541`;
54   let search = await searchForCommunity(beta, searchShort);
55   let communityOnBeta = search.communities[0];
56   assertCommunityFederation(communityOnBeta, communityRes.community_view);
57 });
58
59 test('Delete community', async () => {
60   let communityRes = await createCommunity(beta);
61
62   // Cache the community on Alpha
63   let searchShort = `!${communityRes.community_view.community.name}@lemmy-beta:8551`;
64   let search = await searchForCommunity(alpha, searchShort);
65   let communityOnAlpha = search.communities[0];
66   assertCommunityFederation(communityOnAlpha, communityRes.community_view);
67
68   // Follow the community from alpha
69   let follow = await followCommunity(
70     alpha,
71     true,
72     communityOnAlpha.community.id
73   );
74
75   // Make sure the follow response went through
76   expect(follow.community_view.community.local).toBe(false);
77
78   let deleteCommunityRes = await deleteCommunity(
79     beta,
80     true,
81     communityRes.community_view.community.id
82   );
83   expect(deleteCommunityRes.community_view.community.deleted).toBe(true);
84
85   // Make sure it got deleted on A
86   let communityOnAlphaDeleted = await getCommunity(
87     alpha,
88     communityOnAlpha.community.id
89   );
90   expect(communityOnAlphaDeleted.community_view.community.deleted).toBe(true);
91
92   // Undelete
93   let undeleteCommunityRes = await deleteCommunity(
94     beta,
95     false,
96     communityRes.community_view.community.id
97   );
98   expect(undeleteCommunityRes.community_view.community.deleted).toBe(false);
99
100   // Make sure it got undeleted on A
101   let communityOnAlphaUnDeleted = await getCommunity(
102     alpha,
103     communityOnAlpha.community.id
104   );
105   expect(communityOnAlphaUnDeleted.community_view.community.deleted).toBe(
106     false
107   );
108 });
109
110 test('Remove community', async () => {
111   let communityRes = await createCommunity(beta);
112
113   // Cache the community on Alpha
114   let searchShort = `!${communityRes.community_view.community.name}@lemmy-beta:8551`;
115   let search = await searchForCommunity(alpha, searchShort);
116   let communityOnAlpha = search.communities[0];
117   assertCommunityFederation(communityOnAlpha, communityRes.community_view);
118
119   // Follow the community from alpha
120   let follow = await followCommunity(
121     alpha,
122     true,
123     communityOnAlpha.community.id
124   );
125
126   // Make sure the follow response went through
127   expect(follow.community_view.community.local).toBe(false);
128
129   let removeCommunityRes = await removeCommunity(
130     beta,
131     true,
132     communityRes.community_view.community.id
133   );
134   expect(removeCommunityRes.community_view.community.removed).toBe(true);
135
136   // Make sure it got Removed on A
137   let communityOnAlphaRemoved = await getCommunity(
138     alpha,
139     communityOnAlpha.community.id
140   );
141   expect(communityOnAlphaRemoved.community_view.community.removed).toBe(true);
142
143   // unremove
144   let unremoveCommunityRes = await removeCommunity(
145     beta,
146     false,
147     communityRes.community_view.community.id
148   );
149   expect(unremoveCommunityRes.community_view.community.removed).toBe(false);
150
151   // Make sure it got undeleted on A
152   let communityOnAlphaUnRemoved = await getCommunity(
153     alpha,
154     communityOnAlpha.community.id
155   );
156   expect(communityOnAlphaUnRemoved.community_view.community.removed).toBe(
157     false
158   );
159 });
160
161 test('Search for beta community', async () => {
162   let communityRes = await createCommunity(beta);
163   expect(communityRes.community_view.community.name).toBeDefined();
164
165   let searchShort = `!${communityRes.community_view.community.name}@lemmy-beta:8551`;
166   let search = await searchForCommunity(alpha, searchShort);
167   let communityOnAlpha = search.communities[0];
168   assertCommunityFederation(communityOnAlpha, communityRes.community_view);
169 });