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