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