]> Untitled Git - lemmy.git/blob - api_tests/src/community.spec.ts
Add tests for avatars, banners and more
[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   delay,
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   await delay();
47
48   // Cache the community on beta, make sure it has the other fields
49   let searchShort = `!${prevName}@lemmy-alpha:8541`;
50   let search = await searchForCommunity(beta, searchShort);
51   let communityOnBeta = search.communities[0];
52   assertCommunityFederation(communityOnBeta, communityRes.community);
53 });
54
55 test('Delete community', async () => {
56   let communityRes = await createCommunity(beta);
57   await delay();
58   let deleteCommunityRes = await deleteCommunity(
59     beta,
60     true,
61     communityRes.community.id
62   );
63   expect(deleteCommunityRes.community.deleted).toBe(true);
64   await delay();
65
66   // Make sure it got deleted on A
67   let search = await searchForBetaCommunity(alpha);
68   let communityA = search.communities[0];
69   // TODO this fails currently, because no updates are pushed
70   // expect(communityA.deleted).toBe(true);
71   // assertCommunityFederation(communityA, communityRes.community);
72
73   // Undelete
74   let undeleteCommunityRes = await deleteCommunity(
75     beta,
76     false,
77     communityRes.community.id
78   );
79   expect(undeleteCommunityRes.community.deleted).toBe(false);
80   await delay();
81
82   // Make sure it got undeleted on A
83   let search2 = await searchForBetaCommunity(alpha);
84   let communityA2 = search2.communities[0];
85   // TODO this fails currently, because no updates are pushed
86   // expect(communityA2.deleted).toBe(false);
87   // assertCommunityFederation(communityA2, undeleteCommunityRes.community);
88 });
89
90 test('Remove community', async () => {
91   let communityRes = await createCommunity(beta);
92   await delay();
93   let removeCommunityRes = await removeCommunity(
94     beta,
95     true,
96     communityRes.community.id
97   );
98   expect(removeCommunityRes.community.removed).toBe(true);
99
100   // Make sure it got removed on A
101   let search = await searchForBetaCommunity(alpha);
102   let communityA = search.communities[0];
103   // TODO this fails currently, because no updates are pushed
104   // expect(communityA.removed).toBe(true);
105   // assertCommunityFederation(communityA, communityRes.community);
106   await delay();
107
108   // unremove
109   let unremoveCommunityRes = await removeCommunity(
110     beta,
111     false,
112     communityRes.community.id
113   );
114   expect(unremoveCommunityRes.community.removed).toBe(false);
115   await delay();
116
117   // Make sure it got unremoved on A
118   let search2 = await searchForBetaCommunity(alpha);
119   let communityA2 = search2.communities[0];
120   // TODO this fails currently, because no updates are pushed
121   // expect(communityA2.removed).toBe(false);
122   // assertCommunityFederation(communityA2, unremoveCommunityRes.community);
123 });
124
125 test('Search for beta community', async () => {
126   let search = await searchForBetaCommunity(alpha);
127   expect(search.communities[0].name).toBe('main');
128 });