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