]> Untitled Git - lemmy.git/blob - api_tests/src/user.spec.ts
4b4eaab3be2215d9d2f52075a3ac16086721f854
[lemmy.git] / api_tests / src / user.spec.ts
1 jest.setTimeout(120000);
2 import { PersonViewSafe } from "lemmy-js-client";
3
4 import {
5   alpha,
6   beta,
7   registerUser,
8   resolvePerson,
9   getSite,
10   createPost,
11   resolveCommunity,
12   createComment,
13   resolveBetaCommunity,
14   deleteUser,
15   resolvePost,
16   API,
17   resolveComment,
18   saveUserSettingsFederated,
19   setupLogins,
20 } from "./shared";
21
22 beforeAll(async () => {
23   await setupLogins();
24 });
25
26 let apShortname: string;
27
28 function assertUserFederation(
29   userOne?: PersonViewSafe,
30   userTwo?: PersonViewSafe
31 ) {
32   expect(userOne?.person.name).toBe(userTwo?.person.name);
33   expect(userOne?.person.display_name).toBe(userTwo?.person.display_name);
34   expect(userOne?.person.bio).toBe(userTwo?.person.bio);
35   expect(userOne?.person.actor_id).toBe(userTwo?.person.actor_id);
36   expect(userOne?.person.avatar).toBe(userTwo?.person.avatar);
37   expect(userOne?.person.banner).toBe(userTwo?.person.banner);
38   expect(userOne?.person.published).toBe(userTwo?.person.published);
39 }
40
41 test("Create user", async () => {
42   let userRes = await registerUser(alpha);
43   expect(userRes.jwt).toBeDefined();
44   alpha.auth = userRes.jwt ?? "";
45
46   let site = await getSite(alpha);
47   expect(site.my_user).toBeDefined();
48   if (!site.my_user) {
49     throw "Missing site user";
50   }
51   apShortname = `@${site.my_user.local_user_view.person.name}@lemmy-alpha:8541`;
52 });
53
54 test("Set some user settings, check that they are federated", async () => {
55   await saveUserSettingsFederated(alpha);
56   let alphaPerson = (await resolvePerson(alpha, apShortname)).person;
57   let betaPerson = (await resolvePerson(beta, apShortname)).person;
58   assertUserFederation(alphaPerson, betaPerson);
59 });
60
61 test("Delete user", async () => {
62   let userRes = await registerUser(alpha);
63   expect(userRes.jwt).toBeDefined();
64   let user: API = {
65     client: alpha.client,
66     auth: userRes.jwt ?? "",
67   };
68
69   // make a local post and comment
70   let alphaCommunity = (await resolveCommunity(user, "!main@lemmy-alpha:8541"))
71     .community;
72   if (!alphaCommunity) {
73     throw "Missing alpha community";
74   }
75   let localPost = (await createPost(user, alphaCommunity.community.id))
76     .post_view.post;
77   expect(localPost).toBeDefined();
78   let localComment = (await createComment(user, localPost.id)).comment_view
79     .comment;
80   expect(localComment).toBeDefined();
81
82   // make a remote post and comment
83   let betaCommunity = (await resolveBetaCommunity(user)).community;
84   if (!betaCommunity) {
85     throw "Missing beta community";
86   }
87   let remotePost = (await createPost(user, betaCommunity.community.id))
88     .post_view.post;
89   expect(remotePost).toBeDefined();
90   let remoteComment = (await createComment(user, remotePost.id)).comment_view
91     .comment;
92   expect(remoteComment).toBeDefined();
93
94   await deleteUser(user);
95
96   expect((await resolvePost(alpha, localPost)).post).toBeUndefined();
97   expect((await resolveComment(alpha, localComment)).comment).toBeUndefined();
98   expect((await resolvePost(alpha, remotePost)).post).toBeUndefined();
99   expect((await resolveComment(alpha, remoteComment)).comment).toBeUndefined();
100 });