2020-09-15 19:26:47 +00:00
|
|
|
jest.setTimeout(120000);
|
2022-10-27 09:24:07 +00:00
|
|
|
import { None } from "@sniptt/monads";
|
|
|
|
import { PersonViewSafe } from "lemmy-js-client";
|
2022-07-30 03:55:59 +00:00
|
|
|
|
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,
|
|
|
|
resolvePost,
|
|
|
|
API,
|
|
|
|
resolveComment,
|
2022-07-30 03:55:59 +00:00
|
|
|
saveUserSettingsFederated,
|
2022-10-13 16:30:31 +00:00
|
|
|
setupLogins,
|
2022-10-27 09:24:07 +00:00
|
|
|
} from "./shared";
|
2020-08-04 15:06:27 +00:00
|
|
|
|
2022-10-13 16:30:31 +00:00
|
|
|
beforeAll(async () => {
|
|
|
|
await setupLogins();
|
|
|
|
});
|
|
|
|
|
2020-08-04 15:06:27 +00:00
|
|
|
let apShortname: string;
|
|
|
|
|
2022-10-27 09:24:07 +00:00
|
|
|
function assertUserFederation(
|
|
|
|
userOne: PersonViewSafe,
|
|
|
|
userTwo: PersonViewSafe
|
|
|
|
) {
|
2021-03-12 19:09:03 +00:00
|
|
|
expect(userOne.person.name).toBe(userTwo.person.name);
|
2022-10-27 09:24:07 +00:00
|
|
|
expect(userOne.person.display_name.unwrapOr("none")).toBe(
|
|
|
|
userTwo.person.display_name.unwrapOr("none")
|
|
|
|
);
|
|
|
|
expect(userOne.person.bio.unwrapOr("none")).toBe(
|
|
|
|
userTwo.person.bio.unwrapOr("none")
|
|
|
|
);
|
2021-03-12 19:09:03 +00:00
|
|
|
expect(userOne.person.actor_id).toBe(userTwo.person.actor_id);
|
2022-10-27 09:24:07 +00:00
|
|
|
expect(userOne.person.avatar.unwrapOr("none")).toBe(
|
|
|
|
userTwo.person.avatar.unwrapOr("none")
|
|
|
|
);
|
|
|
|
expect(userOne.person.banner.unwrapOr("none")).toBe(
|
|
|
|
userTwo.person.banner.unwrapOr("none")
|
|
|
|
);
|
2021-03-12 19:09:03 +00:00
|
|
|
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 () => {
|
2020-08-04 15:06:27 +00:00
|
|
|
let userRes = await registerUser(alpha);
|
|
|
|
expect(userRes.jwt).toBeDefined();
|
2021-08-19 20:54:15 +00:00
|
|
|
alpha.auth = userRes.jwt;
|
2022-10-27 09:24:07 +00:00
|
|
|
|
2021-08-19 20:54:15 +00:00
|
|
|
let site = await getSite(alpha);
|
2020-08-04 15:06:27 +00:00
|
|
|
expect(site.my_user).toBeDefined();
|
2022-10-27 09:24:07 +00:00
|
|
|
apShortname = `@${
|
|
|
|
site.my_user.unwrap().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);
|
|
|
|
let alphaPerson = (await resolvePerson(alpha, apShortname)).person.unwrap();
|
|
|
|
let betaPerson = (await resolvePerson(beta, apShortname)).person.unwrap();
|
2021-08-23 15:25:39 +00:00
|
|
|
assertUserFederation(alphaPerson, betaPerson);
|
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 () => {
|
2022-04-07 20:52:17 +00:00
|
|
|
let userRes = await registerUser(alpha);
|
|
|
|
expect(userRes.jwt).toBeDefined();
|
|
|
|
let user: API = {
|
|
|
|
client: alpha.client,
|
2022-10-27 09:24:07 +00:00
|
|
|
auth: userRes.jwt,
|
|
|
|
};
|
2022-04-07 20:52:17 +00:00
|
|
|
|
|
|
|
// make a local post and comment
|
2022-10-27 09:24:07 +00:00
|
|
|
let alphaCommunity = (
|
|
|
|
await resolveCommunity(user, "!main@lemmy-alpha:8541")
|
|
|
|
).community.unwrap();
|
|
|
|
let localPost = (await createPost(user, alphaCommunity.community.id))
|
|
|
|
.post_view.post;
|
2022-04-07 20:52:17 +00:00
|
|
|
expect(localPost).toBeDefined();
|
2022-10-27 09:24:07 +00:00
|
|
|
let localComment = (await createComment(user, localPost.id, None))
|
|
|
|
.comment_view.comment;
|
2022-04-07 20:52:17 +00:00
|
|
|
expect(localComment).toBeDefined();
|
|
|
|
|
|
|
|
// make a remote post and comment
|
2022-07-30 03:55:59 +00:00
|
|
|
let betaCommunity = (await resolveBetaCommunity(user)).community.unwrap();
|
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();
|
2022-10-27 09:24:07 +00:00
|
|
|
let remoteComment = (await createComment(user, remotePost.id, None))
|
|
|
|
.comment_view.comment;
|
2022-04-07 20:52:17 +00:00
|
|
|
expect(remoteComment).toBeDefined();
|
|
|
|
|
|
|
|
await deleteUser(user);
|
|
|
|
|
2022-07-30 03:55:59 +00:00
|
|
|
expect((await resolvePost(alpha, localPost)).post.isNone()).toBe(true);
|
2022-10-27 09:24:07 +00:00
|
|
|
expect((await resolveComment(alpha, localComment)).comment.isNone()).toBe(
|
|
|
|
true
|
|
|
|
);
|
|
|
|
expect((await resolvePost(alpha, remotePost)).post.isNone()).toBe(true);
|
|
|
|
expect((await resolveComment(alpha, remoteComment)).comment.isNone()).toBe(
|
|
|
|
true
|
|
|
|
);
|
2022-04-07 20:52:17 +00:00
|
|
|
});
|