mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-08 09:24:17 +00:00
Removing sniptt/monads for lemmy-js-client. (#2644)
* Removing sniptt/monads for lemmy-js-client. * Fix tests.
This commit is contained in:
parent
b7d5b37ac9
commit
0630d214e3
|
@ -16,14 +16,9 @@
|
||||||
"warnOnUnsupportedTypeScriptVersion": false
|
"warnOnUnsupportedTypeScriptVersion": false
|
||||||
},
|
},
|
||||||
"rules": {
|
"rules": {
|
||||||
"@typescript-eslint/camelcase": 0,
|
"@typescript-eslint/ban-ts-comment": 0,
|
||||||
"@typescript-eslint/member-delimiter-style": 0,
|
|
||||||
"@typescript-eslint/no-empty-interface": 0,
|
|
||||||
"@typescript-eslint/no-explicit-any": 0,
|
"@typescript-eslint/no-explicit-any": 0,
|
||||||
"@typescript-eslint/no-this-alias": 0,
|
"@typescript-eslint/explicit-module-boundary-types": 0,
|
||||||
"@typescript-eslint/no-unused-vars": 0,
|
|
||||||
"@typescript-eslint/no-use-before-define": 0,
|
|
||||||
"@typescript-eslint/no-useless-constructor": 0,
|
|
||||||
"arrow-body-style": 0,
|
"arrow-body-style": 0,
|
||||||
"curly": 0,
|
"curly": 0,
|
||||||
"eol-last": 0,
|
"eol-last": 0,
|
||||||
|
|
|
@ -1,4 +0,0 @@
|
||||||
module.exports = Object.assign(require("eslint-plugin-prettier"), {
|
|
||||||
arrowParens: "avoid",
|
|
||||||
semi: true,
|
|
||||||
});
|
|
4
api_tests/.prettierrc.json
Normal file
4
api_tests/.prettierrc.json
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
"arrowParens": "avoid",
|
||||||
|
"semi": true
|
||||||
|
}
|
|
@ -7,23 +7,20 @@
|
||||||
"author": "Dessalines",
|
"author": "Dessalines",
|
||||||
"license": "AGPL-3.0",
|
"license": "AGPL-3.0",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"lint": "tsc --noEmit && eslint --report-unused-disable-directives --ext .js,.ts,.tsx src",
|
"lint": "tsc --noEmit && eslint --report-unused-disable-directives --ext .js,.ts,.tsx src && prettier --check 'src/**/*.ts'",
|
||||||
"fix": "prettier --write src && eslint --fix src",
|
"fix": "prettier --write src && eslint --fix src",
|
||||||
"api-test": "jest -i follow.spec.ts && jest -i src/post.spec.ts && jest -i comment.spec.ts && jest -i private_message.spec.ts && jest -i user.spec.ts && jest -i community.spec.ts"
|
"api-test": "jest -i follow.spec.ts && jest -i src/post.spec.ts && jest -i comment.spec.ts && jest -i private_message.spec.ts && jest -i user.spec.ts && jest -i community.spec.ts"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@sniptt/monads": "^0.5.10",
|
|
||||||
"@types/jest": "^26.0.23",
|
"@types/jest": "^26.0.23",
|
||||||
"@typescript-eslint/eslint-plugin": "^5.21.0",
|
"@typescript-eslint/eslint-plugin": "^5.21.0",
|
||||||
"@typescript-eslint/parser": "^5.21.0",
|
"@typescript-eslint/parser": "^5.21.0",
|
||||||
"class-transformer": "^0.5.1",
|
|
||||||
"eslint": "^8.25.0",
|
"eslint": "^8.25.0",
|
||||||
"eslint-plugin-prettier": "^4.0.0",
|
"eslint-plugin-prettier": "^4.0.0",
|
||||||
"jest": "^27.0.6",
|
"jest": "^27.0.6",
|
||||||
"lemmy-js-client": "0.17.0-rc.56",
|
"lemmy-js-client": "0.17.0-rc.60",
|
||||||
"node-fetch": "^2.6.1",
|
"node-fetch": "^2.6.1",
|
||||||
"prettier": "^2.7.1",
|
"prettier": "^2.7.1",
|
||||||
"reflect-metadata": "^0.1.13",
|
|
||||||
"ts-jest": "^27.0.3",
|
"ts-jest": "^27.0.3",
|
||||||
"typescript": "^4.8.4"
|
"typescript": "^4.8.4"
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
jest.setTimeout(180000);
|
jest.setTimeout(180000);
|
||||||
import { None, Some } from "@sniptt/monads";
|
|
||||||
import { CommentView } from "lemmy-js-client";
|
import { CommentView } from "lemmy-js-client";
|
||||||
import { PostResponse } from "lemmy-js-client";
|
import { PostResponse } from "lemmy-js-client";
|
||||||
|
|
||||||
|
@ -41,7 +40,9 @@ beforeAll(async () => {
|
||||||
await followBeta(alpha);
|
await followBeta(alpha);
|
||||||
await followBeta(gamma);
|
await followBeta(gamma);
|
||||||
let betaCommunity = (await resolveBetaCommunity(alpha)).community;
|
let betaCommunity = (await resolveBetaCommunity(alpha)).community;
|
||||||
postRes = await createPost(alpha, betaCommunity.unwrap().community.id);
|
if (betaCommunity) {
|
||||||
|
postRes = await createPost(alpha, betaCommunity.community.id);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
afterAll(async () => {
|
afterAll(async () => {
|
||||||
|
@ -49,21 +50,21 @@ afterAll(async () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
function assertCommentFederation(
|
function assertCommentFederation(
|
||||||
commentOne: CommentView,
|
commentOne?: CommentView,
|
||||||
commentTwo: CommentView
|
commentTwo?: CommentView
|
||||||
) {
|
) {
|
||||||
expect(commentOne.comment.ap_id).toBe(commentOne.comment.ap_id);
|
expect(commentOne?.comment.ap_id).toBe(commentTwo?.comment.ap_id);
|
||||||
expect(commentOne.comment.content).toBe(commentTwo.comment.content);
|
expect(commentOne?.comment.content).toBe(commentTwo?.comment.content);
|
||||||
expect(commentOne.creator.name).toBe(commentTwo.creator.name);
|
expect(commentOne?.creator.name).toBe(commentTwo?.creator.name);
|
||||||
expect(commentOne.community.actor_id).toBe(commentTwo.community.actor_id);
|
expect(commentOne?.community.actor_id).toBe(commentTwo?.community.actor_id);
|
||||||
expect(commentOne.comment.published).toBe(commentTwo.comment.published);
|
expect(commentOne?.comment.published).toBe(commentTwo?.comment.published);
|
||||||
expect(commentOne.comment.updated).toBe(commentOne.comment.updated);
|
expect(commentOne?.comment.updated).toBe(commentOne?.comment.updated);
|
||||||
expect(commentOne.comment.deleted).toBe(commentOne.comment.deleted);
|
expect(commentOne?.comment.deleted).toBe(commentOne?.comment.deleted);
|
||||||
expect(commentOne.comment.removed).toBe(commentOne.comment.removed);
|
expect(commentOne?.comment.removed).toBe(commentOne?.comment.removed);
|
||||||
}
|
}
|
||||||
|
|
||||||
test("Create a comment", async () => {
|
test("Create a comment", async () => {
|
||||||
let commentRes = await createComment(alpha, postRes.post_view.post.id, None);
|
let commentRes = await createComment(alpha, postRes.post_view.post.id);
|
||||||
expect(commentRes.comment_view.comment.content).toBeDefined();
|
expect(commentRes.comment_view.comment.content).toBeDefined();
|
||||||
expect(commentRes.comment_view.community.local).toBe(false);
|
expect(commentRes.comment_view.community.local).toBe(false);
|
||||||
expect(commentRes.comment_view.creator.local).toBe(true);
|
expect(commentRes.comment_view.creator.local).toBe(true);
|
||||||
|
@ -72,26 +73,26 @@ test("Create a comment", async () => {
|
||||||
// Make sure that comment is liked on beta
|
// Make sure that comment is liked on beta
|
||||||
let betaComment = (
|
let betaComment = (
|
||||||
await resolveComment(beta, commentRes.comment_view.comment)
|
await resolveComment(beta, commentRes.comment_view.comment)
|
||||||
).comment.unwrap();
|
).comment;
|
||||||
expect(betaComment).toBeDefined();
|
expect(betaComment).toBeDefined();
|
||||||
expect(betaComment.community.local).toBe(true);
|
expect(betaComment?.community.local).toBe(true);
|
||||||
expect(betaComment.creator.local).toBe(false);
|
expect(betaComment?.creator.local).toBe(false);
|
||||||
expect(betaComment.counts.score).toBe(1);
|
expect(betaComment?.counts.score).toBe(1);
|
||||||
assertCommentFederation(betaComment, commentRes.comment_view);
|
assertCommentFederation(betaComment, commentRes.comment_view);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("Create a comment in a non-existent post", async () => {
|
test("Create a comment in a non-existent post", async () => {
|
||||||
let commentRes = (await createComment(alpha, -1, None)) as any;
|
let commentRes = (await createComment(alpha, -1)) as any;
|
||||||
expect(commentRes.error).toBe("couldnt_find_post");
|
expect(commentRes.error).toBe("couldnt_find_post");
|
||||||
});
|
});
|
||||||
|
|
||||||
test("Update a comment", async () => {
|
test("Update a comment", async () => {
|
||||||
let commentRes = await createComment(alpha, postRes.post_view.post.id, None);
|
let commentRes = await createComment(alpha, postRes.post_view.post.id);
|
||||||
// Federate the comment first
|
// Federate the comment first
|
||||||
let betaComment = (
|
let betaComment = (
|
||||||
await resolveComment(beta, commentRes.comment_view.comment)
|
await resolveComment(beta, commentRes.comment_view.comment)
|
||||||
).comment;
|
).comment;
|
||||||
assertCommentFederation(betaComment.unwrap(), commentRes.comment_view);
|
assertCommentFederation(betaComment, commentRes.comment_view);
|
||||||
|
|
||||||
let updateCommentRes = await editComment(
|
let updateCommentRes = await editComment(
|
||||||
alpha,
|
alpha,
|
||||||
|
@ -106,12 +107,12 @@ test("Update a comment", async () => {
|
||||||
// Make sure that post is updated on beta
|
// Make sure that post is updated on beta
|
||||||
let betaCommentUpdated = (
|
let betaCommentUpdated = (
|
||||||
await resolveComment(beta, commentRes.comment_view.comment)
|
await resolveComment(beta, commentRes.comment_view.comment)
|
||||||
).comment.unwrap();
|
).comment;
|
||||||
assertCommentFederation(betaCommentUpdated, updateCommentRes.comment_view);
|
assertCommentFederation(betaCommentUpdated, updateCommentRes.comment_view);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("Delete a comment", async () => {
|
test("Delete a comment", async () => {
|
||||||
let commentRes = await createComment(alpha, postRes.post_view.post.id, None);
|
let commentRes = await createComment(alpha, postRes.post_view.post.id);
|
||||||
|
|
||||||
let deleteCommentRes = await deleteComment(
|
let deleteCommentRes = await deleteComment(
|
||||||
alpha,
|
alpha,
|
||||||
|
@ -138,18 +139,22 @@ test("Delete a comment", async () => {
|
||||||
// Make sure that comment is undeleted on beta
|
// Make sure that comment is undeleted on beta
|
||||||
let betaComment2 = (
|
let betaComment2 = (
|
||||||
await resolveComment(beta, commentRes.comment_view.comment)
|
await resolveComment(beta, commentRes.comment_view.comment)
|
||||||
).comment.unwrap();
|
).comment;
|
||||||
expect(betaComment2.comment.deleted).toBe(false);
|
expect(betaComment2?.comment.deleted).toBe(false);
|
||||||
assertCommentFederation(betaComment2, undeleteCommentRes.comment_view);
|
assertCommentFederation(betaComment2, undeleteCommentRes.comment_view);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("Remove a comment from admin and community on the same instance", async () => {
|
test("Remove a comment from admin and community on the same instance", async () => {
|
||||||
let commentRes = await createComment(alpha, postRes.post_view.post.id, None);
|
let commentRes = await createComment(alpha, postRes.post_view.post.id);
|
||||||
|
|
||||||
// Get the id for beta
|
// Get the id for beta
|
||||||
let betaCommentId = (
|
let betaCommentId = (
|
||||||
await resolveComment(beta, commentRes.comment_view.comment)
|
await resolveComment(beta, commentRes.comment_view.comment)
|
||||||
).comment.unwrap().comment.id;
|
).comment?.comment.id;
|
||||||
|
|
||||||
|
if (!betaCommentId) {
|
||||||
|
throw "beta comment id is missing";
|
||||||
|
}
|
||||||
|
|
||||||
// The beta admin removes it (the community lives on beta)
|
// The beta admin removes it (the community lives on beta)
|
||||||
let removeCommentRes = await removeComment(beta, true, betaCommentId);
|
let removeCommentRes = await removeComment(beta, true, betaCommentId);
|
||||||
|
@ -182,7 +187,7 @@ test("Remove a comment from admin and community on different instance", async ()
|
||||||
let alpha_user = await registerUser(alpha);
|
let alpha_user = await registerUser(alpha);
|
||||||
let newAlphaApi: API = {
|
let newAlphaApi: API = {
|
||||||
client: alpha.client,
|
client: alpha.client,
|
||||||
auth: alpha_user.jwt,
|
auth: alpha_user.jwt ?? "",
|
||||||
};
|
};
|
||||||
|
|
||||||
// New alpha user creates a community, post, and comment.
|
// New alpha user creates a community, post, and comment.
|
||||||
|
@ -191,17 +196,18 @@ test("Remove a comment from admin and community on different instance", async ()
|
||||||
newAlphaApi,
|
newAlphaApi,
|
||||||
newCommunity.community_view.community.id
|
newCommunity.community_view.community.id
|
||||||
);
|
);
|
||||||
let commentRes = await createComment(
|
let commentRes = await createComment(newAlphaApi, newPost.post_view.post.id);
|
||||||
newAlphaApi,
|
|
||||||
newPost.post_view.post.id,
|
|
||||||
None
|
|
||||||
);
|
|
||||||
expect(commentRes.comment_view.comment.content).toBeDefined();
|
expect(commentRes.comment_view.comment.content).toBeDefined();
|
||||||
|
|
||||||
// Beta searches that to cache it, then removes it
|
// Beta searches that to cache it, then removes it
|
||||||
let betaComment = (
|
let betaComment = (
|
||||||
await resolveComment(beta, commentRes.comment_view.comment)
|
await resolveComment(beta, commentRes.comment_view.comment)
|
||||||
).comment.unwrap();
|
).comment;
|
||||||
|
|
||||||
|
if (!betaComment) {
|
||||||
|
throw "beta comment missing";
|
||||||
|
}
|
||||||
|
|
||||||
let removeCommentRes = await removeComment(
|
let removeCommentRes = await removeComment(
|
||||||
beta,
|
beta,
|
||||||
true,
|
true,
|
||||||
|
@ -222,27 +228,31 @@ test("Remove a comment from admin and community on different instance", async ()
|
||||||
});
|
});
|
||||||
|
|
||||||
test("Unlike a comment", async () => {
|
test("Unlike a comment", async () => {
|
||||||
let commentRes = await createComment(alpha, postRes.post_view.post.id, None);
|
let commentRes = await createComment(alpha, postRes.post_view.post.id);
|
||||||
let unlike = await likeComment(alpha, 0, commentRes.comment_view.comment);
|
let unlike = await likeComment(alpha, 0, commentRes.comment_view.comment);
|
||||||
expect(unlike.comment_view.counts.score).toBe(0);
|
expect(unlike.comment_view.counts.score).toBe(0);
|
||||||
|
|
||||||
// Make sure that post is unliked on beta
|
// Make sure that post is unliked on beta
|
||||||
let betaComment = (
|
let betaComment = (
|
||||||
await resolveComment(beta, commentRes.comment_view.comment)
|
await resolveComment(beta, commentRes.comment_view.comment)
|
||||||
).comment.unwrap();
|
).comment;
|
||||||
expect(betaComment).toBeDefined();
|
expect(betaComment).toBeDefined();
|
||||||
expect(betaComment.community.local).toBe(true);
|
expect(betaComment?.community.local).toBe(true);
|
||||||
expect(betaComment.creator.local).toBe(false);
|
expect(betaComment?.creator.local).toBe(false);
|
||||||
expect(betaComment.counts.score).toBe(0);
|
expect(betaComment?.counts.score).toBe(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("Federated comment like", async () => {
|
test("Federated comment like", async () => {
|
||||||
let commentRes = await createComment(alpha, postRes.post_view.post.id, None);
|
let commentRes = await createComment(alpha, postRes.post_view.post.id);
|
||||||
|
|
||||||
// Find the comment on beta
|
// Find the comment on beta
|
||||||
let betaComment = (
|
let betaComment = (
|
||||||
await resolveComment(beta, commentRes.comment_view.comment)
|
await resolveComment(beta, commentRes.comment_view.comment)
|
||||||
).comment.unwrap();
|
).comment;
|
||||||
|
|
||||||
|
if (!betaComment) {
|
||||||
|
throw "Missing beta comment";
|
||||||
|
}
|
||||||
|
|
||||||
let like = await likeComment(beta, 1, betaComment.comment);
|
let like = await likeComment(beta, 1, betaComment.comment);
|
||||||
expect(like.comment_view.counts.score).toBe(2);
|
expect(like.comment_view.counts.score).toBe(2);
|
||||||
|
@ -254,10 +264,14 @@ test("Federated comment like", async () => {
|
||||||
|
|
||||||
test("Reply to a comment", async () => {
|
test("Reply to a comment", async () => {
|
||||||
// Create a comment on alpha, find it on beta
|
// Create a comment on alpha, find it on beta
|
||||||
let commentRes = await createComment(alpha, postRes.post_view.post.id, None);
|
let commentRes = await createComment(alpha, postRes.post_view.post.id);
|
||||||
let betaComment = (
|
let betaComment = (
|
||||||
await resolveComment(beta, commentRes.comment_view.comment)
|
await resolveComment(beta, commentRes.comment_view.comment)
|
||||||
).comment.unwrap();
|
).comment;
|
||||||
|
|
||||||
|
if (!betaComment) {
|
||||||
|
throw "Missing beta comment";
|
||||||
|
}
|
||||||
|
|
||||||
// find that comment id on beta
|
// find that comment id on beta
|
||||||
|
|
||||||
|
@ -265,12 +279,12 @@ test("Reply to a comment", async () => {
|
||||||
let replyRes = await createComment(
|
let replyRes = await createComment(
|
||||||
beta,
|
beta,
|
||||||
betaComment.post.id,
|
betaComment.post.id,
|
||||||
Some(betaComment.comment.id)
|
betaComment.comment.id
|
||||||
);
|
);
|
||||||
expect(replyRes.comment_view.comment.content).toBeDefined();
|
expect(replyRes.comment_view.comment.content).toBeDefined();
|
||||||
expect(replyRes.comment_view.community.local).toBe(true);
|
expect(replyRes.comment_view.community.local).toBe(true);
|
||||||
expect(replyRes.comment_view.creator.local).toBe(true);
|
expect(replyRes.comment_view.creator.local).toBe(true);
|
||||||
expect(getCommentParentId(replyRes.comment_view.comment).unwrap()).toBe(
|
expect(getCommentParentId(replyRes.comment_view.comment)).toBe(
|
||||||
betaComment.comment.id
|
betaComment.comment.id
|
||||||
);
|
);
|
||||||
expect(replyRes.comment_view.counts.score).toBe(1);
|
expect(replyRes.comment_view.counts.score).toBe(1);
|
||||||
|
@ -282,7 +296,7 @@ test("Reply to a comment", async () => {
|
||||||
let postComments = await getComments(alpha, postRes.post_view.post.id);
|
let postComments = await getComments(alpha, postRes.post_view.post.id);
|
||||||
let alphaComment = postComments.comments[0];
|
let alphaComment = postComments.comments[0];
|
||||||
expect(alphaComment.comment.content).toBeDefined();
|
expect(alphaComment.comment.content).toBeDefined();
|
||||||
expect(getCommentParentId(alphaComment.comment).unwrap()).toBe(
|
expect(getCommentParentId(alphaComment.comment)).toBe(
|
||||||
postComments.comments[1].comment.id
|
postComments.comments[1].comment.id
|
||||||
);
|
);
|
||||||
expect(alphaComment.community.local).toBe(false);
|
expect(alphaComment.community.local).toBe(false);
|
||||||
|
@ -294,11 +308,11 @@ test("Reply to a comment", async () => {
|
||||||
test("Mention beta", async () => {
|
test("Mention beta", async () => {
|
||||||
// Create a mention on alpha
|
// Create a mention on alpha
|
||||||
let mentionContent = "A test mention of @lemmy_beta@lemmy-beta:8551";
|
let mentionContent = "A test mention of @lemmy_beta@lemmy-beta:8551";
|
||||||
let commentRes = await createComment(alpha, postRes.post_view.post.id, None);
|
let commentRes = await createComment(alpha, postRes.post_view.post.id);
|
||||||
let mentionRes = await createComment(
|
let mentionRes = await createComment(
|
||||||
alpha,
|
alpha,
|
||||||
postRes.post_view.post.id,
|
postRes.post_view.post.id,
|
||||||
Some(commentRes.comment_view.comment.id),
|
commentRes.comment_view.comment.id,
|
||||||
mentionContent
|
mentionContent
|
||||||
);
|
);
|
||||||
expect(mentionRes.comment_view.comment.content).toBeDefined();
|
expect(mentionRes.comment_view.comment.content).toBeDefined();
|
||||||
|
@ -314,32 +328,38 @@ test("Mention beta", async () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("Comment Search", async () => {
|
test("Comment Search", async () => {
|
||||||
let commentRes = await createComment(alpha, postRes.post_view.post.id, None);
|
let commentRes = await createComment(alpha, postRes.post_view.post.id);
|
||||||
let betaComment = (
|
let betaComment = (
|
||||||
await resolveComment(beta, commentRes.comment_view.comment)
|
await resolveComment(beta, commentRes.comment_view.comment)
|
||||||
).comment.unwrap();
|
).comment;
|
||||||
assertCommentFederation(betaComment, commentRes.comment_view);
|
assertCommentFederation(betaComment, commentRes.comment_view);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("A and G subscribe to B (center) A posts, G mentions B, it gets announced to A", async () => {
|
test("A and G subscribe to B (center) A posts, G mentions B, it gets announced to A", async () => {
|
||||||
// Create a local post
|
// Create a local post
|
||||||
let alphaCommunity = (
|
let alphaCommunity = (await resolveCommunity(alpha, "!main@lemmy-alpha:8541"))
|
||||||
await resolveCommunity(alpha, "!main@lemmy-alpha:8541")
|
.community;
|
||||||
).community.unwrap();
|
|
||||||
|
if (!alphaCommunity) {
|
||||||
|
throw "Missing alpha community";
|
||||||
|
}
|
||||||
|
|
||||||
let alphaPost = await createPost(alpha, alphaCommunity.community.id);
|
let alphaPost = await createPost(alpha, alphaCommunity.community.id);
|
||||||
expect(alphaPost.post_view.community.local).toBe(true);
|
expect(alphaPost.post_view.community.local).toBe(true);
|
||||||
|
|
||||||
// Make sure gamma sees it
|
// Make sure gamma sees it
|
||||||
let gammaPost = (
|
let gammaPost = (await resolvePost(gamma, alphaPost.post_view.post)).post;
|
||||||
await resolvePost(gamma, alphaPost.post_view.post)
|
|
||||||
).post.unwrap();
|
if (!gammaPost) {
|
||||||
|
throw "Missing gamma post";
|
||||||
|
}
|
||||||
|
|
||||||
let commentContent =
|
let commentContent =
|
||||||
"A jest test federated comment announce, lets mention @lemmy_beta@lemmy-beta:8551";
|
"A jest test federated comment announce, lets mention @lemmy_beta@lemmy-beta:8551";
|
||||||
let commentRes = await createComment(
|
let commentRes = await createComment(
|
||||||
gamma,
|
gamma,
|
||||||
gammaPost.post.id,
|
gammaPost.post.id,
|
||||||
None,
|
undefined,
|
||||||
commentContent
|
commentContent
|
||||||
);
|
);
|
||||||
expect(commentRes.comment_view.comment.content).toBe(commentContent);
|
expect(commentRes.comment_view.comment.content).toBe(commentContent);
|
||||||
|
@ -385,13 +405,16 @@ test("Check that activity from another instance is sent to third instance", asyn
|
||||||
expect(betaPost.post_view.community.local).toBe(true);
|
expect(betaPost.post_view.community.local).toBe(true);
|
||||||
|
|
||||||
// Make sure gamma and alpha see it
|
// Make sure gamma and alpha see it
|
||||||
let gammaPost = (
|
let gammaPost = (await resolvePost(gamma, betaPost.post_view.post)).post;
|
||||||
await resolvePost(gamma, betaPost.post_view.post)
|
if (!gammaPost) {
|
||||||
).post.unwrap();
|
throw "Missing gamma post";
|
||||||
|
}
|
||||||
expect(gammaPost.post).toBeDefined();
|
expect(gammaPost.post).toBeDefined();
|
||||||
let alphaPost = (
|
|
||||||
await resolvePost(alpha, betaPost.post_view.post)
|
let alphaPost = (await resolvePost(alpha, betaPost.post_view.post)).post;
|
||||||
).post.unwrap();
|
if (!alphaPost) {
|
||||||
|
throw "Missing alpha post";
|
||||||
|
}
|
||||||
expect(alphaPost.post).toBeDefined();
|
expect(alphaPost.post).toBeDefined();
|
||||||
|
|
||||||
// The bug: gamma comments, and alpha should see it.
|
// The bug: gamma comments, and alpha should see it.
|
||||||
|
@ -399,7 +422,7 @@ test("Check that activity from another instance is sent to third instance", asyn
|
||||||
let commentRes = await createComment(
|
let commentRes = await createComment(
|
||||||
gamma,
|
gamma,
|
||||||
gammaPost.post.id,
|
gammaPost.post.id,
|
||||||
None,
|
undefined,
|
||||||
commentContent
|
commentContent
|
||||||
);
|
);
|
||||||
expect(commentRes.comment_view.comment.content).toBe(commentContent);
|
expect(commentRes.comment_view.comment.content).toBe(commentContent);
|
||||||
|
@ -426,7 +449,7 @@ test("Fetch in_reply_tos: A is unsubbed from B, B makes a post, and some embedde
|
||||||
// Unfollow all remote communities
|
// Unfollow all remote communities
|
||||||
let site = await unfollowRemotes(alpha);
|
let site = await unfollowRemotes(alpha);
|
||||||
expect(
|
expect(
|
||||||
site.my_user.unwrap().follows.filter(c => c.community.local == false).length
|
site.my_user?.follows.filter(c => c.community.local == false).length
|
||||||
).toBe(0);
|
).toBe(0);
|
||||||
|
|
||||||
// B creates a post, and two comments, should be invisible to A
|
// B creates a post, and two comments, should be invisible to A
|
||||||
|
@ -437,7 +460,7 @@ test("Fetch in_reply_tos: A is unsubbed from B, B makes a post, and some embedde
|
||||||
let parentCommentRes = await createComment(
|
let parentCommentRes = await createComment(
|
||||||
beta,
|
beta,
|
||||||
postRes.post_view.post.id,
|
postRes.post_view.post.id,
|
||||||
None,
|
undefined,
|
||||||
parentCommentContent
|
parentCommentContent
|
||||||
);
|
);
|
||||||
expect(parentCommentRes.comment_view.comment.content).toBe(
|
expect(parentCommentRes.comment_view.comment.content).toBe(
|
||||||
|
@ -449,7 +472,7 @@ test("Fetch in_reply_tos: A is unsubbed from B, B makes a post, and some embedde
|
||||||
let childCommentRes = await createComment(
|
let childCommentRes = await createComment(
|
||||||
beta,
|
beta,
|
||||||
postRes.post_view.post.id,
|
postRes.post_view.post.id,
|
||||||
Some(parentCommentRes.comment_view.comment.id),
|
parentCommentRes.comment_view.comment.id,
|
||||||
childCommentContent
|
childCommentContent
|
||||||
);
|
);
|
||||||
expect(childCommentRes.comment_view.comment.content).toBe(
|
expect(childCommentRes.comment_view.comment.content).toBe(
|
||||||
|
@ -462,20 +485,19 @@ test("Fetch in_reply_tos: A is unsubbed from B, B makes a post, and some embedde
|
||||||
expect(follow.community_view.community.name).toBe("main");
|
expect(follow.community_view.community.name).toBe("main");
|
||||||
|
|
||||||
// An update to the child comment on beta, should push the post, parent, and child to alpha now
|
// An update to the child comment on beta, should push the post, parent, and child to alpha now
|
||||||
let updatedCommentContent = Some("An update child comment from beta");
|
let updatedCommentContent = "An update child comment from beta";
|
||||||
let updateRes = await editComment(
|
let updateRes = await editComment(
|
||||||
beta,
|
beta,
|
||||||
childCommentRes.comment_view.comment.id,
|
childCommentRes.comment_view.comment.id,
|
||||||
updatedCommentContent
|
updatedCommentContent
|
||||||
);
|
);
|
||||||
expect(updateRes.comment_view.comment.content).toBe(
|
expect(updateRes.comment_view.comment.content).toBe(updatedCommentContent);
|
||||||
updatedCommentContent.unwrap()
|
|
||||||
);
|
|
||||||
|
|
||||||
// Get the post from alpha
|
// Get the post from alpha
|
||||||
let alphaPostB = (
|
let alphaPostB = (await resolvePost(alpha, postRes.post_view.post)).post;
|
||||||
await resolvePost(alpha, postRes.post_view.post)
|
if (!alphaPostB) {
|
||||||
).post.unwrap();
|
throw "Missing alpha post B";
|
||||||
|
}
|
||||||
|
|
||||||
let alphaPost = await getPost(alpha, alphaPostB.post.id);
|
let alphaPost = await getPost(alpha, alphaPostB.post.id);
|
||||||
let alphaPostComments = await getComments(alpha, alphaPostB.post.id);
|
let alphaPostComments = await getComments(alpha, alphaPostB.post.id);
|
||||||
|
@ -495,16 +517,21 @@ test("Fetch in_reply_tos: A is unsubbed from B, B makes a post, and some embedde
|
||||||
});
|
});
|
||||||
|
|
||||||
test("Report a comment", async () => {
|
test("Report a comment", async () => {
|
||||||
let betaCommunity = (await resolveBetaCommunity(beta)).community.unwrap();
|
let betaCommunity = (await resolveBetaCommunity(beta)).community;
|
||||||
|
if (!betaCommunity) {
|
||||||
|
throw "Missing beta community";
|
||||||
|
}
|
||||||
let postRes = (await createPost(beta, betaCommunity.community.id)).post_view
|
let postRes = (await createPost(beta, betaCommunity.community.id)).post_view
|
||||||
.post;
|
.post;
|
||||||
expect(postRes).toBeDefined();
|
expect(postRes).toBeDefined();
|
||||||
let commentRes = (await createComment(beta, postRes.id, None)).comment_view
|
let commentRes = (await createComment(beta, postRes.id)).comment_view.comment;
|
||||||
.comment;
|
|
||||||
expect(commentRes).toBeDefined();
|
expect(commentRes).toBeDefined();
|
||||||
|
|
||||||
let alphaComment = (await resolveComment(alpha, commentRes)).comment.unwrap()
|
let alphaComment = (await resolveComment(alpha, commentRes)).comment?.comment;
|
||||||
.comment;
|
if (!alphaComment) {
|
||||||
|
throw "Missing alpha comment";
|
||||||
|
}
|
||||||
|
|
||||||
let alphaReport = (
|
let alphaReport = (
|
||||||
await reportComment(alpha, alphaComment.id, randomString(10))
|
await reportComment(alpha, alphaComment.id, randomString(10))
|
||||||
).comment_report_view.comment_report;
|
).comment_report_view.comment_report;
|
||||||
|
|
|
@ -25,27 +25,25 @@ beforeAll(async () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
function assertCommunityFederation(
|
function assertCommunityFederation(
|
||||||
communityOne: CommunityView,
|
communityOne?: CommunityView,
|
||||||
communityTwo: CommunityView
|
communityTwo?: CommunityView
|
||||||
) {
|
) {
|
||||||
expect(communityOne.community.actor_id).toBe(communityTwo.community.actor_id);
|
expect(communityOne?.community.actor_id).toBe(
|
||||||
expect(communityOne.community.name).toBe(communityTwo.community.name);
|
communityTwo?.community.actor_id
|
||||||
expect(communityOne.community.title).toBe(communityTwo.community.title);
|
|
||||||
expect(communityOne.community.description.unwrapOr("none")).toBe(
|
|
||||||
communityTwo.community.description.unwrapOr("none")
|
|
||||||
);
|
);
|
||||||
expect(communityOne.community.icon.unwrapOr("none")).toBe(
|
expect(communityOne?.community.name).toBe(communityTwo?.community.name);
|
||||||
communityTwo.community.icon.unwrapOr("none")
|
expect(communityOne?.community.title).toBe(communityTwo?.community.title);
|
||||||
|
expect(communityOne?.community.description).toBe(
|
||||||
|
communityTwo?.community.description
|
||||||
);
|
);
|
||||||
expect(communityOne.community.banner.unwrapOr("none")).toBe(
|
expect(communityOne?.community.icon).toBe(communityTwo?.community.icon);
|
||||||
communityTwo.community.banner.unwrapOr("none")
|
expect(communityOne?.community.banner).toBe(communityTwo?.community.banner);
|
||||||
|
expect(communityOne?.community.published).toBe(
|
||||||
|
communityTwo?.community.published
|
||||||
);
|
);
|
||||||
expect(communityOne.community.published).toBe(
|
expect(communityOne?.community.nsfw).toBe(communityTwo?.community.nsfw);
|
||||||
communityTwo.community.published
|
expect(communityOne?.community.removed).toBe(communityTwo?.community.removed);
|
||||||
);
|
expect(communityOne?.community.deleted).toBe(communityTwo?.community.deleted);
|
||||||
expect(communityOne.community.nsfw).toBe(communityTwo.community.nsfw);
|
|
||||||
expect(communityOne.community.removed).toBe(communityTwo.community.removed);
|
|
||||||
expect(communityOne.community.deleted).toBe(communityTwo.community.deleted);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
test("Create community", async () => {
|
test("Create community", async () => {
|
||||||
|
@ -59,9 +57,7 @@ test("Create community", async () => {
|
||||||
|
|
||||||
// Cache the community on beta, make sure it has the other fields
|
// Cache the community on beta, make sure it has the other fields
|
||||||
let searchShort = `!${prevName}@lemmy-alpha:8541`;
|
let searchShort = `!${prevName}@lemmy-alpha:8541`;
|
||||||
let betaCommunity = (
|
let betaCommunity = (await resolveCommunity(beta, searchShort)).community;
|
||||||
await resolveCommunity(beta, searchShort)
|
|
||||||
).community.unwrap();
|
|
||||||
assertCommunityFederation(betaCommunity, communityRes.community_view);
|
assertCommunityFederation(betaCommunity, communityRes.community_view);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -70,9 +66,10 @@ test("Delete community", async () => {
|
||||||
|
|
||||||
// Cache the community on Alpha
|
// Cache the community on Alpha
|
||||||
let searchShort = `!${communityRes.community_view.community.name}@lemmy-beta:8551`;
|
let searchShort = `!${communityRes.community_view.community.name}@lemmy-beta:8551`;
|
||||||
let alphaCommunity = (
|
let alphaCommunity = (await resolveCommunity(alpha, searchShort)).community;
|
||||||
await resolveCommunity(alpha, searchShort)
|
if (!alphaCommunity) {
|
||||||
).community.unwrap();
|
throw "Missing alpha community";
|
||||||
|
}
|
||||||
assertCommunityFederation(alphaCommunity, communityRes.community_view);
|
assertCommunityFederation(alphaCommunity, communityRes.community_view);
|
||||||
|
|
||||||
// Follow the community from alpha
|
// Follow the community from alpha
|
||||||
|
@ -121,9 +118,10 @@ test("Remove community", async () => {
|
||||||
|
|
||||||
// Cache the community on Alpha
|
// Cache the community on Alpha
|
||||||
let searchShort = `!${communityRes.community_view.community.name}@lemmy-beta:8551`;
|
let searchShort = `!${communityRes.community_view.community.name}@lemmy-beta:8551`;
|
||||||
let alphaCommunity = (
|
let alphaCommunity = (await resolveCommunity(alpha, searchShort)).community;
|
||||||
await resolveCommunity(alpha, searchShort)
|
if (!alphaCommunity) {
|
||||||
).community.unwrap();
|
throw "Missing alpha community";
|
||||||
|
}
|
||||||
assertCommunityFederation(alphaCommunity, communityRes.community_view);
|
assertCommunityFederation(alphaCommunity, communityRes.community_view);
|
||||||
|
|
||||||
// Follow the community from alpha
|
// Follow the community from alpha
|
||||||
|
@ -172,9 +170,7 @@ test("Search for beta community", async () => {
|
||||||
expect(communityRes.community_view.community.name).toBeDefined();
|
expect(communityRes.community_view.community.name).toBeDefined();
|
||||||
|
|
||||||
let searchShort = `!${communityRes.community_view.community.name}@lemmy-beta:8551`;
|
let searchShort = `!${communityRes.community_view.community.name}@lemmy-beta:8551`;
|
||||||
let alphaCommunity = (
|
let alphaCommunity = (await resolveCommunity(alpha, searchShort)).community;
|
||||||
await resolveCommunity(alpha, searchShort)
|
|
||||||
).community.unwrap();
|
|
||||||
assertCommunityFederation(alphaCommunity, communityRes.community_view);
|
assertCommunityFederation(alphaCommunity, communityRes.community_view);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -186,15 +182,17 @@ test("Admin actions in remote community are not federated to origin", async () =
|
||||||
// gamma follows community and posts in it
|
// gamma follows community and posts in it
|
||||||
let gammaCommunity = (
|
let gammaCommunity = (
|
||||||
await resolveCommunity(gamma, communityRes.community.actor_id)
|
await resolveCommunity(gamma, communityRes.community.actor_id)
|
||||||
).community.unwrap();
|
).community;
|
||||||
await followCommunity(
|
if (!gammaCommunity) {
|
||||||
gamma,
|
throw "Missing gamma community";
|
||||||
true,
|
}
|
||||||
gammaCommunity.community.id
|
await followCommunity(gamma, true, gammaCommunity.community.id);
|
||||||
);
|
|
||||||
gammaCommunity = (
|
gammaCommunity = (
|
||||||
await resolveCommunity(gamma, communityRes.community.actor_id)
|
await resolveCommunity(gamma, communityRes.community.actor_id)
|
||||||
).community.unwrap();
|
).community;
|
||||||
|
if (!gammaCommunity) {
|
||||||
|
throw "Missing gamma community";
|
||||||
|
}
|
||||||
expect(gammaCommunity.subscribed).toBe("Subscribed");
|
expect(gammaCommunity.subscribed).toBe("Subscribed");
|
||||||
let gammaPost = (await createPost(gamma, gammaCommunity.community.id))
|
let gammaPost = (await createPost(gamma, gammaCommunity.community.id))
|
||||||
.post_view;
|
.post_view;
|
||||||
|
@ -204,12 +202,19 @@ test("Admin actions in remote community are not federated to origin", async () =
|
||||||
// admin of beta decides to ban gamma from community
|
// admin of beta decides to ban gamma from community
|
||||||
let betaCommunity = (
|
let betaCommunity = (
|
||||||
await resolveCommunity(beta, communityRes.community.actor_id)
|
await resolveCommunity(beta, communityRes.community.actor_id)
|
||||||
).community.unwrap();
|
).community;
|
||||||
let bannedUserInfo1 = (await getSite(gamma)).my_user.unwrap().local_user_view
|
if (!betaCommunity) {
|
||||||
|
throw "Missing beta community";
|
||||||
|
}
|
||||||
|
let bannedUserInfo1 = (await getSite(gamma)).my_user?.local_user_view.person;
|
||||||
|
if (!bannedUserInfo1) {
|
||||||
|
throw "Missing banned user 1";
|
||||||
|
}
|
||||||
|
let bannedUserInfo2 = (await resolvePerson(beta, bannedUserInfo1.actor_id))
|
||||||
.person;
|
.person;
|
||||||
let bannedUserInfo2 = (
|
if (!bannedUserInfo2) {
|
||||||
await resolvePerson(beta, bannedUserInfo1.actor_id)
|
throw "Missing banned user 2";
|
||||||
).person.unwrap();
|
}
|
||||||
let banRes = await banPersonFromCommunity(
|
let banRes = await banPersonFromCommunity(
|
||||||
beta,
|
beta,
|
||||||
bannedUserInfo2.person.id,
|
bannedUserInfo2.person.id,
|
||||||
|
@ -220,8 +225,8 @@ test("Admin actions in remote community are not federated to origin", async () =
|
||||||
expect(banRes.banned).toBe(true);
|
expect(banRes.banned).toBe(true);
|
||||||
|
|
||||||
// ban doesnt federate to community's origin instance alpha
|
// ban doesnt federate to community's origin instance alpha
|
||||||
let alphaPost = (await resolvePost(alpha, gammaPost.post)).post.unwrap();
|
let alphaPost = (await resolvePost(alpha, gammaPost.post)).post;
|
||||||
expect(alphaPost.creator_banned_from_community).toBe(false);
|
expect(alphaPost?.creator_banned_from_community).toBe(false);
|
||||||
|
|
||||||
// and neither to gamma
|
// and neither to gamma
|
||||||
let gammaPost2 = await getPost(gamma, gammaPost.post.id);
|
let gammaPost2 = await getPost(gamma, gammaPost.post.id);
|
||||||
|
|
|
@ -19,22 +19,29 @@ afterAll(async () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("Follow federated community", async () => {
|
test("Follow federated community", async () => {
|
||||||
let betaCommunity = (await resolveBetaCommunity(alpha)).community.unwrap();
|
let betaCommunity = (await resolveBetaCommunity(alpha)).community;
|
||||||
|
if (!betaCommunity) {
|
||||||
|
throw "Missing beta community";
|
||||||
|
}
|
||||||
await followCommunity(alpha, true, betaCommunity.community.id);
|
await followCommunity(alpha, true, betaCommunity.community.id);
|
||||||
betaCommunity = (await resolveBetaCommunity(alpha)).community.unwrap();
|
betaCommunity = (await resolveBetaCommunity(alpha)).community;
|
||||||
|
|
||||||
// Make sure the follow response went through
|
// Make sure the follow response went through
|
||||||
expect(betaCommunity.community.local).toBe(false);
|
expect(betaCommunity?.community.local).toBe(false);
|
||||||
expect(betaCommunity.community.name).toBe("main");
|
expect(betaCommunity?.community.name).toBe("main");
|
||||||
expect(betaCommunity.subscribed).toBe(SubscribedType.Subscribed);
|
expect(betaCommunity?.subscribed).toBe(SubscribedType.Subscribed);
|
||||||
|
|
||||||
// Check it from local
|
// Check it from local
|
||||||
let site = await getSite(alpha);
|
let site = await getSite(alpha);
|
||||||
let remoteCommunityId = site.my_user
|
let remoteCommunityId = site.my_user?.follows.find(
|
||||||
.unwrap()
|
c => c.community.local == false
|
||||||
.follows.find(c => c.community.local == false).community.id;
|
)?.community.id;
|
||||||
expect(remoteCommunityId).toBeDefined();
|
expect(remoteCommunityId).toBeDefined();
|
||||||
expect(site.my_user.unwrap().follows.length).toBe(2);
|
expect(site.my_user?.follows.length).toBe(2);
|
||||||
|
|
||||||
|
if (!remoteCommunityId) {
|
||||||
|
throw "Missing remote community id";
|
||||||
|
}
|
||||||
|
|
||||||
// Test an unfollow
|
// Test an unfollow
|
||||||
let unfollow = await followCommunity(alpha, false, remoteCommunityId);
|
let unfollow = await followCommunity(alpha, false, remoteCommunityId);
|
||||||
|
@ -42,5 +49,5 @@ test("Follow federated community", async () => {
|
||||||
|
|
||||||
// Make sure you are unsubbed locally
|
// Make sure you are unsubbed locally
|
||||||
let siteUnfollowCheck = await getSite(alpha);
|
let siteUnfollowCheck = await getSite(alpha);
|
||||||
expect(siteUnfollowCheck.my_user.unwrap().follows.length).toBe(1);
|
expect(siteUnfollowCheck.my_user?.follows.length).toBe(1);
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
jest.setTimeout(120000);
|
jest.setTimeout(120000);
|
||||||
import { None } from "@sniptt/monads";
|
|
||||||
import { PostView, CommunityView } from "lemmy-js-client";
|
import { PostView, CommunityView } from "lemmy-js-client";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
@ -37,11 +36,11 @@ import {
|
||||||
resolveCommunity,
|
resolveCommunity,
|
||||||
} from "./shared";
|
} from "./shared";
|
||||||
|
|
||||||
let betaCommunity: CommunityView;
|
let betaCommunity: CommunityView | undefined;
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
await setupLogins();
|
await setupLogins();
|
||||||
betaCommunity = (await resolveBetaCommunity(alpha)).community.unwrap();
|
betaCommunity = (await resolveBetaCommunity(alpha)).community;
|
||||||
expect(betaCommunity).toBeDefined();
|
expect(betaCommunity).toBeDefined();
|
||||||
await unfollows();
|
await unfollows();
|
||||||
});
|
});
|
||||||
|
@ -50,33 +49,28 @@ afterAll(async () => {
|
||||||
await unfollows();
|
await unfollows();
|
||||||
});
|
});
|
||||||
|
|
||||||
function assertPostFederation(postOne: PostView, postTwo: PostView) {
|
function assertPostFederation(postOne?: PostView, postTwo?: PostView) {
|
||||||
expect(postOne.post.ap_id).toBe(postTwo.post.ap_id);
|
expect(postOne?.post.ap_id).toBe(postTwo?.post.ap_id);
|
||||||
expect(postOne.post.name).toBe(postTwo.post.name);
|
expect(postOne?.post.name).toBe(postTwo?.post.name);
|
||||||
expect(postOne.post.body.unwrapOr("none")).toBe(
|
expect(postOne?.post.body).toBe(postTwo?.post.body);
|
||||||
postTwo.post.body.unwrapOr("none")
|
// TODO url clears arent working
|
||||||
);
|
// expect(postOne?.post.url).toBe(postTwo?.post.url);
|
||||||
expect(postOne.post.url.unwrapOr("https://google.com/")).toBe(
|
expect(postOne?.post.nsfw).toBe(postTwo?.post.nsfw);
|
||||||
postTwo.post.url.unwrapOr("https://google.com/")
|
expect(postOne?.post.embed_title).toBe(postTwo?.post.embed_title);
|
||||||
);
|
expect(postOne?.post.embed_description).toBe(postTwo?.post.embed_description);
|
||||||
expect(postOne.post.nsfw).toBe(postTwo.post.nsfw);
|
expect(postOne?.post.embed_video_url).toBe(postTwo?.post.embed_video_url);
|
||||||
expect(postOne.post.embed_title.unwrapOr("none")).toBe(
|
expect(postOne?.post.published).toBe(postTwo?.post.published);
|
||||||
postTwo.post.embed_title.unwrapOr("none")
|
expect(postOne?.community.actor_id).toBe(postTwo?.community.actor_id);
|
||||||
);
|
expect(postOne?.post.locked).toBe(postTwo?.post.locked);
|
||||||
expect(postOne.post.embed_description.unwrapOr("none")).toBe(
|
expect(postOne?.post.removed).toBe(postTwo?.post.removed);
|
||||||
postTwo.post.embed_description.unwrapOr("none")
|
expect(postOne?.post.deleted).toBe(postTwo?.post.deleted);
|
||||||
);
|
|
||||||
expect(postOne.post.embed_video_url.unwrapOr("none")).toBe(
|
|
||||||
postTwo.post.embed_video_url.unwrapOr("none")
|
|
||||||
);
|
|
||||||
expect(postOne.post.published).toBe(postTwo.post.published);
|
|
||||||
expect(postOne.community.actor_id).toBe(postTwo.community.actor_id);
|
|
||||||
expect(postOne.post.locked).toBe(postTwo.post.locked);
|
|
||||||
expect(postOne.post.removed).toBe(postTwo.post.removed);
|
|
||||||
expect(postOne.post.deleted).toBe(postTwo.post.deleted);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
test("Create a post", async () => {
|
test("Create a post", async () => {
|
||||||
|
if (!betaCommunity) {
|
||||||
|
throw "Missing beta community";
|
||||||
|
}
|
||||||
|
|
||||||
let postRes = await createPost(alpha, betaCommunity.community.id);
|
let postRes = await createPost(alpha, betaCommunity.community.id);
|
||||||
expect(postRes.post_view.post).toBeDefined();
|
expect(postRes.post_view.post).toBeDefined();
|
||||||
expect(postRes.post_view.community.local).toBe(false);
|
expect(postRes.post_view.community.local).toBe(false);
|
||||||
|
@ -84,23 +78,21 @@ test("Create a post", async () => {
|
||||||
expect(postRes.post_view.counts.score).toBe(1);
|
expect(postRes.post_view.counts.score).toBe(1);
|
||||||
|
|
||||||
// Make sure that post is liked on beta
|
// Make sure that post is liked on beta
|
||||||
let betaPost = (
|
let betaPost = (await resolvePost(beta, postRes.post_view.post)).post;
|
||||||
await resolvePost(beta, postRes.post_view.post)
|
|
||||||
).post.unwrap();
|
|
||||||
|
|
||||||
expect(betaPost).toBeDefined();
|
expect(betaPost).toBeDefined();
|
||||||
expect(betaPost.community.local).toBe(true);
|
expect(betaPost?.community.local).toBe(true);
|
||||||
expect(betaPost.creator.local).toBe(false);
|
expect(betaPost?.creator.local).toBe(false);
|
||||||
expect(betaPost.counts.score).toBe(1);
|
expect(betaPost?.counts.score).toBe(1);
|
||||||
assertPostFederation(betaPost, postRes.post_view);
|
assertPostFederation(betaPost, postRes.post_view);
|
||||||
|
|
||||||
// Delta only follows beta, so it should not see an alpha ap_id
|
// Delta only follows beta, so it should not see an alpha ap_id
|
||||||
let deltaPost = (await resolvePost(delta, postRes.post_view.post)).post;
|
let deltaPost = (await resolvePost(delta, postRes.post_view.post)).post;
|
||||||
expect(deltaPost.isNone()).toBe(true);
|
expect(deltaPost).toBeUndefined();
|
||||||
|
|
||||||
// Epsilon has alpha blocked, it should not see the alpha post
|
// Epsilon has alpha blocked, it should not see the alpha post
|
||||||
let epsilonPost = (await resolvePost(epsilon, postRes.post_view.post)).post;
|
let epsilonPost = (await resolvePost(epsilon, postRes.post_view.post)).post;
|
||||||
expect(epsilonPost.isNone()).toBe(true);
|
expect(epsilonPost).toBeUndefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
test("Create a post in a non-existent community", async () => {
|
test("Create a post in a non-existent community", async () => {
|
||||||
|
@ -109,6 +101,9 @@ test("Create a post in a non-existent community", async () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("Unlike a post", async () => {
|
test("Unlike a post", async () => {
|
||||||
|
if (!betaCommunity) {
|
||||||
|
throw "Missing beta community";
|
||||||
|
}
|
||||||
let postRes = await createPost(alpha, betaCommunity.community.id);
|
let postRes = await createPost(alpha, betaCommunity.community.id);
|
||||||
let unlike = await likePost(alpha, 0, postRes.post_view.post);
|
let unlike = await likePost(alpha, 0, postRes.post_view.post);
|
||||||
expect(unlike.post_view.counts.score).toBe(0);
|
expect(unlike.post_view.counts.score).toBe(0);
|
||||||
|
@ -118,17 +113,18 @@ test("Unlike a post", async () => {
|
||||||
expect(unlike2.post_view.counts.score).toBe(0);
|
expect(unlike2.post_view.counts.score).toBe(0);
|
||||||
|
|
||||||
// Make sure that post is unliked on beta
|
// Make sure that post is unliked on beta
|
||||||
let betaPost = (
|
let betaPost = (await resolvePost(beta, postRes.post_view.post)).post;
|
||||||
await resolvePost(beta, postRes.post_view.post)
|
|
||||||
).post.unwrap();
|
|
||||||
expect(betaPost).toBeDefined();
|
expect(betaPost).toBeDefined();
|
||||||
expect(betaPost.community.local).toBe(true);
|
expect(betaPost?.community.local).toBe(true);
|
||||||
expect(betaPost.creator.local).toBe(false);
|
expect(betaPost?.creator.local).toBe(false);
|
||||||
expect(betaPost.counts.score).toBe(0);
|
expect(betaPost?.counts.score).toBe(0);
|
||||||
assertPostFederation(betaPost, postRes.post_view);
|
assertPostFederation(betaPost, postRes.post_view);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("Update a post", async () => {
|
test("Update a post", async () => {
|
||||||
|
if (!betaCommunity) {
|
||||||
|
throw "Missing beta community";
|
||||||
|
}
|
||||||
let postRes = await createPost(alpha, betaCommunity.community.id);
|
let postRes = await createPost(alpha, betaCommunity.community.id);
|
||||||
|
|
||||||
let updatedName = "A jest test federated post, updated";
|
let updatedName = "A jest test federated post, updated";
|
||||||
|
@ -138,9 +134,10 @@ test("Update a post", async () => {
|
||||||
expect(updatedPost.post_view.creator.local).toBe(true);
|
expect(updatedPost.post_view.creator.local).toBe(true);
|
||||||
|
|
||||||
// Make sure that post is updated on beta
|
// Make sure that post is updated on beta
|
||||||
let betaPost = (
|
let betaPost = (await resolvePost(beta, postRes.post_view.post)).post;
|
||||||
await resolvePost(beta, postRes.post_view.post)
|
if (!betaPost) {
|
||||||
).post.unwrap();
|
throw "Missing beta post";
|
||||||
|
}
|
||||||
expect(betaPost.community.local).toBe(true);
|
expect(betaPost.community.local).toBe(true);
|
||||||
expect(betaPost.creator.local).toBe(false);
|
expect(betaPost.creator.local).toBe(false);
|
||||||
expect(betaPost.post.name).toBe(updatedName);
|
expect(betaPost.post.name).toBe(updatedName);
|
||||||
|
@ -152,54 +149,57 @@ test("Update a post", async () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("Sticky a post", async () => {
|
test("Sticky a post", async () => {
|
||||||
|
if (!betaCommunity) {
|
||||||
|
throw "Missing beta community";
|
||||||
|
}
|
||||||
let postRes = await createPost(alpha, betaCommunity.community.id);
|
let postRes = await createPost(alpha, betaCommunity.community.id);
|
||||||
|
|
||||||
let betaPost1 = (
|
let betaPost1 = (await resolvePost(beta, postRes.post_view.post)).post;
|
||||||
await resolvePost(beta, postRes.post_view.post)
|
if (!betaPost1) {
|
||||||
).post.unwrap();
|
throw "Missing beta post1";
|
||||||
|
}
|
||||||
let stickiedPostRes = await featurePost(beta, true, betaPost1.post);
|
let stickiedPostRes = await featurePost(beta, true, betaPost1.post);
|
||||||
expect(stickiedPostRes.post_view.post.featured_community).toBe(true);
|
expect(stickiedPostRes.post_view.post.featured_community).toBe(true);
|
||||||
|
|
||||||
// Make sure that post is stickied on beta
|
// Make sure that post is stickied on beta
|
||||||
let betaPost = (
|
let betaPost = (await resolvePost(beta, postRes.post_view.post)).post;
|
||||||
await resolvePost(beta, postRes.post_view.post)
|
expect(betaPost?.community.local).toBe(true);
|
||||||
).post.unwrap();
|
expect(betaPost?.creator.local).toBe(false);
|
||||||
expect(betaPost.community.local).toBe(true);
|
expect(betaPost?.post.featured_community).toBe(true);
|
||||||
expect(betaPost.creator.local).toBe(false);
|
|
||||||
expect(betaPost.post.featured_community).toBe(true);
|
|
||||||
|
|
||||||
// Unsticky a post
|
// Unsticky a post
|
||||||
let unstickiedPost = await featurePost(beta, false, betaPost1.post);
|
let unstickiedPost = await featurePost(beta, false, betaPost1.post);
|
||||||
expect(unstickiedPost.post_view.post.featured_community).toBe(false);
|
expect(unstickiedPost.post_view.post.featured_community).toBe(false);
|
||||||
|
|
||||||
// Make sure that post is unstickied on beta
|
// Make sure that post is unstickied on beta
|
||||||
let betaPost2 = (
|
let betaPost2 = (await resolvePost(beta, postRes.post_view.post)).post;
|
||||||
await resolvePost(beta, postRes.post_view.post)
|
expect(betaPost2?.community.local).toBe(true);
|
||||||
).post.unwrap();
|
expect(betaPost2?.creator.local).toBe(false);
|
||||||
expect(betaPost2.community.local).toBe(true);
|
expect(betaPost2?.post.featured_community).toBe(false);
|
||||||
expect(betaPost2.creator.local).toBe(false);
|
|
||||||
expect(betaPost2.post.featured_community).toBe(false);
|
|
||||||
|
|
||||||
// Make sure that gamma cannot sticky the post on beta
|
// Make sure that gamma cannot sticky the post on beta
|
||||||
let gammaPost = (
|
let gammaPost = (await resolvePost(gamma, postRes.post_view.post)).post;
|
||||||
await resolvePost(gamma, postRes.post_view.post)
|
if (!gammaPost) {
|
||||||
).post.unwrap();
|
throw "Missing gamma post";
|
||||||
|
}
|
||||||
let gammaTrySticky = await featurePost(gamma, true, gammaPost.post);
|
let gammaTrySticky = await featurePost(gamma, true, gammaPost.post);
|
||||||
let betaPost3 = (
|
let betaPost3 = (await resolvePost(beta, postRes.post_view.post)).post;
|
||||||
await resolvePost(beta, postRes.post_view.post)
|
|
||||||
).post.unwrap();
|
|
||||||
expect(gammaTrySticky.post_view.post.featured_community).toBe(true);
|
expect(gammaTrySticky.post_view.post.featured_community).toBe(true);
|
||||||
expect(betaPost3.post.featured_community).toBe(false);
|
expect(betaPost3?.post.featured_community).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("Lock a post", async () => {
|
test("Lock a post", async () => {
|
||||||
|
if (!betaCommunity) {
|
||||||
|
throw "Missing beta community";
|
||||||
|
}
|
||||||
await followCommunity(alpha, true, betaCommunity.community.id);
|
await followCommunity(alpha, true, betaCommunity.community.id);
|
||||||
let postRes = await createPost(alpha, betaCommunity.community.id);
|
let postRes = await createPost(alpha, betaCommunity.community.id);
|
||||||
|
|
||||||
// Lock the post
|
// Lock the post
|
||||||
let betaPost1 = (
|
let betaPost1 = (await resolvePost(beta, postRes.post_view.post)).post;
|
||||||
await resolvePost(beta, postRes.post_view.post)
|
if (!betaPost1) {
|
||||||
).post.unwrap();
|
throw "Missing beta post1";
|
||||||
|
}
|
||||||
let lockedPostRes = await lockPost(beta, true, betaPost1.post);
|
let lockedPostRes = await lockPost(beta, true, betaPost1.post);
|
||||||
expect(lockedPostRes.post_view.post.locked).toBe(true);
|
expect(lockedPostRes.post_view.post.locked).toBe(true);
|
||||||
|
|
||||||
|
@ -209,7 +209,7 @@ test("Lock a post", async () => {
|
||||||
expect(alphaPost1.post.locked).toBe(true);
|
expect(alphaPost1.post.locked).toBe(true);
|
||||||
|
|
||||||
// Try to make a new comment there, on alpha
|
// Try to make a new comment there, on alpha
|
||||||
let comment: any = await createComment(alpha, alphaPost1.post.id, None);
|
let comment: any = await createComment(alpha, alphaPost1.post.id);
|
||||||
expect(comment["error"]).toBe("locked");
|
expect(comment["error"]).toBe("locked");
|
||||||
|
|
||||||
// Unlock a post
|
// Unlock a post
|
||||||
|
@ -224,11 +224,15 @@ test("Lock a post", async () => {
|
||||||
expect(alphaPost2.post.locked).toBe(false);
|
expect(alphaPost2.post.locked).toBe(false);
|
||||||
|
|
||||||
// Try to create a new comment, on alpha
|
// Try to create a new comment, on alpha
|
||||||
let commentAlpha = await createComment(alpha, alphaPost1.post.id, None);
|
let commentAlpha = await createComment(alpha, alphaPost1.post.id);
|
||||||
expect(commentAlpha).toBeDefined();
|
expect(commentAlpha).toBeDefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
test("Delete a post", async () => {
|
test("Delete a post", async () => {
|
||||||
|
if (!betaCommunity) {
|
||||||
|
throw "Missing beta community";
|
||||||
|
}
|
||||||
|
|
||||||
let postRes = await createPost(alpha, betaCommunity.community.id);
|
let postRes = await createPost(alpha, betaCommunity.community.id);
|
||||||
expect(postRes.post_view.post).toBeDefined();
|
expect(postRes.post_view.post).toBeDefined();
|
||||||
|
|
||||||
|
@ -239,16 +243,17 @@ test("Delete a post", async () => {
|
||||||
// Make sure lemmy beta sees post is deleted
|
// Make sure lemmy beta sees post is deleted
|
||||||
let betaPost = (await resolvePost(beta, postRes.post_view.post)).post;
|
let betaPost = (await resolvePost(beta, postRes.post_view.post)).post;
|
||||||
// This will be undefined because of the tombstone
|
// This will be undefined because of the tombstone
|
||||||
expect(betaPost.isNone()).toBe(true);
|
expect(betaPost).toBeUndefined();
|
||||||
|
|
||||||
// Undelete
|
// Undelete
|
||||||
let undeletedPost = await deletePost(alpha, false, postRes.post_view.post);
|
let undeletedPost = await deletePost(alpha, false, postRes.post_view.post);
|
||||||
expect(undeletedPost.post_view.post.deleted).toBe(false);
|
expect(undeletedPost.post_view.post.deleted).toBe(false);
|
||||||
|
|
||||||
// Make sure lemmy beta sees post is undeleted
|
// Make sure lemmy beta sees post is undeleted
|
||||||
let betaPost2 = (
|
let betaPost2 = (await resolvePost(beta, postRes.post_view.post)).post;
|
||||||
await resolvePost(beta, postRes.post_view.post)
|
if (!betaPost2) {
|
||||||
).post.unwrap();
|
throw "Missing beta post 2";
|
||||||
|
}
|
||||||
expect(betaPost2.post.deleted).toBe(false);
|
expect(betaPost2.post.deleted).toBe(false);
|
||||||
assertPostFederation(betaPost2, undeletedPost.post_view);
|
assertPostFederation(betaPost2, undeletedPost.post_view);
|
||||||
|
|
||||||
|
@ -258,26 +263,31 @@ test("Delete a post", async () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("Remove a post from admin and community on different instance", async () => {
|
test("Remove a post from admin and community on different instance", async () => {
|
||||||
let gammaCommunity = await resolveCommunity(
|
if (!betaCommunity) {
|
||||||
gamma,
|
throw "Missing beta community";
|
||||||
betaCommunity.community.actor_id
|
}
|
||||||
);
|
|
||||||
let postRes = await createPost(
|
|
||||||
gamma,
|
|
||||||
gammaCommunity.community.unwrap().community.id
|
|
||||||
);
|
|
||||||
|
|
||||||
let alphaPost = (
|
let gammaCommunity = (
|
||||||
await resolvePost(alpha, postRes.post_view.post)
|
await resolveCommunity(gamma, betaCommunity.community.actor_id)
|
||||||
).post.unwrap();
|
).community?.community;
|
||||||
|
if (!gammaCommunity) {
|
||||||
|
throw "Missing gamma community";
|
||||||
|
}
|
||||||
|
let postRes = await createPost(gamma, gammaCommunity.id);
|
||||||
|
|
||||||
|
let alphaPost = (await resolvePost(alpha, postRes.post_view.post)).post;
|
||||||
|
if (!alphaPost) {
|
||||||
|
throw "Missing alpha post";
|
||||||
|
}
|
||||||
let removedPost = await removePost(alpha, true, alphaPost.post);
|
let removedPost = await removePost(alpha, true, alphaPost.post);
|
||||||
expect(removedPost.post_view.post.removed).toBe(true);
|
expect(removedPost.post_view.post.removed).toBe(true);
|
||||||
expect(removedPost.post_view.post.name).toBe(postRes.post_view.post.name);
|
expect(removedPost.post_view.post.name).toBe(postRes.post_view.post.name);
|
||||||
|
|
||||||
// Make sure lemmy beta sees post is NOT removed
|
// Make sure lemmy beta sees post is NOT removed
|
||||||
let betaPost = (
|
let betaPost = (await resolvePost(beta, postRes.post_view.post)).post;
|
||||||
await resolvePost(beta, postRes.post_view.post)
|
if (!betaPost) {
|
||||||
).post.unwrap();
|
throw "Missing beta post";
|
||||||
|
}
|
||||||
expect(betaPost.post.removed).toBe(false);
|
expect(betaPost.post.removed).toBe(false);
|
||||||
|
|
||||||
// Undelete
|
// Undelete
|
||||||
|
@ -285,14 +295,15 @@ test("Remove a post from admin and community on different instance", async () =>
|
||||||
expect(undeletedPost.post_view.post.removed).toBe(false);
|
expect(undeletedPost.post_view.post.removed).toBe(false);
|
||||||
|
|
||||||
// Make sure lemmy beta sees post is undeleted
|
// Make sure lemmy beta sees post is undeleted
|
||||||
let betaPost2 = (
|
let betaPost2 = (await resolvePost(beta, postRes.post_view.post)).post;
|
||||||
await resolvePost(beta, postRes.post_view.post)
|
expect(betaPost2?.post.removed).toBe(false);
|
||||||
).post.unwrap();
|
|
||||||
expect(betaPost2.post.removed).toBe(false);
|
|
||||||
assertPostFederation(betaPost2, undeletedPost.post_view);
|
assertPostFederation(betaPost2, undeletedPost.post_view);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("Remove a post from admin and community on same instance", async () => {
|
test("Remove a post from admin and community on same instance", async () => {
|
||||||
|
if (!betaCommunity) {
|
||||||
|
throw "Missing beta community";
|
||||||
|
}
|
||||||
await followBeta(alpha);
|
await followBeta(alpha);
|
||||||
let postRes = await createPost(alpha, betaCommunity.community.id);
|
let postRes = await createPost(alpha, betaCommunity.community.id);
|
||||||
expect(postRes.post_view.post).toBeDefined();
|
expect(postRes.post_view.post).toBeDefined();
|
||||||
|
@ -323,30 +334,38 @@ test("Remove a post from admin and community on same instance", async () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("Search for a post", async () => {
|
test("Search for a post", async () => {
|
||||||
|
if (!betaCommunity) {
|
||||||
|
throw "Missing beta community";
|
||||||
|
}
|
||||||
await unfollowRemotes(alpha);
|
await unfollowRemotes(alpha);
|
||||||
let postRes = await createPost(alpha, betaCommunity.community.id);
|
let postRes = await createPost(alpha, betaCommunity.community.id);
|
||||||
expect(postRes.post_view.post).toBeDefined();
|
expect(postRes.post_view.post).toBeDefined();
|
||||||
|
|
||||||
let betaPost = (
|
let betaPost = (await resolvePost(beta, postRes.post_view.post)).post;
|
||||||
await resolvePost(beta, postRes.post_view.post)
|
expect(betaPost?.post.name).toBeDefined();
|
||||||
).post.unwrap();
|
|
||||||
expect(betaPost.post.name).toBeDefined();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("Enforce site ban for federated user", async () => {
|
test("Enforce site ban for federated user", async () => {
|
||||||
|
if (!betaCommunity) {
|
||||||
|
throw "Missing beta community";
|
||||||
|
}
|
||||||
// create a test user
|
// create a test user
|
||||||
let alphaUserJwt = await registerUser(alpha);
|
let alphaUserJwt = await registerUser(alpha);
|
||||||
expect(alphaUserJwt).toBeDefined();
|
expect(alphaUserJwt).toBeDefined();
|
||||||
let alpha_user: API = {
|
let alpha_user: API = {
|
||||||
client: alpha.client,
|
client: alpha.client,
|
||||||
auth: alphaUserJwt.jwt,
|
auth: alphaUserJwt.jwt ?? "",
|
||||||
};
|
};
|
||||||
let alphaUserActorId = (await getSite(alpha_user)).my_user.unwrap()
|
let alphaUserActorId = (await getSite(alpha_user)).my_user?.local_user_view
|
||||||
.local_user_view.person.actor_id;
|
.person.actor_id;
|
||||||
|
if (!alphaUserActorId) {
|
||||||
|
throw "Missing alpha user actor id";
|
||||||
|
}
|
||||||
expect(alphaUserActorId).toBeDefined();
|
expect(alphaUserActorId).toBeDefined();
|
||||||
let alphaPerson = (
|
let alphaPerson = (await resolvePerson(alpha_user, alphaUserActorId)).person;
|
||||||
await resolvePerson(alpha_user, alphaUserActorId)
|
if (!alphaPerson) {
|
||||||
).person.unwrap();
|
throw "Missing alpha person";
|
||||||
|
}
|
||||||
expect(alphaPerson).toBeDefined();
|
expect(alphaPerson).toBeDefined();
|
||||||
|
|
||||||
// alpha makes post in beta community, it federates to beta instance
|
// alpha makes post in beta community, it federates to beta instance
|
||||||
|
@ -365,7 +384,7 @@ test("Enforce site ban for federated user", async () => {
|
||||||
|
|
||||||
// alpha ban should be federated to beta
|
// alpha ban should be federated to beta
|
||||||
let alphaUserOnBeta1 = await resolvePerson(beta, alphaUserActorId);
|
let alphaUserOnBeta1 = await resolvePerson(beta, alphaUserActorId);
|
||||||
expect(alphaUserOnBeta1.person.unwrap().person.banned).toBe(true);
|
expect(alphaUserOnBeta1.person?.person.banned).toBe(true);
|
||||||
|
|
||||||
// existing alpha post should be removed on beta
|
// existing alpha post should be removed on beta
|
||||||
let searchBeta2 = await searchPostLocal(beta, postRes1.post_view.post);
|
let searchBeta2 = await searchPostLocal(beta, postRes1.post_view.post);
|
||||||
|
@ -386,12 +405,18 @@ test("Enforce site ban for federated user", async () => {
|
||||||
expect(searchBeta3.posts[0]).toBeDefined();
|
expect(searchBeta3.posts[0]).toBeDefined();
|
||||||
|
|
||||||
let alphaUserOnBeta2 = await resolvePerson(beta, alphaUserActorId);
|
let alphaUserOnBeta2 = await resolvePerson(beta, alphaUserActorId);
|
||||||
expect(alphaUserOnBeta2.person.unwrap().person.banned).toBe(false);
|
expect(alphaUserOnBeta2.person?.person.banned).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("Enforce community ban for federated user", async () => {
|
test("Enforce community ban for federated user", async () => {
|
||||||
|
if (!betaCommunity) {
|
||||||
|
throw "Missing beta community";
|
||||||
|
}
|
||||||
let alphaShortname = `@lemmy_alpha@lemmy-alpha:8541`;
|
let alphaShortname = `@lemmy_alpha@lemmy-alpha:8541`;
|
||||||
let alphaPerson = (await resolvePerson(beta, alphaShortname)).person.unwrap();
|
let alphaPerson = (await resolvePerson(beta, alphaShortname)).person;
|
||||||
|
if (!alphaPerson) {
|
||||||
|
throw "Missing alpha person";
|
||||||
|
}
|
||||||
expect(alphaPerson).toBeDefined();
|
expect(alphaPerson).toBeDefined();
|
||||||
|
|
||||||
// make a post in beta, it goes through
|
// make a post in beta, it goes through
|
||||||
|
@ -438,23 +463,29 @@ test("Enforce community ban for federated user", async () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("A and G subscribe to B (center) A posts, it gets announced to G", async () => {
|
test("A and G subscribe to B (center) A posts, it gets announced to G", async () => {
|
||||||
|
if (!betaCommunity) {
|
||||||
|
throw "Missing beta community";
|
||||||
|
}
|
||||||
let postRes = await createPost(alpha, betaCommunity.community.id);
|
let postRes = await createPost(alpha, betaCommunity.community.id);
|
||||||
expect(postRes.post_view.post).toBeDefined();
|
expect(postRes.post_view.post).toBeDefined();
|
||||||
|
|
||||||
let betaPost = (
|
let betaPost = (await resolvePost(gamma, postRes.post_view.post)).post;
|
||||||
await resolvePost(gamma, postRes.post_view.post)
|
expect(betaPost?.post.name).toBeDefined();
|
||||||
).post.unwrap();
|
|
||||||
expect(betaPost.post.name).toBeDefined();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("Report a post", async () => {
|
test("Report a post", async () => {
|
||||||
let betaCommunity = (await resolveBetaCommunity(beta)).community.unwrap();
|
// Note, this is a different one from the setup
|
||||||
|
let betaCommunity = (await resolveBetaCommunity(beta)).community;
|
||||||
|
if (!betaCommunity) {
|
||||||
|
throw "Missing beta community";
|
||||||
|
}
|
||||||
let postRes = await createPost(beta, betaCommunity.community.id);
|
let postRes = await createPost(beta, betaCommunity.community.id);
|
||||||
expect(postRes.post_view.post).toBeDefined();
|
expect(postRes.post_view.post).toBeDefined();
|
||||||
|
|
||||||
let alphaPost = (
|
let alphaPost = (await resolvePost(alpha, postRes.post_view.post)).post;
|
||||||
await resolvePost(alpha, postRes.post_view.post)
|
if (!alphaPost) {
|
||||||
).post.unwrap();
|
throw "Missing alpha post";
|
||||||
|
}
|
||||||
let alphaReport = (
|
let alphaReport = (
|
||||||
await reportPost(alpha, alphaPost.post.id, randomString(10))
|
await reportPost(alpha, alphaPost.post.id, randomString(10))
|
||||||
).post_report_view.post_report;
|
).post_report_view.post_report;
|
||||||
|
@ -463,11 +494,7 @@ test("Report a post", async () => {
|
||||||
expect(betaReport).toBeDefined();
|
expect(betaReport).toBeDefined();
|
||||||
expect(betaReport.resolved).toBe(false);
|
expect(betaReport.resolved).toBe(false);
|
||||||
expect(betaReport.original_post_name).toBe(alphaReport.original_post_name);
|
expect(betaReport.original_post_name).toBe(alphaReport.original_post_name);
|
||||||
expect(betaReport.original_post_url.unwrapOr("none")).toBe(
|
expect(betaReport.original_post_url).toBe(alphaReport.original_post_url);
|
||||||
alphaReport.original_post_url.unwrapOr("none")
|
expect(betaReport.original_post_body).toBe(alphaReport.original_post_body);
|
||||||
);
|
|
||||||
expect(betaReport.original_post_body.unwrapOr("none")).toBe(
|
|
||||||
alphaReport.original_post_body.unwrapOr("none")
|
|
||||||
);
|
|
||||||
expect(betaReport.reason).toBe(alphaReport.reason);
|
expect(betaReport.reason).toBe(alphaReport.reason);
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
import { None, Some, Option } from "@sniptt/monads";
|
|
||||||
import {
|
import {
|
||||||
Login,
|
Login,
|
||||||
LoginResponse,
|
LoginResponse,
|
||||||
|
@ -69,65 +68,65 @@ import {
|
||||||
|
|
||||||
export interface API {
|
export interface API {
|
||||||
client: LemmyHttp;
|
client: LemmyHttp;
|
||||||
auth: Option<string>;
|
auth: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export let alpha: API = {
|
export let alpha: API = {
|
||||||
client: new LemmyHttp("http://127.0.0.1:8541"),
|
client: new LemmyHttp("http://127.0.0.1:8541"),
|
||||||
auth: None,
|
auth: "",
|
||||||
};
|
};
|
||||||
|
|
||||||
export let beta: API = {
|
export let beta: API = {
|
||||||
client: new LemmyHttp("http://127.0.0.1:8551"),
|
client: new LemmyHttp("http://127.0.0.1:8551"),
|
||||||
auth: None,
|
auth: "",
|
||||||
};
|
};
|
||||||
|
|
||||||
export let gamma: API = {
|
export let gamma: API = {
|
||||||
client: new LemmyHttp("http://127.0.0.1:8561"),
|
client: new LemmyHttp("http://127.0.0.1:8561"),
|
||||||
auth: None,
|
auth: "",
|
||||||
};
|
};
|
||||||
|
|
||||||
export let delta: API = {
|
export let delta: API = {
|
||||||
client: new LemmyHttp("http://127.0.0.1:8571"),
|
client: new LemmyHttp("http://127.0.0.1:8571"),
|
||||||
auth: None,
|
auth: "",
|
||||||
};
|
};
|
||||||
|
|
||||||
export let epsilon: API = {
|
export let epsilon: API = {
|
||||||
client: new LemmyHttp("http://127.0.0.1:8581"),
|
client: new LemmyHttp("http://127.0.0.1:8581"),
|
||||||
auth: None,
|
auth: "",
|
||||||
};
|
};
|
||||||
|
|
||||||
const password = "lemmylemmy";
|
const password = "lemmylemmy";
|
||||||
|
|
||||||
export async function setupLogins() {
|
export async function setupLogins() {
|
||||||
let formAlpha = new Login({
|
let formAlpha: Login = {
|
||||||
username_or_email: "lemmy_alpha",
|
username_or_email: "lemmy_alpha",
|
||||||
password,
|
password,
|
||||||
});
|
};
|
||||||
let resAlpha = alpha.client.login(formAlpha);
|
let resAlpha = alpha.client.login(formAlpha);
|
||||||
|
|
||||||
let formBeta = new Login({
|
let formBeta: Login = {
|
||||||
username_or_email: "lemmy_beta",
|
username_or_email: "lemmy_beta",
|
||||||
password,
|
password,
|
||||||
});
|
};
|
||||||
let resBeta = beta.client.login(formBeta);
|
let resBeta = beta.client.login(formBeta);
|
||||||
|
|
||||||
let formGamma = new Login({
|
let formGamma: Login = {
|
||||||
username_or_email: "lemmy_gamma",
|
username_or_email: "lemmy_gamma",
|
||||||
password,
|
password,
|
||||||
});
|
};
|
||||||
let resGamma = gamma.client.login(formGamma);
|
let resGamma = gamma.client.login(formGamma);
|
||||||
|
|
||||||
let formDelta = new Login({
|
let formDelta: Login = {
|
||||||
username_or_email: "lemmy_delta",
|
username_or_email: "lemmy_delta",
|
||||||
password,
|
password,
|
||||||
});
|
};
|
||||||
let resDelta = delta.client.login(formDelta);
|
let resDelta = delta.client.login(formDelta);
|
||||||
|
|
||||||
let formEpsilon = new Login({
|
let formEpsilon: Login = {
|
||||||
username_or_email: "lemmy_epsilon",
|
username_or_email: "lemmy_epsilon",
|
||||||
password,
|
password,
|
||||||
});
|
};
|
||||||
let resEpsilon = epsilon.client.login(formEpsilon);
|
let resEpsilon = epsilon.client.login(formEpsilon);
|
||||||
|
|
||||||
let res = await Promise.all([
|
let res = await Promise.all([
|
||||||
|
@ -138,93 +137,60 @@ export async function setupLogins() {
|
||||||
resEpsilon,
|
resEpsilon,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
alpha.auth = res[0].jwt;
|
alpha.auth = res[0].jwt ?? "";
|
||||||
beta.auth = res[1].jwt;
|
beta.auth = res[1].jwt ?? "";
|
||||||
gamma.auth = res[2].jwt;
|
gamma.auth = res[2].jwt ?? "";
|
||||||
delta.auth = res[3].jwt;
|
delta.auth = res[3].jwt ?? "";
|
||||||
epsilon.auth = res[4].jwt;
|
epsilon.auth = res[4].jwt ?? "";
|
||||||
|
|
||||||
// Registration applications are now enabled by default, need to disable them
|
// Registration applications are now enabled by default, need to disable them
|
||||||
let editSiteForm = new EditSite({
|
let editSiteForm: EditSite = {
|
||||||
require_application: Some(false),
|
require_application: false,
|
||||||
federation_debug: Some(true),
|
federation_debug: true,
|
||||||
name: None,
|
rate_limit_message: 999,
|
||||||
sidebar: None,
|
rate_limit_post: 999,
|
||||||
description: None,
|
rate_limit_register: 999,
|
||||||
icon: None,
|
rate_limit_image: 999,
|
||||||
banner: None,
|
rate_limit_comment: 999,
|
||||||
enable_downvotes: None,
|
rate_limit_search: 999,
|
||||||
open_registration: None,
|
|
||||||
enable_nsfw: None,
|
|
||||||
community_creation_admin_only: None,
|
|
||||||
require_email_verification: None,
|
|
||||||
application_question: None,
|
|
||||||
private_instance: None,
|
|
||||||
default_theme: None,
|
|
||||||
default_post_listing_type: None,
|
|
||||||
legal_information: None,
|
|
||||||
application_email_admins: None,
|
|
||||||
hide_modlog_mod_names: None,
|
|
||||||
discussion_languages: None,
|
|
||||||
slur_filter_regex: None,
|
|
||||||
actor_name_max_length: None,
|
|
||||||
rate_limit_message: Some(999),
|
|
||||||
rate_limit_message_per_second: None,
|
|
||||||
rate_limit_post: Some(999),
|
|
||||||
rate_limit_post_per_second: None,
|
|
||||||
rate_limit_register: Some(999),
|
|
||||||
rate_limit_register_per_second: None,
|
|
||||||
rate_limit_image: Some(999),
|
|
||||||
rate_limit_image_per_second: None,
|
|
||||||
rate_limit_comment: Some(999),
|
|
||||||
rate_limit_comment_per_second: None,
|
|
||||||
rate_limit_search: Some(999),
|
|
||||||
rate_limit_search_per_second: None,
|
|
||||||
federation_enabled: None,
|
|
||||||
federation_worker_count: None,
|
|
||||||
captcha_enabled: None,
|
|
||||||
captcha_difficulty: None,
|
|
||||||
allowed_instances: None,
|
|
||||||
blocked_instances: None,
|
|
||||||
auth: "",
|
auth: "",
|
||||||
taglines: None,
|
};
|
||||||
});
|
|
||||||
|
|
||||||
// Set the blocks and auths for each
|
// Set the blocks and auths for each
|
||||||
editSiteForm.auth = alpha.auth.unwrap();
|
editSiteForm.auth = alpha.auth;
|
||||||
editSiteForm.allowed_instances = Some([
|
editSiteForm.allowed_instances = [
|
||||||
"lemmy-beta",
|
"lemmy-beta",
|
||||||
"lemmy-gamma",
|
"lemmy-gamma",
|
||||||
"lemmy-delta",
|
"lemmy-delta",
|
||||||
"lemmy-epsilon",
|
"lemmy-epsilon",
|
||||||
]);
|
];
|
||||||
await alpha.client.editSite(editSiteForm);
|
await alpha.client.editSite(editSiteForm);
|
||||||
|
|
||||||
editSiteForm.auth = beta.auth.unwrap();
|
editSiteForm.auth = beta.auth;
|
||||||
editSiteForm.allowed_instances = Some([
|
editSiteForm.allowed_instances = [
|
||||||
"lemmy-alpha",
|
"lemmy-alpha",
|
||||||
"lemmy-gamma",
|
"lemmy-gamma",
|
||||||
"lemmy-delta",
|
"lemmy-delta",
|
||||||
"lemmy-epsilon",
|
"lemmy-epsilon",
|
||||||
]);
|
];
|
||||||
await beta.client.editSite(editSiteForm);
|
await beta.client.editSite(editSiteForm);
|
||||||
|
|
||||||
editSiteForm.auth = gamma.auth.unwrap();
|
editSiteForm.auth = gamma.auth;
|
||||||
editSiteForm.allowed_instances = Some([
|
editSiteForm.allowed_instances = [
|
||||||
"lemmy-alpha",
|
"lemmy-alpha",
|
||||||
"lemmy-beta",
|
"lemmy-beta",
|
||||||
"lemmy-delta",
|
"lemmy-delta",
|
||||||
"lemmy-epsilon",
|
"lemmy-epsilon",
|
||||||
]);
|
];
|
||||||
await gamma.client.editSite(editSiteForm);
|
await gamma.client.editSite(editSiteForm);
|
||||||
|
|
||||||
editSiteForm.allowed_instances = Some(["lemmy-beta"]);
|
editSiteForm.allowed_instances = ["lemmy-beta"];
|
||||||
editSiteForm.auth = delta.auth.unwrap();
|
editSiteForm.auth = delta.auth;
|
||||||
await delta.client.editSite(editSiteForm);
|
await delta.client.editSite(editSiteForm);
|
||||||
|
|
||||||
editSiteForm.auth = epsilon.auth.unwrap();
|
editSiteForm.auth = epsilon.auth;
|
||||||
editSiteForm.allowed_instances = Some([]);
|
editSiteForm.allowed_instances = [];
|
||||||
editSiteForm.blocked_instances = Some(["lemmy-alpha"]);
|
editSiteForm.blocked_instances = ["lemmy-alpha"];
|
||||||
await epsilon.client.editSite(editSiteForm);
|
await epsilon.client.editSite(editSiteForm);
|
||||||
|
|
||||||
// Create the main alpha/beta communities
|
// Create the main alpha/beta communities
|
||||||
|
@ -237,32 +203,25 @@ export async function createPost(
|
||||||
community_id: number
|
community_id: number
|
||||||
): Promise<PostResponse> {
|
): Promise<PostResponse> {
|
||||||
let name = randomString(5);
|
let name = randomString(5);
|
||||||
let body = Some(randomString(10));
|
let body = randomString(10);
|
||||||
let url = Some("https://google.com/");
|
let url = "https://google.com/";
|
||||||
let form = new CreatePost({
|
let form: CreatePost = {
|
||||||
name,
|
name,
|
||||||
url,
|
url,
|
||||||
body,
|
body,
|
||||||
auth: api.auth.unwrap(),
|
auth: api.auth,
|
||||||
community_id,
|
community_id,
|
||||||
nsfw: None,
|
};
|
||||||
honeypot: None,
|
|
||||||
language_id: None,
|
|
||||||
});
|
|
||||||
return api.client.createPost(form);
|
return api.client.createPost(form);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function editPost(api: API, post: Post): Promise<PostResponse> {
|
export async function editPost(api: API, post: Post): Promise<PostResponse> {
|
||||||
let name = Some("A jest test federated post, updated");
|
let name = "A jest test federated post, updated";
|
||||||
let form = new EditPost({
|
let form: EditPost = {
|
||||||
name,
|
name,
|
||||||
post_id: post.id,
|
post_id: post.id,
|
||||||
auth: api.auth.unwrap(),
|
auth: api.auth,
|
||||||
nsfw: None,
|
};
|
||||||
url: None,
|
|
||||||
body: None,
|
|
||||||
language_id: None,
|
|
||||||
});
|
|
||||||
return api.client.editPost(form);
|
return api.client.editPost(form);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -271,11 +230,11 @@ export async function deletePost(
|
||||||
deleted: boolean,
|
deleted: boolean,
|
||||||
post: Post
|
post: Post
|
||||||
): Promise<PostResponse> {
|
): Promise<PostResponse> {
|
||||||
let form = new DeletePost({
|
let form: DeletePost = {
|
||||||
post_id: post.id,
|
post_id: post.id,
|
||||||
deleted: deleted,
|
deleted: deleted,
|
||||||
auth: api.auth.unwrap(),
|
auth: api.auth,
|
||||||
});
|
};
|
||||||
return api.client.deletePost(form);
|
return api.client.deletePost(form);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -284,12 +243,11 @@ export async function removePost(
|
||||||
removed: boolean,
|
removed: boolean,
|
||||||
post: Post
|
post: Post
|
||||||
): Promise<PostResponse> {
|
): Promise<PostResponse> {
|
||||||
let form = new RemovePost({
|
let form: RemovePost = {
|
||||||
post_id: post.id,
|
post_id: post.id,
|
||||||
removed,
|
removed,
|
||||||
auth: api.auth.unwrap(),
|
auth: api.auth,
|
||||||
reason: None,
|
};
|
||||||
});
|
|
||||||
return api.client.removePost(form);
|
return api.client.removePost(form);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -298,12 +256,12 @@ export async function featurePost(
|
||||||
featured: boolean,
|
featured: boolean,
|
||||||
post: Post
|
post: Post
|
||||||
): Promise<PostResponse> {
|
): Promise<PostResponse> {
|
||||||
let form = new FeaturePost({
|
let form: FeaturePost = {
|
||||||
post_id: post.id,
|
post_id: post.id,
|
||||||
featured,
|
featured,
|
||||||
feature_type: PostFeatureType.Community,
|
feature_type: PostFeatureType.Community,
|
||||||
auth: api.auth.unwrap(),
|
auth: api.auth,
|
||||||
});
|
};
|
||||||
return api.client.featurePost(form);
|
return api.client.featurePost(form);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -312,11 +270,11 @@ export async function lockPost(
|
||||||
locked: boolean,
|
locked: boolean,
|
||||||
post: Post
|
post: Post
|
||||||
): Promise<PostResponse> {
|
): Promise<PostResponse> {
|
||||||
let form = new LockPost({
|
let form: LockPost = {
|
||||||
post_id: post.id,
|
post_id: post.id,
|
||||||
locked,
|
locked,
|
||||||
auth: api.auth.unwrap(),
|
auth: api.auth,
|
||||||
});
|
};
|
||||||
return api.client.lockPost(form);
|
return api.client.lockPost(form);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -324,10 +282,10 @@ export async function resolvePost(
|
||||||
api: API,
|
api: API,
|
||||||
post: Post
|
post: Post
|
||||||
): Promise<ResolveObjectResponse> {
|
): Promise<ResolveObjectResponse> {
|
||||||
let form = new ResolveObject({
|
let form: ResolveObject = {
|
||||||
q: post.ap_id,
|
q: post.ap_id,
|
||||||
auth: api.auth,
|
auth: api.auth,
|
||||||
});
|
};
|
||||||
return api.client.resolveObject(form);
|
return api.client.resolveObject(form);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -335,18 +293,12 @@ export async function searchPostLocal(
|
||||||
api: API,
|
api: API,
|
||||||
post: Post
|
post: Post
|
||||||
): Promise<SearchResponse> {
|
): Promise<SearchResponse> {
|
||||||
let form = new Search({
|
let form: Search = {
|
||||||
q: post.name,
|
q: post.name,
|
||||||
type_: Some(SearchType.Posts),
|
type_: SearchType.Posts,
|
||||||
sort: Some(SortType.TopAll),
|
sort: SortType.TopAll,
|
||||||
community_id: None,
|
|
||||||
community_name: None,
|
|
||||||
creator_id: None,
|
|
||||||
listing_type: None,
|
|
||||||
page: None,
|
|
||||||
limit: None,
|
|
||||||
auth: api.auth,
|
auth: api.auth,
|
||||||
});
|
};
|
||||||
return api.client.search(form);
|
return api.client.search(form);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -354,11 +306,10 @@ export async function getPost(
|
||||||
api: API,
|
api: API,
|
||||||
post_id: number
|
post_id: number
|
||||||
): Promise<GetPostResponse> {
|
): Promise<GetPostResponse> {
|
||||||
let form = new GetPost({
|
let form: GetPost = {
|
||||||
id: Some(post_id),
|
id: post_id,
|
||||||
comment_id: None,
|
|
||||||
auth: api.auth,
|
auth: api.auth,
|
||||||
});
|
};
|
||||||
return api.client.getPost(form);
|
return api.client.getPost(form);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -366,19 +317,12 @@ export async function getComments(
|
||||||
api: API,
|
api: API,
|
||||||
post_id: number
|
post_id: number
|
||||||
): Promise<GetCommentsResponse> {
|
): Promise<GetCommentsResponse> {
|
||||||
let form = new GetComments({
|
let form: GetComments = {
|
||||||
post_id: Some(post_id),
|
post_id: post_id,
|
||||||
type_: Some(ListingType.All),
|
type_: ListingType.All,
|
||||||
sort: Some(CommentSortType.New), // TODO this sort might be wrong
|
sort: CommentSortType.New,
|
||||||
max_depth: None,
|
|
||||||
page: None,
|
|
||||||
limit: None,
|
|
||||||
community_id: None,
|
|
||||||
community_name: None,
|
|
||||||
saved_only: None,
|
|
||||||
parent_id: None,
|
|
||||||
auth: api.auth,
|
auth: api.auth,
|
||||||
});
|
};
|
||||||
return api.client.getComments(form);
|
return api.client.getComments(form);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -386,10 +330,10 @@ export async function resolveComment(
|
||||||
api: API,
|
api: API,
|
||||||
comment: Comment
|
comment: Comment
|
||||||
): Promise<ResolveObjectResponse> {
|
): Promise<ResolveObjectResponse> {
|
||||||
let form = new ResolveObject({
|
let form: ResolveObject = {
|
||||||
q: comment.ap_id,
|
q: comment.ap_id,
|
||||||
auth: api.auth,
|
auth: api.auth,
|
||||||
});
|
};
|
||||||
return api.client.resolveObject(form);
|
return api.client.resolveObject(form);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -397,10 +341,10 @@ export async function resolveBetaCommunity(
|
||||||
api: API
|
api: API
|
||||||
): Promise<ResolveObjectResponse> {
|
): Promise<ResolveObjectResponse> {
|
||||||
// Use short-hand search url
|
// Use short-hand search url
|
||||||
let form = new ResolveObject({
|
let form: ResolveObject = {
|
||||||
q: "!main@lemmy-beta:8551",
|
q: "!main@lemmy-beta:8551",
|
||||||
auth: api.auth,
|
auth: api.auth,
|
||||||
});
|
};
|
||||||
return api.client.resolveObject(form);
|
return api.client.resolveObject(form);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -408,10 +352,10 @@ export async function resolveCommunity(
|
||||||
api: API,
|
api: API,
|
||||||
q: string
|
q: string
|
||||||
): Promise<ResolveObjectResponse> {
|
): Promise<ResolveObjectResponse> {
|
||||||
let form = new ResolveObject({
|
let form: ResolveObject = {
|
||||||
q,
|
q,
|
||||||
auth: api.auth,
|
auth: api.auth,
|
||||||
});
|
};
|
||||||
return api.client.resolveObject(form);
|
return api.client.resolveObject(form);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -419,10 +363,10 @@ export async function resolvePerson(
|
||||||
api: API,
|
api: API,
|
||||||
apShortname: string
|
apShortname: string
|
||||||
): Promise<ResolveObjectResponse> {
|
): Promise<ResolveObjectResponse> {
|
||||||
let form = new ResolveObject({
|
let form: ResolveObject = {
|
||||||
q: apShortname,
|
q: apShortname,
|
||||||
auth: api.auth,
|
auth: api.auth,
|
||||||
});
|
};
|
||||||
return api.client.resolveObject(form);
|
return api.client.resolveObject(form);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -433,14 +377,12 @@ export async function banPersonFromSite(
|
||||||
remove_data: boolean
|
remove_data: boolean
|
||||||
): Promise<BanPersonResponse> {
|
): Promise<BanPersonResponse> {
|
||||||
// Make sure lemmy-beta/c/main is cached on lemmy_alpha
|
// Make sure lemmy-beta/c/main is cached on lemmy_alpha
|
||||||
let form = new BanPerson({
|
let form: BanPerson = {
|
||||||
person_id,
|
person_id,
|
||||||
ban,
|
ban,
|
||||||
remove_data: Some(remove_data),
|
remove_data: remove_data,
|
||||||
auth: api.auth.unwrap(),
|
auth: api.auth,
|
||||||
reason: None,
|
};
|
||||||
expires: None,
|
|
||||||
});
|
|
||||||
return api.client.banPerson(form);
|
return api.client.banPerson(form);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -451,15 +393,13 @@ export async function banPersonFromCommunity(
|
||||||
remove_data: boolean,
|
remove_data: boolean,
|
||||||
ban: boolean
|
ban: boolean
|
||||||
): Promise<BanFromCommunityResponse> {
|
): Promise<BanFromCommunityResponse> {
|
||||||
let form = new BanFromCommunity({
|
let form: BanFromCommunity = {
|
||||||
person_id,
|
person_id,
|
||||||
community_id,
|
community_id,
|
||||||
remove_data: Some(remove_data),
|
remove_data: remove_data,
|
||||||
ban,
|
ban,
|
||||||
reason: None,
|
auth: api.auth,
|
||||||
expires: None,
|
};
|
||||||
auth: api.auth.unwrap(),
|
|
||||||
});
|
|
||||||
return api.client.banFromCommunity(form);
|
return api.client.banFromCommunity(form);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -468,11 +408,11 @@ export async function followCommunity(
|
||||||
follow: boolean,
|
follow: boolean,
|
||||||
community_id: number
|
community_id: number
|
||||||
): Promise<CommunityResponse> {
|
): Promise<CommunityResponse> {
|
||||||
let form = new FollowCommunity({
|
let form: FollowCommunity = {
|
||||||
community_id,
|
community_id,
|
||||||
follow,
|
follow,
|
||||||
auth: api.auth.unwrap(),
|
auth: api.auth,
|
||||||
});
|
};
|
||||||
return api.client.followCommunity(form);
|
return api.client.followCommunity(form);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -481,11 +421,11 @@ export async function likePost(
|
||||||
score: number,
|
score: number,
|
||||||
post: Post
|
post: Post
|
||||||
): Promise<PostResponse> {
|
): Promise<PostResponse> {
|
||||||
let form = new CreatePostLike({
|
let form: CreatePostLike = {
|
||||||
post_id: post.id,
|
post_id: post.id,
|
||||||
score: score,
|
score: score,
|
||||||
auth: api.auth.unwrap(),
|
auth: api.auth,
|
||||||
});
|
};
|
||||||
|
|
||||||
return api.client.likePost(form);
|
return api.client.likePost(form);
|
||||||
}
|
}
|
||||||
|
@ -493,33 +433,28 @@ export async function likePost(
|
||||||
export async function createComment(
|
export async function createComment(
|
||||||
api: API,
|
api: API,
|
||||||
post_id: number,
|
post_id: number,
|
||||||
parent_id: Option<number>,
|
parent_id?: number,
|
||||||
content = "a jest test comment"
|
content = "a jest test comment"
|
||||||
): Promise<CommentResponse> {
|
): Promise<CommentResponse> {
|
||||||
let form = new CreateComment({
|
let form: CreateComment = {
|
||||||
content,
|
content,
|
||||||
post_id,
|
post_id,
|
||||||
parent_id,
|
parent_id,
|
||||||
form_id: None,
|
auth: api.auth,
|
||||||
language_id: None,
|
};
|
||||||
auth: api.auth.unwrap(),
|
|
||||||
});
|
|
||||||
return api.client.createComment(form);
|
return api.client.createComment(form);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function editComment(
|
export async function editComment(
|
||||||
api: API,
|
api: API,
|
||||||
comment_id: number,
|
comment_id: number,
|
||||||
content = Some("A jest test federated comment update")
|
content = "A jest test federated comment update"
|
||||||
): Promise<CommentResponse> {
|
): Promise<CommentResponse> {
|
||||||
let form = new EditComment({
|
let form: EditComment = {
|
||||||
content,
|
content,
|
||||||
comment_id,
|
comment_id,
|
||||||
form_id: None,
|
auth: api.auth,
|
||||||
language_id: None,
|
};
|
||||||
distinguished: None,
|
|
||||||
auth: api.auth.unwrap(),
|
|
||||||
});
|
|
||||||
return api.client.editComment(form);
|
return api.client.editComment(form);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -528,11 +463,11 @@ export async function deleteComment(
|
||||||
deleted: boolean,
|
deleted: boolean,
|
||||||
comment_id: number
|
comment_id: number
|
||||||
): Promise<CommentResponse> {
|
): Promise<CommentResponse> {
|
||||||
let form = new DeleteComment({
|
let form: DeleteComment = {
|
||||||
comment_id,
|
comment_id,
|
||||||
deleted,
|
deleted,
|
||||||
auth: api.auth.unwrap(),
|
auth: api.auth,
|
||||||
});
|
};
|
||||||
return api.client.deleteComment(form);
|
return api.client.deleteComment(form);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -541,25 +476,22 @@ export async function removeComment(
|
||||||
removed: boolean,
|
removed: boolean,
|
||||||
comment_id: number
|
comment_id: number
|
||||||
): Promise<CommentResponse> {
|
): Promise<CommentResponse> {
|
||||||
let form = new RemoveComment({
|
let form: RemoveComment = {
|
||||||
comment_id,
|
comment_id,
|
||||||
removed,
|
removed,
|
||||||
reason: None,
|
auth: api.auth,
|
||||||
auth: api.auth.unwrap(),
|
};
|
||||||
});
|
|
||||||
return api.client.removeComment(form);
|
return api.client.removeComment(form);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getMentions(
|
export async function getMentions(
|
||||||
api: API
|
api: API
|
||||||
): Promise<GetPersonMentionsResponse> {
|
): Promise<GetPersonMentionsResponse> {
|
||||||
let form = new GetPersonMentions({
|
let form: GetPersonMentions = {
|
||||||
sort: Some(CommentSortType.New),
|
sort: CommentSortType.New,
|
||||||
unread_only: Some(false),
|
unread_only: false,
|
||||||
auth: api.auth.unwrap(),
|
auth: api.auth,
|
||||||
page: None,
|
};
|
||||||
limit: None,
|
|
||||||
});
|
|
||||||
return api.client.getPersonMentions(form);
|
return api.client.getPersonMentions(form);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -568,11 +500,11 @@ export async function likeComment(
|
||||||
score: number,
|
score: number,
|
||||||
comment: Comment
|
comment: Comment
|
||||||
): Promise<CommentResponse> {
|
): Promise<CommentResponse> {
|
||||||
let form = new CreateCommentLike({
|
let form: CreateCommentLike = {
|
||||||
comment_id: comment.id,
|
comment_id: comment.id,
|
||||||
score,
|
score,
|
||||||
auth: api.auth.unwrap(),
|
auth: api.auth,
|
||||||
});
|
};
|
||||||
return api.client.likeComment(form);
|
return api.client.likeComment(form);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -580,17 +512,13 @@ export async function createCommunity(
|
||||||
api: API,
|
api: API,
|
||||||
name_: string = randomString(5)
|
name_: string = randomString(5)
|
||||||
): Promise<CommunityResponse> {
|
): Promise<CommunityResponse> {
|
||||||
let description = Some("a sample description");
|
let description = "a sample description";
|
||||||
let form = new CreateCommunity({
|
let form: CreateCommunity = {
|
||||||
name: name_,
|
name: name_,
|
||||||
title: name_,
|
title: name_,
|
||||||
description,
|
description,
|
||||||
nsfw: None,
|
auth: api.auth,
|
||||||
icon: None,
|
};
|
||||||
banner: None,
|
|
||||||
posting_restricted_to_mods: None,
|
|
||||||
auth: api.auth.unwrap(),
|
|
||||||
});
|
|
||||||
return api.client.createCommunity(form);
|
return api.client.createCommunity(form);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -598,11 +526,10 @@ export async function getCommunity(
|
||||||
api: API,
|
api: API,
|
||||||
id: number
|
id: number
|
||||||
): Promise<CommunityResponse> {
|
): Promise<CommunityResponse> {
|
||||||
let form = new GetCommunity({
|
let form: GetCommunity = {
|
||||||
id: Some(id),
|
id,
|
||||||
name: None,
|
|
||||||
auth: api.auth,
|
auth: api.auth,
|
||||||
});
|
};
|
||||||
return api.client.getCommunity(form);
|
return api.client.getCommunity(form);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -611,11 +538,11 @@ export async function deleteCommunity(
|
||||||
deleted: boolean,
|
deleted: boolean,
|
||||||
community_id: number
|
community_id: number
|
||||||
): Promise<CommunityResponse> {
|
): Promise<CommunityResponse> {
|
||||||
let form = new DeleteCommunity({
|
let form: DeleteCommunity = {
|
||||||
community_id,
|
community_id,
|
||||||
deleted,
|
deleted,
|
||||||
auth: api.auth.unwrap(),
|
auth: api.auth,
|
||||||
});
|
};
|
||||||
return api.client.deleteCommunity(form);
|
return api.client.deleteCommunity(form);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -624,13 +551,11 @@ export async function removeCommunity(
|
||||||
removed: boolean,
|
removed: boolean,
|
||||||
community_id: number
|
community_id: number
|
||||||
): Promise<CommunityResponse> {
|
): Promise<CommunityResponse> {
|
||||||
let form = new RemoveCommunity({
|
let form: RemoveCommunity = {
|
||||||
community_id,
|
community_id,
|
||||||
removed,
|
removed,
|
||||||
reason: None,
|
auth: api.auth,
|
||||||
expires: None,
|
};
|
||||||
auth: api.auth.unwrap(),
|
|
||||||
});
|
|
||||||
return api.client.removeCommunity(form);
|
return api.client.removeCommunity(form);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -639,11 +564,11 @@ export async function createPrivateMessage(
|
||||||
recipient_id: number
|
recipient_id: number
|
||||||
): Promise<PrivateMessageResponse> {
|
): Promise<PrivateMessageResponse> {
|
||||||
let content = "A jest test federated private message";
|
let content = "A jest test federated private message";
|
||||||
let form = new CreatePrivateMessage({
|
let form: CreatePrivateMessage = {
|
||||||
content,
|
content,
|
||||||
recipient_id,
|
recipient_id,
|
||||||
auth: api.auth.unwrap(),
|
auth: api.auth,
|
||||||
});
|
};
|
||||||
return api.client.createPrivateMessage(form);
|
return api.client.createPrivateMessage(form);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -652,11 +577,11 @@ export async function editPrivateMessage(
|
||||||
private_message_id: number
|
private_message_id: number
|
||||||
): Promise<PrivateMessageResponse> {
|
): Promise<PrivateMessageResponse> {
|
||||||
let updatedContent = "A jest test federated private message edited";
|
let updatedContent = "A jest test federated private message edited";
|
||||||
let form = new EditPrivateMessage({
|
let form: EditPrivateMessage = {
|
||||||
content: updatedContent,
|
content: updatedContent,
|
||||||
private_message_id,
|
private_message_id,
|
||||||
auth: api.auth.unwrap(),
|
auth: api.auth,
|
||||||
});
|
};
|
||||||
return api.client.editPrivateMessage(form);
|
return api.client.editPrivateMessage(form);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -665,11 +590,11 @@ export async function deletePrivateMessage(
|
||||||
deleted: boolean,
|
deleted: boolean,
|
||||||
private_message_id: number
|
private_message_id: number
|
||||||
): Promise<PrivateMessageResponse> {
|
): Promise<PrivateMessageResponse> {
|
||||||
let form = new DeletePrivateMessage({
|
let form: DeletePrivateMessage = {
|
||||||
deleted,
|
deleted,
|
||||||
private_message_id,
|
private_message_id,
|
||||||
auth: api.auth.unwrap(),
|
auth: api.auth,
|
||||||
});
|
};
|
||||||
return api.client.deletePrivateMessage(form);
|
return api.client.deletePrivateMessage(form);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -677,78 +602,49 @@ export async function registerUser(
|
||||||
api: API,
|
api: API,
|
||||||
username: string = randomString(5)
|
username: string = randomString(5)
|
||||||
): Promise<LoginResponse> {
|
): Promise<LoginResponse> {
|
||||||
let form = new Register({
|
let form: Register = {
|
||||||
username,
|
username,
|
||||||
password,
|
password,
|
||||||
password_verify: password,
|
password_verify: password,
|
||||||
show_nsfw: true,
|
show_nsfw: true,
|
||||||
email: None,
|
};
|
||||||
captcha_uuid: None,
|
|
||||||
captcha_answer: None,
|
|
||||||
honeypot: None,
|
|
||||||
answer: None,
|
|
||||||
});
|
|
||||||
return api.client.register(form);
|
return api.client.register(form);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function saveUserSettingsBio(api: API): Promise<LoginResponse> {
|
export async function saveUserSettingsBio(api: API): Promise<LoginResponse> {
|
||||||
let form = new SaveUserSettings({
|
let form: SaveUserSettings = {
|
||||||
show_nsfw: Some(true),
|
show_nsfw: true,
|
||||||
theme: Some("darkly"),
|
theme: "darkly",
|
||||||
default_sort_type: Some(Object.keys(SortType).indexOf(SortType.Active)),
|
default_sort_type: Object.keys(SortType).indexOf(SortType.Active),
|
||||||
default_listing_type: Some(
|
default_listing_type: Object.keys(ListingType).indexOf(ListingType.All),
|
||||||
Object.keys(ListingType).indexOf(ListingType.All)
|
interface_language: "en",
|
||||||
),
|
show_avatars: true,
|
||||||
interface_language: Some("en"),
|
send_notifications_to_email: false,
|
||||||
show_avatars: Some(true),
|
bio: "a changed bio",
|
||||||
send_notifications_to_email: Some(false),
|
auth: api.auth,
|
||||||
bio: Some("a changed bio"),
|
};
|
||||||
avatar: None,
|
|
||||||
banner: None,
|
|
||||||
display_name: None,
|
|
||||||
email: None,
|
|
||||||
matrix_user_id: None,
|
|
||||||
show_scores: None,
|
|
||||||
show_read_posts: None,
|
|
||||||
show_bot_accounts: None,
|
|
||||||
show_new_post_notifs: None,
|
|
||||||
bot_account: None,
|
|
||||||
discussion_languages: None,
|
|
||||||
auth: api.auth.unwrap(),
|
|
||||||
});
|
|
||||||
return saveUserSettings(api, form);
|
return saveUserSettings(api, form);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function saveUserSettingsFederated(
|
export async function saveUserSettingsFederated(
|
||||||
api: API
|
api: API
|
||||||
): Promise<LoginResponse> {
|
): Promise<LoginResponse> {
|
||||||
let avatar = Some("https://image.flaticon.com/icons/png/512/35/35896.png");
|
let avatar = "https://image.flaticon.com/icons/png/512/35/35896.png";
|
||||||
let banner = Some("https://image.flaticon.com/icons/png/512/36/35896.png");
|
let banner = "https://image.flaticon.com/icons/png/512/36/35896.png";
|
||||||
let bio = Some("a changed bio");
|
let bio = "a changed bio";
|
||||||
let form = new SaveUserSettings({
|
let form: SaveUserSettings = {
|
||||||
show_nsfw: Some(false),
|
show_nsfw: false,
|
||||||
theme: Some(""),
|
default_sort_type: Object.keys(SortType).indexOf(SortType.Hot),
|
||||||
default_sort_type: Some(Object.keys(SortType).indexOf(SortType.Hot)),
|
default_listing_type: Object.keys(ListingType).indexOf(ListingType.All),
|
||||||
default_listing_type: Some(
|
interface_language: "",
|
||||||
Object.keys(ListingType).indexOf(ListingType.All)
|
|
||||||
),
|
|
||||||
interface_language: Some(""),
|
|
||||||
avatar,
|
avatar,
|
||||||
banner,
|
banner,
|
||||||
display_name: Some("user321"),
|
display_name: "user321",
|
||||||
show_avatars: Some(false),
|
show_avatars: false,
|
||||||
send_notifications_to_email: Some(false),
|
send_notifications_to_email: false,
|
||||||
bio,
|
bio,
|
||||||
email: None,
|
auth: api.auth,
|
||||||
show_scores: None,
|
};
|
||||||
show_read_posts: None,
|
|
||||||
matrix_user_id: None,
|
|
||||||
bot_account: None,
|
|
||||||
show_bot_accounts: None,
|
|
||||||
show_new_post_notifs: None,
|
|
||||||
discussion_languages: None,
|
|
||||||
auth: api.auth.unwrap(),
|
|
||||||
});
|
|
||||||
return await saveUserSettings(alpha, form);
|
return await saveUserSettings(alpha, form);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -760,38 +656,35 @@ export async function saveUserSettings(
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function deleteUser(api: API): Promise<DeleteAccountResponse> {
|
export async function deleteUser(api: API): Promise<DeleteAccountResponse> {
|
||||||
let form = new DeleteAccount({
|
let form: DeleteAccount = {
|
||||||
auth: api.auth.unwrap(),
|
auth: api.auth,
|
||||||
password,
|
password,
|
||||||
});
|
};
|
||||||
return api.client.deleteAccount(form);
|
return api.client.deleteAccount(form);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getSite(api: API): Promise<GetSiteResponse> {
|
export async function getSite(api: API): Promise<GetSiteResponse> {
|
||||||
let form = new GetSite({
|
let form: GetSite = {
|
||||||
auth: api.auth,
|
auth: api.auth,
|
||||||
});
|
};
|
||||||
return api.client.getSite(form);
|
return api.client.getSite(form);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function listPrivateMessages(
|
export async function listPrivateMessages(
|
||||||
api: API
|
api: API
|
||||||
): Promise<PrivateMessagesResponse> {
|
): Promise<PrivateMessagesResponse> {
|
||||||
let form = new GetPrivateMessages({
|
let form: GetPrivateMessages = {
|
||||||
auth: api.auth.unwrap(),
|
auth: api.auth,
|
||||||
unread_only: Some(false),
|
unread_only: false,
|
||||||
page: None,
|
};
|
||||||
limit: None,
|
|
||||||
});
|
|
||||||
return api.client.getPrivateMessages(form);
|
return api.client.getPrivateMessages(form);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function unfollowRemotes(api: API): Promise<GetSiteResponse> {
|
export async function unfollowRemotes(api: API): Promise<GetSiteResponse> {
|
||||||
// Unfollow all remote communities
|
// Unfollow all remote communities
|
||||||
let site = await getSite(api);
|
let site = await getSite(api);
|
||||||
let remoteFollowed = site.my_user
|
let remoteFollowed =
|
||||||
.unwrap()
|
site.my_user?.follows.filter(c => c.community.local == false) ?? [];
|
||||||
.follows.filter(c => c.community.local == false);
|
|
||||||
for (let cu of remoteFollowed) {
|
for (let cu of remoteFollowed) {
|
||||||
await followCommunity(api, false, cu.community.id);
|
await followCommunity(api, false, cu.community.id);
|
||||||
}
|
}
|
||||||
|
@ -801,12 +694,8 @@ export async function unfollowRemotes(api: API): Promise<GetSiteResponse> {
|
||||||
|
|
||||||
export async function followBeta(api: API): Promise<CommunityResponse> {
|
export async function followBeta(api: API): Promise<CommunityResponse> {
|
||||||
let betaCommunity = (await resolveBetaCommunity(api)).community;
|
let betaCommunity = (await resolveBetaCommunity(api)).community;
|
||||||
if (betaCommunity.isSome()) {
|
if (betaCommunity) {
|
||||||
let follow = await followCommunity(
|
let follow = await followCommunity(api, true, betaCommunity.community.id);
|
||||||
api,
|
|
||||||
true,
|
|
||||||
betaCommunity.unwrap().community.id
|
|
||||||
);
|
|
||||||
return follow;
|
return follow;
|
||||||
} else {
|
} else {
|
||||||
return Promise.reject("no community worked");
|
return Promise.reject("no community worked");
|
||||||
|
@ -818,24 +707,20 @@ export async function reportPost(
|
||||||
post_id: number,
|
post_id: number,
|
||||||
reason: string
|
reason: string
|
||||||
): Promise<PostReportResponse> {
|
): Promise<PostReportResponse> {
|
||||||
let form = new CreatePostReport({
|
let form: CreatePostReport = {
|
||||||
post_id,
|
post_id,
|
||||||
reason,
|
reason,
|
||||||
auth: api.auth.unwrap(),
|
auth: api.auth,
|
||||||
});
|
};
|
||||||
return api.client.createPostReport(form);
|
return api.client.createPostReport(form);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function listPostReports(
|
export async function listPostReports(
|
||||||
api: API
|
api: API
|
||||||
): Promise<ListPostReportsResponse> {
|
): Promise<ListPostReportsResponse> {
|
||||||
let form = new ListPostReports({
|
let form: ListPostReports = {
|
||||||
auth: api.auth.unwrap(),
|
auth: api.auth,
|
||||||
page: None,
|
};
|
||||||
limit: None,
|
|
||||||
community_id: None,
|
|
||||||
unresolved_only: None,
|
|
||||||
});
|
|
||||||
return api.client.listPostReports(form);
|
return api.client.listPostReports(form);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -844,24 +729,20 @@ export async function reportComment(
|
||||||
comment_id: number,
|
comment_id: number,
|
||||||
reason: string
|
reason: string
|
||||||
): Promise<CommentReportResponse> {
|
): Promise<CommentReportResponse> {
|
||||||
let form = new CreateCommentReport({
|
let form: CreateCommentReport = {
|
||||||
comment_id,
|
comment_id,
|
||||||
reason,
|
reason,
|
||||||
auth: api.auth.unwrap(),
|
auth: api.auth,
|
||||||
});
|
};
|
||||||
return api.client.createCommentReport(form);
|
return api.client.createCommentReport(form);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function listCommentReports(
|
export async function listCommentReports(
|
||||||
api: API
|
api: API
|
||||||
): Promise<ListCommentReportsResponse> {
|
): Promise<ListCommentReportsResponse> {
|
||||||
let form = new ListCommentReports({
|
let form: ListCommentReports = {
|
||||||
page: None,
|
auth: api.auth,
|
||||||
limit: None,
|
};
|
||||||
community_id: None,
|
|
||||||
unresolved_only: None,
|
|
||||||
auth: api.auth.unwrap(),
|
|
||||||
});
|
|
||||||
return api.client.listCommentReports(form);
|
return api.client.listCommentReports(form);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -895,14 +776,14 @@ export async function unfollows() {
|
||||||
await unfollowRemotes(epsilon);
|
await unfollowRemotes(epsilon);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getCommentParentId(comment: Comment): Option<number> {
|
export function getCommentParentId(comment: Comment): number | undefined {
|
||||||
let split = comment.path.split(".");
|
let split = comment.path.split(".");
|
||||||
// remove the 0
|
// remove the 0
|
||||||
split.shift();
|
split.shift();
|
||||||
|
|
||||||
if (split.length > 1) {
|
if (split.length > 1) {
|
||||||
return Some(Number(split[split.length - 2]));
|
return Number(split[split.length - 2]);
|
||||||
} else {
|
} else {
|
||||||
return None;
|
return undefined;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
jest.setTimeout(120000);
|
jest.setTimeout(120000);
|
||||||
import { None } from "@sniptt/monads";
|
|
||||||
import { PersonViewSafe } from "lemmy-js-client";
|
import { PersonViewSafe } from "lemmy-js-client";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
@ -27,42 +26,35 @@ beforeAll(async () => {
|
||||||
let apShortname: string;
|
let apShortname: string;
|
||||||
|
|
||||||
function assertUserFederation(
|
function assertUserFederation(
|
||||||
userOne: PersonViewSafe,
|
userOne?: PersonViewSafe,
|
||||||
userTwo: PersonViewSafe
|
userTwo?: PersonViewSafe
|
||||||
) {
|
) {
|
||||||
expect(userOne.person.name).toBe(userTwo.person.name);
|
expect(userOne?.person.name).toBe(userTwo?.person.name);
|
||||||
expect(userOne.person.display_name.unwrapOr("none")).toBe(
|
expect(userOne?.person.display_name).toBe(userTwo?.person.display_name);
|
||||||
userTwo.person.display_name.unwrapOr("none")
|
expect(userOne?.person.bio).toBe(userTwo?.person.bio);
|
||||||
);
|
expect(userOne?.person.actor_id).toBe(userTwo?.person.actor_id);
|
||||||
expect(userOne.person.bio.unwrapOr("none")).toBe(
|
expect(userOne?.person.avatar).toBe(userTwo?.person.avatar);
|
||||||
userTwo.person.bio.unwrapOr("none")
|
expect(userOne?.person.banner).toBe(userTwo?.person.banner);
|
||||||
);
|
expect(userOne?.person.published).toBe(userTwo?.person.published);
|
||||||
expect(userOne.person.actor_id).toBe(userTwo.person.actor_id);
|
|
||||||
expect(userOne.person.avatar.unwrapOr("none")).toBe(
|
|
||||||
userTwo.person.avatar.unwrapOr("none")
|
|
||||||
);
|
|
||||||
expect(userOne.person.banner.unwrapOr("none")).toBe(
|
|
||||||
userTwo.person.banner.unwrapOr("none")
|
|
||||||
);
|
|
||||||
expect(userOne.person.published).toBe(userTwo.person.published);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
test("Create user", async () => {
|
test("Create user", async () => {
|
||||||
let userRes = await registerUser(alpha);
|
let userRes = await registerUser(alpha);
|
||||||
expect(userRes.jwt).toBeDefined();
|
expect(userRes.jwt).toBeDefined();
|
||||||
alpha.auth = userRes.jwt;
|
alpha.auth = userRes.jwt ?? "";
|
||||||
|
|
||||||
let site = await getSite(alpha);
|
let site = await getSite(alpha);
|
||||||
expect(site.my_user).toBeDefined();
|
expect(site.my_user).toBeDefined();
|
||||||
apShortname = `@${
|
if (!site.my_user) {
|
||||||
site.my_user.unwrap().local_user_view.person.name
|
throw "Missing site user";
|
||||||
}@lemmy-alpha:8541`;
|
}
|
||||||
|
apShortname = `@${site.my_user.local_user_view.person.name}@lemmy-alpha:8541`;
|
||||||
});
|
});
|
||||||
|
|
||||||
test("Set some user settings, check that they are federated", async () => {
|
test("Set some user settings, check that they are federated", async () => {
|
||||||
await saveUserSettingsFederated(alpha);
|
await saveUserSettingsFederated(alpha);
|
||||||
let alphaPerson = (await resolvePerson(alpha, apShortname)).person.unwrap();
|
let alphaPerson = (await resolvePerson(alpha, apShortname)).person;
|
||||||
let betaPerson = (await resolvePerson(beta, apShortname)).person.unwrap();
|
let betaPerson = (await resolvePerson(beta, apShortname)).person;
|
||||||
assertUserFederation(alphaPerson, betaPerson);
|
assertUserFederation(alphaPerson, betaPerson);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -71,37 +63,38 @@ test("Delete user", async () => {
|
||||||
expect(userRes.jwt).toBeDefined();
|
expect(userRes.jwt).toBeDefined();
|
||||||
let user: API = {
|
let user: API = {
|
||||||
client: alpha.client,
|
client: alpha.client,
|
||||||
auth: userRes.jwt,
|
auth: userRes.jwt ?? "",
|
||||||
};
|
};
|
||||||
|
|
||||||
// make a local post and comment
|
// make a local post and comment
|
||||||
let alphaCommunity = (
|
let alphaCommunity = (await resolveCommunity(user, "!main@lemmy-alpha:8541"))
|
||||||
await resolveCommunity(user, "!main@lemmy-alpha:8541")
|
.community;
|
||||||
).community.unwrap();
|
if (!alphaCommunity) {
|
||||||
|
throw "Missing alpha community";
|
||||||
|
}
|
||||||
let localPost = (await createPost(user, alphaCommunity.community.id))
|
let localPost = (await createPost(user, alphaCommunity.community.id))
|
||||||
.post_view.post;
|
.post_view.post;
|
||||||
expect(localPost).toBeDefined();
|
expect(localPost).toBeDefined();
|
||||||
let localComment = (await createComment(user, localPost.id, None))
|
let localComment = (await createComment(user, localPost.id)).comment_view
|
||||||
.comment_view.comment;
|
.comment;
|
||||||
expect(localComment).toBeDefined();
|
expect(localComment).toBeDefined();
|
||||||
|
|
||||||
// make a remote post and comment
|
// make a remote post and comment
|
||||||
let betaCommunity = (await resolveBetaCommunity(user)).community.unwrap();
|
let betaCommunity = (await resolveBetaCommunity(user)).community;
|
||||||
|
if (!betaCommunity) {
|
||||||
|
throw "Missing beta community";
|
||||||
|
}
|
||||||
let remotePost = (await createPost(user, betaCommunity.community.id))
|
let remotePost = (await createPost(user, betaCommunity.community.id))
|
||||||
.post_view.post;
|
.post_view.post;
|
||||||
expect(remotePost).toBeDefined();
|
expect(remotePost).toBeDefined();
|
||||||
let remoteComment = (await createComment(user, remotePost.id, None))
|
let remoteComment = (await createComment(user, remotePost.id)).comment_view
|
||||||
.comment_view.comment;
|
.comment;
|
||||||
expect(remoteComment).toBeDefined();
|
expect(remoteComment).toBeDefined();
|
||||||
|
|
||||||
await deleteUser(user);
|
await deleteUser(user);
|
||||||
|
|
||||||
expect((await resolvePost(alpha, localPost)).post.isNone()).toBe(true);
|
expect((await resolvePost(alpha, localPost)).post).toBeUndefined();
|
||||||
expect((await resolveComment(alpha, localComment)).comment.isNone()).toBe(
|
expect((await resolveComment(alpha, localComment)).comment).toBeUndefined();
|
||||||
true
|
expect((await resolvePost(alpha, remotePost)).post).toBeUndefined();
|
||||||
);
|
expect((await resolveComment(alpha, remoteComment)).comment).toBeUndefined();
|
||||||
expect((await resolvePost(alpha, remotePost)).post.isNone()).toBe(true);
|
|
||||||
expect((await resolveComment(alpha, remoteComment)).comment.isNone()).toBe(
|
|
||||||
true
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
"lib": ["es2017", "es7", "es6", "dom"],
|
"lib": ["es2017", "es7", "es6", "dom"],
|
||||||
"outDir": "./dist",
|
"outDir": "./dist",
|
||||||
"target": "ES5",
|
"target": "ES5",
|
||||||
|
"strictNullChecks": true,
|
||||||
"moduleResolution": "Node"
|
"moduleResolution": "Node"
|
||||||
},
|
},
|
||||||
"include": [
|
"include": [
|
||||||
|
|
|
@ -596,11 +596,6 @@
|
||||||
dependencies:
|
dependencies:
|
||||||
"@sinonjs/commons" "^1.7.0"
|
"@sinonjs/commons" "^1.7.0"
|
||||||
|
|
||||||
"@sniptt/monads@^0.5.10":
|
|
||||||
version "0.5.10"
|
|
||||||
resolved "https://registry.yarnpkg.com/@sniptt/monads/-/monads-0.5.10.tgz#a80cd00738bbd682d36d36dd36bdc0bddc96eb76"
|
|
||||||
integrity sha512-+agDOv9DpDV+9e2zN/Vmdk+XaqGx5Sykl0fqhqgiJ90r18nsBkxe44DmZ2sA1HYK+MSsBeZBiAr6pq4w+5uhfw==
|
|
||||||
|
|
||||||
"@tootallnate/once@1":
|
"@tootallnate/once@1":
|
||||||
version "1.1.2"
|
version "1.1.2"
|
||||||
resolved "https://registry.yarnpkg.com/@tootallnate/once/-/once-1.1.2.tgz#ccb91445360179a04e7fe6aff78c00ffc1eeaf82"
|
resolved "https://registry.yarnpkg.com/@tootallnate/once/-/once-1.1.2.tgz#ccb91445360179a04e7fe6aff78c00ffc1eeaf82"
|
||||||
|
@ -1077,11 +1072,6 @@ cjs-module-lexer@^1.0.0:
|
||||||
resolved "https://registry.yarnpkg.com/cjs-module-lexer/-/cjs-module-lexer-1.2.2.tgz#9f84ba3244a512f3a54e5277e8eef4c489864e40"
|
resolved "https://registry.yarnpkg.com/cjs-module-lexer/-/cjs-module-lexer-1.2.2.tgz#9f84ba3244a512f3a54e5277e8eef4c489864e40"
|
||||||
integrity sha512-cOU9usZw8/dXIXKtwa8pM0OTJQuJkxMN6w30csNRUerHfeQ5R6U3kkU/FtJeIf3M202OHfY2U8ccInBG7/xogA==
|
integrity sha512-cOU9usZw8/dXIXKtwa8pM0OTJQuJkxMN6w30csNRUerHfeQ5R6U3kkU/FtJeIf3M202OHfY2U8ccInBG7/xogA==
|
||||||
|
|
||||||
class-transformer@^0.5.1:
|
|
||||||
version "0.5.1"
|
|
||||||
resolved "https://registry.yarnpkg.com/class-transformer/-/class-transformer-0.5.1.tgz#24147d5dffd2a6cea930a3250a677addf96ab336"
|
|
||||||
integrity sha512-SQa1Ws6hUbfC98vKGxZH3KFY0Y1lm5Zm0SY8XX9zbK7FJCyVEac3ATW0RIpwzW+oOfmHE5PMPufDG9hCfoEOMw==
|
|
||||||
|
|
||||||
cliui@^7.0.2:
|
cliui@^7.0.2:
|
||||||
version "7.0.4"
|
version "7.0.4"
|
||||||
resolved "https://registry.yarnpkg.com/cliui/-/cliui-7.0.4.tgz#a0265ee655476fc807aea9df3df8df7783808b4f"
|
resolved "https://registry.yarnpkg.com/cliui/-/cliui-7.0.4.tgz#a0265ee655476fc807aea9df3df8df7783808b4f"
|
||||||
|
@ -2373,15 +2363,12 @@ kleur@^3.0.3:
|
||||||
resolved "https://registry.yarnpkg.com/kleur/-/kleur-3.0.3.tgz#a79c9ecc86ee1ce3fa6206d1216c501f147fc07e"
|
resolved "https://registry.yarnpkg.com/kleur/-/kleur-3.0.3.tgz#a79c9ecc86ee1ce3fa6206d1216c501f147fc07e"
|
||||||
integrity sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w==
|
integrity sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w==
|
||||||
|
|
||||||
lemmy-js-client@0.17.0-rc.56:
|
lemmy-js-client@0.17.0-rc.60:
|
||||||
version "0.17.0-rc.56"
|
version "0.17.0-rc.60"
|
||||||
resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.17.0-rc.56.tgz#2c7abba9b8195826eb36401e7c5c2cb75609bcf2"
|
resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.17.0-rc.60.tgz#6cabac42d842eb1f152d230be018090050476614"
|
||||||
integrity sha512-7MM5xV8H9fIr1TbM/4e9PFKJpwlD2t135pSiH92TFgdkTzOMf0mtLO2BWLAQ7Rq+XVoVgj/WSBR4BofJka8XRQ==
|
integrity sha512-Nl+DUBJde0KpKywNkX5wof9PDCmr6RuJlgukVfQRmW5rznYRKYnI1V+awf+9mUx1eNQ8jhnjVO+6XxOzMjloZA==
|
||||||
dependencies:
|
dependencies:
|
||||||
"@sniptt/monads" "^0.5.10"
|
|
||||||
class-transformer "^0.5.1"
|
|
||||||
node-fetch "2.6.6"
|
node-fetch "2.6.6"
|
||||||
reflect-metadata "^0.1.13"
|
|
||||||
|
|
||||||
leven@^3.1.0:
|
leven@^3.1.0:
|
||||||
version "3.1.0"
|
version "3.1.0"
|
||||||
|
@ -2761,11 +2748,6 @@ react-is@^17.0.1:
|
||||||
resolved "https://registry.yarnpkg.com/react-is/-/react-is-17.0.2.tgz#e691d4a8e9c789365655539ab372762b0efb54f0"
|
resolved "https://registry.yarnpkg.com/react-is/-/react-is-17.0.2.tgz#e691d4a8e9c789365655539ab372762b0efb54f0"
|
||||||
integrity sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==
|
integrity sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==
|
||||||
|
|
||||||
reflect-metadata@^0.1.13:
|
|
||||||
version "0.1.13"
|
|
||||||
resolved "https://registry.yarnpkg.com/reflect-metadata/-/reflect-metadata-0.1.13.tgz#67ae3ca57c972a2aa1642b10fe363fe32d49dc08"
|
|
||||||
integrity sha512-Ts1Y/anZELhSsjMcU605fU9RE4Oi3p5ORujwbIKXfWa+0Zxs510Qrmrce5/Jowq3cHSZSJqBjypxmHarc+vEWg==
|
|
||||||
|
|
||||||
regexpp@^3.2.0:
|
regexpp@^3.2.0:
|
||||||
version "3.2.0"
|
version "3.2.0"
|
||||||
resolved "https://registry.yarnpkg.com/regexpp/-/regexpp-3.2.0.tgz#0425a2768d8f23bad70ca4b90461fa2f1213e1b2"
|
resolved "https://registry.yarnpkg.com/regexpp/-/regexpp-3.2.0.tgz#0425a2768d8f23bad70ca4b90461fa2f1213e1b2"
|
||||||
|
|
Loading…
Reference in a new issue