]> Untitled Git - lemmy.git/blob - ui/src/api_tests/community.spec.ts
routes.api: fix get_captcha endpoint (#1135)
[lemmy.git] / ui / src / api_tests / community.spec.ts
1 import {
2   alpha,
3   beta,
4   setupLogins,
5   searchForBetaCommunity,
6   createCommunity,
7   deleteCommunity,
8   removeCommunity,
9   delay,
10 } from './shared';
11
12 beforeAll(async () => {
13   await setupLogins();
14 });
15
16 test('Create community', async () => {
17   let communityRes = await createCommunity(alpha);
18   expect(communityRes.community.name).toBeDefined();
19
20   // A dupe check
21   let prevName = communityRes.community.name;
22   let communityRes2 = await createCommunity(alpha, prevName);
23   expect(communityRes2['error']).toBe('community_already_exists');
24 });
25
26 test('Delete community', async () => {
27   let communityRes = await createCommunity(beta);
28   await delay();
29   let deleteCommunityRes = await deleteCommunity(
30     beta,
31     true,
32     communityRes.community.id
33   );
34   expect(deleteCommunityRes.community.deleted).toBe(true);
35   await delay();
36
37   // Make sure it got deleted on A
38   let search = await searchForBetaCommunity(alpha);
39   let communityA = search.communities[0];
40   // TODO this fails currently, because no updates are pushed
41   // expect(communityA.deleted).toBe(true);
42
43   // Undelete
44   let undeleteCommunityRes = await deleteCommunity(
45     beta,
46     false,
47     communityRes.community.id
48   );
49   expect(undeleteCommunityRes.community.deleted).toBe(false);
50   await delay();
51
52   // Make sure it got undeleted on A
53   let search2 = await searchForBetaCommunity(alpha);
54   let communityA2 = search2.communities[0];
55   // TODO this fails currently, because no updates are pushed
56   // expect(communityA2.deleted).toBe(false);
57 });
58
59 test('Remove community', async () => {
60   let communityRes = await createCommunity(beta);
61   await delay();
62   let removeCommunityRes = await removeCommunity(
63     beta,
64     true,
65     communityRes.community.id
66   );
67   expect(removeCommunityRes.community.removed).toBe(true);
68
69   // Make sure it got removed on A
70   let search = await searchForBetaCommunity(alpha);
71   let communityA = search.communities[0];
72   // TODO this fails currently, because no updates are pushed
73   // expect(communityA.removed).toBe(true);
74   await delay();
75
76   // unremove
77   let unremoveCommunityRes = await removeCommunity(
78     beta,
79     false,
80     communityRes.community.id
81   );
82   expect(unremoveCommunityRes.community.removed).toBe(false);
83   await delay();
84
85   // Make sure it got unremoved on A
86   let search2 = await searchForBetaCommunity(alpha);
87   let communityA2 = search2.communities[0];
88   // TODO this fails currently, because no updates are pushed
89   // expect(communityA2.removed).toBe(false);
90 });
91
92 test('Search for beta community', async () => {
93   let search = await searchForBetaCommunity(alpha);
94   expect(search.communities[0].name).toBe('main');
95 });