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,
|
|
|
|
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;
|
|
|
|
|
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 () => {
|
2020-08-04 15:06:27 +00:00
|
|
|
let userRes = await registerUser(alpha);
|
|
|
|
expect(userRes.jwt).toBeDefined();
|
2023-01-04 15:59:26 +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();
|
2023-01-04 15:59:26 +00:00
|
|
|
if (!site.my_user) {
|
|
|
|
throw "Missing site user";
|
|
|
|
}
|
|
|
|
apShortname = `@${site.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);
|
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,
|
2023-01-04 15:59:26 +00:00
|
|
|
auth: userRes.jwt ?? "",
|
2022-10-27 09:24:07 +00:00
|
|
|
};
|
2022-04-07 20:52:17 +00:00
|
|
|
|
|
|
|
// make a local post and comment
|
2023-01-04 15:59:26 +00:00
|
|
|
let alphaCommunity = (await resolveCommunity(user, "!main@lemmy-alpha:8541"))
|
|
|
|
.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);
|
|
|
|
|
2023-01-04 15:59:26 +00:00
|
|
|
expect((await resolvePost(alpha, localPost)).post).toBeUndefined();
|
|
|
|
expect((await resolveComment(alpha, localComment)).comment).toBeUndefined();
|
|
|
|
expect((await resolvePost(alpha, remotePost)).post).toBeUndefined();
|
|
|
|
expect((await resolveComment(alpha, remoteComment)).comment).toBeUndefined();
|
2022-04-07 20:52:17 +00:00
|
|
|
});
|