mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-23 04:41:19 +00:00
Nutomic
a00313e680
* Merge /site_inbox into /inbox (fixes #4137) Get rid of different inboxes, only use /inbox Remove shared_inbox_url db columns add code migration move to db migration, fixes machete fix sql drop inbox url unique constraints Dont create auth cookie in backend (#4136) dont change individual inboxes to shared inbox Dont send comment reply to user who has community blocked. Fixes #3684 (#4096) * Dont send comment reply to user who has community blocked. Fixes #3684 * Adding source instance block check. * Adding api test. * Addressing PR comments. * move site inbox rewrite to db * fix test * clippy * clippy 2 * fix test
153 lines
4.7 KiB
TypeScript
153 lines
4.7 KiB
TypeScript
jest.setTimeout(120000);
|
|
|
|
import { PersonView } from "lemmy-js-client/dist/types/PersonView";
|
|
import {
|
|
alpha,
|
|
beta,
|
|
registerUser,
|
|
resolvePerson,
|
|
getSite,
|
|
createPost,
|
|
resolveCommunity,
|
|
createComment,
|
|
resolveBetaCommunity,
|
|
deleteUser,
|
|
saveUserSettingsFederated,
|
|
setupLogins,
|
|
alphaUrl,
|
|
saveUserSettings,
|
|
getPost,
|
|
getComments,
|
|
} from "./shared";
|
|
import { LemmyHttp, SaveUserSettings } from "lemmy-js-client";
|
|
import { GetPosts } from "lemmy-js-client/dist/types/GetPosts";
|
|
|
|
beforeAll(async () => {
|
|
await setupLogins();
|
|
});
|
|
|
|
let apShortname: string;
|
|
|
|
function assertUserFederation(userOne?: PersonView, userTwo?: PersonView) {
|
|
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);
|
|
}
|
|
|
|
test("Create user", async () => {
|
|
let userRes = await registerUser(alpha);
|
|
expect(userRes.jwt).toBeDefined();
|
|
let user = new LemmyHttp(alphaUrl, {
|
|
headers: { Authorization: `Bearer ${userRes.jwt ?? ""}` },
|
|
});
|
|
|
|
let site = await getSite(user);
|
|
expect(site.my_user).toBeDefined();
|
|
if (!site.my_user) {
|
|
throw "Missing site user";
|
|
}
|
|
apShortname = `@${site.my_user.local_user_view.person.name}@lemmy-alpha:8541`;
|
|
});
|
|
|
|
test("Set some user settings, check that they are federated", async () => {
|
|
await saveUserSettingsFederated(alpha);
|
|
let alphaPerson = (await resolvePerson(alpha, apShortname)).person;
|
|
let betaPerson = (await resolvePerson(beta, apShortname)).person;
|
|
assertUserFederation(alphaPerson, betaPerson);
|
|
|
|
// Catches a bug where when only the person or local_user changed
|
|
let form: SaveUserSettings = {
|
|
theme: "test",
|
|
};
|
|
await saveUserSettings(beta, form);
|
|
|
|
let site = await getSite(beta);
|
|
expect(site.my_user?.local_user_view.local_user.theme).toBe("test");
|
|
});
|
|
|
|
test("Delete user", async () => {
|
|
let userRes = await registerUser(alpha);
|
|
expect(userRes.jwt).toBeDefined();
|
|
let user = new LemmyHttp(alphaUrl, {
|
|
headers: { Authorization: `Bearer ${userRes.jwt ?? ""}` },
|
|
});
|
|
|
|
// make a local post and comment
|
|
let alphaCommunity = (await resolveCommunity(user, "!main@lemmy-alpha:8541"))
|
|
.community;
|
|
if (!alphaCommunity) {
|
|
throw "Missing alpha community";
|
|
}
|
|
let localPost = (await createPost(user, alphaCommunity.community.id))
|
|
.post_view.post;
|
|
expect(localPost).toBeDefined();
|
|
let localComment = (await createComment(user, localPost.id)).comment_view
|
|
.comment;
|
|
expect(localComment).toBeDefined();
|
|
|
|
// make a remote post and comment
|
|
let betaCommunity = (await resolveBetaCommunity(user)).community;
|
|
if (!betaCommunity) {
|
|
throw "Missing beta community";
|
|
}
|
|
let remotePost = (await createPost(user, betaCommunity.community.id))
|
|
.post_view.post;
|
|
expect(remotePost).toBeDefined();
|
|
let remoteComment = (await createComment(user, remotePost.id)).comment_view
|
|
.comment;
|
|
expect(remoteComment).toBeDefined();
|
|
|
|
await deleteUser(user);
|
|
|
|
// 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,
|
|
);
|
|
expect((await getPost(alpha, remotePost.id)).post_view.post.deleted).toBe(
|
|
true,
|
|
);
|
|
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);
|
|
});
|
|
|
|
test("Requests with invalid auth should be treated as unauthenticated", async () => {
|
|
let invalid_auth = new LemmyHttp(alphaUrl, {
|
|
headers: { Authorization: "Bearer foobar" },
|
|
});
|
|
let site = await getSite(invalid_auth);
|
|
expect(site.my_user).toBeUndefined();
|
|
expect(site.site_view).toBeDefined();
|
|
|
|
let form: GetPosts = {};
|
|
let posts = invalid_auth.getPosts(form);
|
|
expect((await posts).posts).toBeDefined();
|
|
});
|
|
|
|
test("Create user with Arabic name", async () => {
|
|
let userRes = await registerUser(alpha, "تجريب");
|
|
expect(userRes.jwt).toBeDefined();
|
|
let user = new LemmyHttp(alphaUrl, {
|
|
headers: { Authorization: `Bearer ${userRes.jwt ?? ""}` },
|
|
});
|
|
|
|
let site = await getSite(user);
|
|
expect(site.my_user).toBeDefined();
|
|
if (!site.my_user) {
|
|
throw "Missing site user";
|
|
}
|
|
apShortname = `@${site.my_user.local_user_view.person.name}@lemmy-alpha:8541`;
|
|
|
|
let alphaPerson = (await resolvePerson(alpha, apShortname)).person;
|
|
expect(alphaPerson).toBeDefined();
|
|
});
|