]> Untitled Git - lemmy.git/blob - api_tests/src/community.spec.ts
routes.api: fix get_captcha endpoint (#1135)
[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
14 beforeAll(async () => {
15   await setupLogins();
16 });
17
18 test('Create community', async () => {
19   let communityRes = await createCommunity(alpha);
20   expect(communityRes.community.name).toBeDefined();
21
22   // A dupe check
23   let prevName = communityRes.community.name;
24   let communityRes2 = await createCommunity(alpha, prevName);
25   expect(communityRes2['error']).toBe('community_already_exists');
26   await delay();
27
28   // Cache the community on beta, make sure it has the other fields
29   let searchShort = `!${prevName}@lemmy-alpha:8541`;
30   let search = await searchForCommunity(beta, searchShort);
31   let communityOnBeta = search.communities[0];
32   expect(communityOnBeta.name).toBe(communityRes.community.name);
33   expect(communityOnBeta.title).toBe(communityRes.community.title);
34   expect(communityOnBeta.description).toBe(communityRes.community.description);
35   expect(communityOnBeta.icon).toBe(communityRes.community.icon);
36   expect(communityOnBeta.banner).toBe(communityRes.community.banner);
37 });
38
39 test('Delete community', async () => {
40   let communityRes = await createCommunity(beta);
41   await delay();
42   let deleteCommunityRes = await deleteCommunity(
43     beta,
44     true,
45     communityRes.community.id
46   );
47   expect(deleteCommunityRes.community.deleted).toBe(true);
48   await delay();
49
50   // Make sure it got deleted on A
51   let search = await searchForBetaCommunity(alpha);
52   let communityA = search.communities[0];
53   // TODO this fails currently, because no updates are pushed
54   // expect(communityA.deleted).toBe(true);
55
56   // Undelete
57   let undeleteCommunityRes = await deleteCommunity(
58     beta,
59     false,
60     communityRes.community.id
61   );
62   expect(undeleteCommunityRes.community.deleted).toBe(false);
63   await delay();
64
65   // Make sure it got undeleted on A
66   let search2 = await searchForBetaCommunity(alpha);
67   let communityA2 = search2.communities[0];
68   // TODO this fails currently, because no updates are pushed
69   // expect(communityA2.deleted).toBe(false);
70 });
71
72 test('Remove community', async () => {
73   let communityRes = await createCommunity(beta);
74   await delay();
75   let removeCommunityRes = await removeCommunity(
76     beta,
77     true,
78     communityRes.community.id
79   );
80   expect(removeCommunityRes.community.removed).toBe(true);
81
82   // Make sure it got removed on A
83   let search = await searchForBetaCommunity(alpha);
84   let communityA = search.communities[0];
85   // TODO this fails currently, because no updates are pushed
86   // expect(communityA.removed).toBe(true);
87   await delay();
88
89   // unremove
90   let unremoveCommunityRes = await removeCommunity(
91     beta,
92     false,
93     communityRes.community.id
94   );
95   expect(unremoveCommunityRes.community.removed).toBe(false);
96   await delay();
97
98   // Make sure it got unremoved on A
99   let search2 = await searchForBetaCommunity(alpha);
100   let communityA2 = search2.communities[0];
101   // TODO this fails currently, because no updates are pushed
102   // expect(communityA2.removed).toBe(false);
103 });
104
105 test('Search for beta community', async () => {
106   let search = await searchForBetaCommunity(alpha);
107   expect(search.communities[0].name).toBe('main');
108 });