2020-09-15 19:26:47 +00:00
|
|
|
jest.setTimeout(120000);
|
2022-07-30 03:55:59 +00:00
|
|
|
|
2023-04-26 04:26:10 +00:00
|
|
|
import { PersonView } from "lemmy-js-client/dist/types/PersonView";
|
2020-08-04 15:06:27 +00:00
|
|
|
import {
|
|
|
|
alpha,
|
|
|
|
beta,
|
|
|
|
registerUser,
|
2021-08-23 15:25:39 +00:00
|
|
|
resolvePerson,
|
2020-08-04 15:06:27 +00:00
|
|
|
getSite,
|
2022-04-07 20:52:17 +00:00
|
|
|
createPost,
|
|
|
|
resolveCommunity,
|
|
|
|
createComment,
|
|
|
|
resolveBetaCommunity,
|
|
|
|
deleteUser,
|
2022-07-30 03:55:59 +00:00
|
|
|
saveUserSettingsFederated,
|
2022-10-13 16:30:31 +00:00
|
|
|
setupLogins,
|
2023-09-21 10:42:28 +00:00
|
|
|
alphaUrl,
|
2023-10-24 09:20:23 +00:00
|
|
|
saveUserSettings,
|
2023-11-16 13:22:40 +00:00
|
|
|
getPost,
|
|
|
|
getComments,
|
2023-11-24 09:29:41 +00:00
|
|
|
fetchFunction,
|
2024-03-27 13:00:52 +00:00
|
|
|
alphaImage,
|
2024-04-10 14:59:46 +00:00
|
|
|
unfollows,
|
2024-06-06 13:55:08 +00:00
|
|
|
saveUserSettingsBio,
|
2024-12-07 21:06:33 +00:00
|
|
|
getMyUser,
|
2024-12-03 17:19:01 +00:00
|
|
|
getPersonDetails,
|
2022-10-27 09:24:07 +00:00
|
|
|
} from "./shared";
|
2024-11-28 23:03:14 +00:00
|
|
|
import {
|
|
|
|
EditSite,
|
|
|
|
LemmyHttp,
|
|
|
|
SaveUserSettings,
|
|
|
|
UploadImage,
|
|
|
|
} from "lemmy-js-client";
|
2023-05-25 14:50:07 +00:00
|
|
|
import { GetPosts } from "lemmy-js-client/dist/types/GetPosts";
|
2020-08-04 15:06:27 +00:00
|
|
|
|
2023-11-17 04:43:40 +00:00
|
|
|
beforeAll(setupLogins);
|
2024-04-10 14:59:46 +00:00
|
|
|
afterAll(unfollows);
|
2022-10-13 16:30:31 +00:00
|
|
|
|
2020-08-04 15:06:27 +00:00
|
|
|
let apShortname: string;
|
|
|
|
|
2023-04-17 19:19:51 +00:00
|
|
|
function assertUserFederation(userOne?: PersonView, userTwo?: PersonView) {
|
2023-01-04 15:59:26 +00:00
|
|
|
expect(userOne?.person.name).toBe(userTwo?.person.name);
|
|
|
|
expect(userOne?.person.display_name).toBe(userTwo?.person.display_name);
|
|
|
|
expect(userOne?.person.bio).toBe(userTwo?.person.bio);
|
|
|
|
expect(userOne?.person.actor_id).toBe(userTwo?.person.actor_id);
|
|
|
|
expect(userOne?.person.avatar).toBe(userTwo?.person.avatar);
|
|
|
|
expect(userOne?.person.banner).toBe(userTwo?.person.banner);
|
|
|
|
expect(userOne?.person.published).toBe(userTwo?.person.published);
|
2020-09-17 15:41:51 +00:00
|
|
|
}
|
|
|
|
|
2022-10-27 09:24:07 +00:00
|
|
|
test("Create user", async () => {
|
2023-11-22 15:15:06 +00:00
|
|
|
let user = await registerUser(alpha, alphaUrl);
|
2022-10-27 09:24:07 +00:00
|
|
|
|
2024-12-07 21:06:33 +00:00
|
|
|
let my_user = await getMyUser(user);
|
|
|
|
expect(my_user).toBeDefined();
|
|
|
|
apShortname = `${my_user.local_user_view.person.name}@lemmy-alpha:8541`;
|
2020-08-04 15:06:27 +00:00
|
|
|
});
|
|
|
|
|
2022-10-27 09:24:07 +00:00
|
|
|
test("Set some user settings, check that they are federated", async () => {
|
2022-07-30 03:55:59 +00:00
|
|
|
await saveUserSettingsFederated(alpha);
|
2023-01-04 15:59:26 +00:00
|
|
|
let alphaPerson = (await resolvePerson(alpha, apShortname)).person;
|
|
|
|
let betaPerson = (await resolvePerson(beta, apShortname)).person;
|
2021-08-23 15:25:39 +00:00
|
|
|
assertUserFederation(alphaPerson, betaPerson);
|
2023-10-24 09:20:23 +00:00
|
|
|
|
|
|
|
// Catches a bug where when only the person or local_user changed
|
|
|
|
let form: SaveUserSettings = {
|
|
|
|
theme: "test",
|
|
|
|
};
|
|
|
|
await saveUserSettings(beta, form);
|
|
|
|
|
2024-12-07 21:06:33 +00:00
|
|
|
let my_user = await getMyUser(beta);
|
|
|
|
expect(my_user.local_user_view.local_user.theme).toBe("test");
|
2020-09-18 11:04:12 +00:00
|
|
|
});
|
2022-04-07 20:52:17 +00:00
|
|
|
|
2022-10-27 09:24:07 +00:00
|
|
|
test("Delete user", async () => {
|
2023-11-22 15:15:06 +00:00
|
|
|
let user = await registerUser(alpha, alphaUrl);
|
2024-12-12 15:03:55 +00:00
|
|
|
let user_profile = await getMyUser(user);
|
|
|
|
let person_id = user_profile.local_user_view.person.id;
|
|
|
|
let actor_id = user_profile.local_user_view.person.actor_id;
|
2022-04-07 20:52:17 +00:00
|
|
|
|
|
|
|
// make a local post and comment
|
2024-03-15 12:42:09 +00:00
|
|
|
let alphaCommunity = (await resolveCommunity(user, "main@lemmy-alpha:8541"))
|
2023-01-04 15:59:26 +00:00
|
|
|
.community;
|
|
|
|
if (!alphaCommunity) {
|
|
|
|
throw "Missing alpha community";
|
|
|
|
}
|
2022-10-27 09:24:07 +00:00
|
|
|
let localPost = (await createPost(user, alphaCommunity.community.id))
|
|
|
|
.post_view.post;
|
2022-04-07 20:52:17 +00:00
|
|
|
expect(localPost).toBeDefined();
|
2023-01-04 15:59:26 +00:00
|
|
|
let localComment = (await createComment(user, localPost.id)).comment_view
|
|
|
|
.comment;
|
2022-04-07 20:52:17 +00:00
|
|
|
expect(localComment).toBeDefined();
|
|
|
|
|
|
|
|
// make a remote post and comment
|
2023-01-04 15:59:26 +00:00
|
|
|
let betaCommunity = (await resolveBetaCommunity(user)).community;
|
|
|
|
if (!betaCommunity) {
|
|
|
|
throw "Missing beta community";
|
|
|
|
}
|
2022-10-27 09:24:07 +00:00
|
|
|
let remotePost = (await createPost(user, betaCommunity.community.id))
|
|
|
|
.post_view.post;
|
2022-04-07 20:52:17 +00:00
|
|
|
expect(remotePost).toBeDefined();
|
2023-01-04 15:59:26 +00:00
|
|
|
let remoteComment = (await createComment(user, remotePost.id)).comment_view
|
|
|
|
.comment;
|
2022-04-07 20:52:17 +00:00
|
|
|
expect(remoteComment).toBeDefined();
|
|
|
|
|
|
|
|
await deleteUser(user);
|
2024-12-12 15:03:55 +00:00
|
|
|
await expect(getMyUser(user)).rejects.toStrictEqual(Error("incorrect_login"));
|
|
|
|
await expect(getPersonDetails(user, person_id)).rejects.toStrictEqual(
|
|
|
|
Error("not_found"),
|
|
|
|
);
|
2022-04-07 20:52:17 +00:00
|
|
|
|
2023-11-16 13:22:40 +00:00
|
|
|
// check that posts and comments are marked as deleted on other instances.
|
|
|
|
// use get methods to avoid refetching from origin instance
|
|
|
|
expect((await getPost(alpha, localPost.id)).post_view.post.deleted).toBe(
|
|
|
|
true,
|
2023-07-21 09:47:56 +00:00
|
|
|
);
|
2023-11-16 13:22:40 +00:00
|
|
|
expect((await getPost(alpha, remotePost.id)).post_view.post.deleted).toBe(
|
|
|
|
true,
|
2023-07-21 09:47:56 +00:00
|
|
|
);
|
2023-11-16 13:22:40 +00:00
|
|
|
expect(
|
|
|
|
(await getComments(alpha, localComment.post_id)).comments[0].comment
|
|
|
|
.deleted,
|
|
|
|
).toBe(true);
|
|
|
|
expect(
|
|
|
|
(await getComments(alpha, remoteComment.post_id)).comments[0].comment
|
|
|
|
.deleted,
|
|
|
|
).toBe(true);
|
2024-12-12 15:03:55 +00:00
|
|
|
await expect(
|
|
|
|
getPersonDetails(user, remoteComment.creator_id),
|
|
|
|
).rejects.toStrictEqual(Error("not_found"));
|
2022-04-07 20:52:17 +00:00
|
|
|
});
|
2023-05-25 14:50:07 +00:00
|
|
|
|
2024-01-19 16:21:43 +00:00
|
|
|
test("Requests with invalid auth should be treated as unauthenticated", async () => {
|
2023-09-21 10:42:28 +00:00
|
|
|
let invalid_auth = new LemmyHttp(alphaUrl, {
|
2023-09-25 10:37:45 +00:00
|
|
|
headers: { Authorization: "Bearer foobar" },
|
2023-11-24 09:29:41 +00:00
|
|
|
fetchFunction,
|
2023-09-21 10:42:28 +00:00
|
|
|
});
|
2024-12-07 21:06:33 +00:00
|
|
|
await expect(getMyUser(invalid_auth)).rejects.toStrictEqual(
|
|
|
|
Error("incorrect_login"),
|
|
|
|
);
|
2024-01-19 16:21:43 +00:00
|
|
|
let site = await getSite(invalid_auth);
|
|
|
|
expect(site.site_view).toBeDefined();
|
2023-05-25 14:50:07 +00:00
|
|
|
|
2023-09-21 10:42:28 +00:00
|
|
|
let form: GetPosts = {};
|
2024-01-19 16:21:43 +00:00
|
|
|
let posts = invalid_auth.getPosts(form);
|
|
|
|
expect((await posts).posts).toBeDefined();
|
2023-05-25 14:50:07 +00:00
|
|
|
});
|
2023-10-24 20:25:52 +00:00
|
|
|
|
|
|
|
test("Create user with Arabic name", async () => {
|
2024-12-03 17:19:01 +00:00
|
|
|
// less than actor_name_max_length
|
|
|
|
const name = "تجريب" + Math.random().toString().slice(2, 10);
|
|
|
|
let user = await registerUser(alpha, alphaUrl, name);
|
2023-10-24 20:25:52 +00:00
|
|
|
|
2024-12-07 21:06:33 +00:00
|
|
|
let my_user = await getMyUser(user);
|
|
|
|
expect(my_user).toBeDefined();
|
|
|
|
apShortname = `${my_user.local_user_view.person.name}@lemmy-alpha:8541`;
|
2023-10-24 20:25:52 +00:00
|
|
|
|
2024-12-03 17:19:01 +00:00
|
|
|
let betaPerson1 = (await resolvePerson(beta, apShortname)).person;
|
|
|
|
expect(betaPerson1!.person.name).toBe(name);
|
|
|
|
|
|
|
|
let betaPerson2 = await getPersonDetails(beta, betaPerson1!.person.id);
|
|
|
|
expect(betaPerson2!.person_view.person.name).toBe(name);
|
2023-10-24 20:25:52 +00:00
|
|
|
});
|
2024-03-25 20:02:12 +00:00
|
|
|
|
|
|
|
test("Create user with accept-language", async () => {
|
2024-11-28 23:03:14 +00:00
|
|
|
const edit: EditSite = {
|
|
|
|
discussion_languages: [32],
|
|
|
|
};
|
|
|
|
await alpha.editSite(edit);
|
|
|
|
|
2024-03-25 20:02:12 +00:00
|
|
|
let lemmy_http = new LemmyHttp(alphaUrl, {
|
|
|
|
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Language#syntax
|
2024-11-28 23:03:14 +00:00
|
|
|
headers: { "Accept-Language": "fr-CH, en;q=0.8, *;q=0.5" },
|
2024-03-25 20:02:12 +00:00
|
|
|
});
|
|
|
|
let user = await registerUser(lemmy_http, alphaUrl);
|
|
|
|
|
2024-12-07 21:06:33 +00:00
|
|
|
let my_user = await getMyUser(user);
|
|
|
|
expect(my_user).toBeDefined();
|
|
|
|
expect(my_user?.local_user_view.local_user.interface_language).toBe("fr");
|
2024-03-25 20:02:12 +00:00
|
|
|
let site = await getSite(user);
|
|
|
|
let langs = site.all_languages
|
2024-12-07 21:06:33 +00:00
|
|
|
.filter(a => my_user.discussion_languages.includes(a.id))
|
2024-03-25 20:02:12 +00:00
|
|
|
.map(l => l.code);
|
|
|
|
// should have languages from accept header, as well as "undetermined"
|
|
|
|
// which is automatically enabled by backend
|
|
|
|
expect(langs).toStrictEqual(["und", "de", "en", "fr"]);
|
|
|
|
});
|
2024-03-27 13:00:52 +00:00
|
|
|
|
|
|
|
test("Set a new avatar, old avatar is deleted", async () => {
|
|
|
|
const listMediaRes = await alphaImage.listMedia();
|
|
|
|
expect(listMediaRes.images.length).toBe(0);
|
|
|
|
const upload_form1: UploadImage = {
|
|
|
|
image: Buffer.from("test1"),
|
|
|
|
};
|
|
|
|
const upload1 = await alphaImage.uploadImage(upload_form1);
|
|
|
|
expect(upload1.url).toBeDefined();
|
|
|
|
|
|
|
|
let form1 = {
|
|
|
|
avatar: upload1.url,
|
|
|
|
};
|
|
|
|
await saveUserSettings(alpha, form1);
|
|
|
|
const listMediaRes1 = await alphaImage.listMedia();
|
|
|
|
expect(listMediaRes1.images.length).toBe(1);
|
|
|
|
|
|
|
|
const upload_form2: UploadImage = {
|
|
|
|
image: Buffer.from("test2"),
|
|
|
|
};
|
|
|
|
const upload2 = await alphaImage.uploadImage(upload_form2);
|
|
|
|
expect(upload2.url).toBeDefined();
|
|
|
|
|
|
|
|
let form2 = {
|
2024-06-04 12:28:22 +00:00
|
|
|
avatar: upload2.url,
|
2024-03-27 13:00:52 +00:00
|
|
|
};
|
|
|
|
await saveUserSettings(alpha, form2);
|
|
|
|
// make sure only the new avatar is kept
|
|
|
|
const listMediaRes2 = await alphaImage.listMedia();
|
|
|
|
expect(listMediaRes2.images.length).toBe(1);
|
2024-06-04 12:28:22 +00:00
|
|
|
|
|
|
|
// Upload that same form2 avatar, make sure it isn't replaced / deleted
|
|
|
|
await saveUserSettings(alpha, form2);
|
|
|
|
// make sure only the new avatar is kept
|
|
|
|
const listMediaRes3 = await alphaImage.listMedia();
|
|
|
|
expect(listMediaRes3.images.length).toBe(1);
|
2024-06-06 13:55:08 +00:00
|
|
|
|
|
|
|
// Now try to save a user settings, with the icon missing,
|
|
|
|
// and make sure it doesn't clear the data, or delete the image
|
|
|
|
await saveUserSettingsBio(alpha);
|
2024-12-07 21:06:33 +00:00
|
|
|
let my_user = await getMyUser(alpha);
|
|
|
|
expect(my_user.local_user_view.person.avatar).toBe(upload2.url);
|
2024-06-06 13:55:08 +00:00
|
|
|
|
|
|
|
// make sure only the new avatar is kept
|
|
|
|
const listMediaRes4 = await alphaImage.listMedia();
|
|
|
|
expect(listMediaRes4.images.length).toBe(1);
|
2024-03-27 13:00:52 +00:00
|
|
|
});
|