});
test("Create a comment in a non-existent post", async () => {
- let commentRes = (await createComment(alpha, -1)) as any;
- expect(commentRes.error).toBe("couldnt_find_post");
+ await expect(createComment(alpha, -1)).rejects.toBe("couldnt_find_post");
});
test("Update a comment", async () => {
expect(deleteCommentRes.comment_view.comment.deleted).toBe(true);
// Make sure that comment is undefined on beta
- let betaCommentRes = (await resolveComment(
- beta,
- commentRes.comment_view.comment,
- )) as any;
- expect(betaCommentRes.error).toBe("couldnt_find_object");
+ await expect(
+ resolveComment(beta, commentRes.comment_view.comment),
+ ).rejects.toBe("couldnt_find_object");
let undeleteCommentRes = await deleteComment(
alpha,
alpha,
commentRes.comment_view.comment.creator_id,
);
- console.log(refetchedPostComments.comments[0].comment);
expect(refetchedPostComments.comments[0].comment.removed).toBe(true);
let unremoveCommentRes = await removeComment(beta, false, betaCommentId);
assertPostFederation(betaPost, postRes.post_view);
// Delta only follows beta, so it should not see an alpha ap_id
- let deltaPost = (await resolvePost(delta, postRes.post_view.post)).post;
- expect(deltaPost).toBeUndefined();
+ await expect(resolvePost(delta, postRes.post_view.post)).rejects.toBe(
+ "couldnt_find_object",
+ );
// Epsilon has alpha blocked, it should not see the alpha post
- let epsilonPost = (await resolvePost(epsilon, postRes.post_view.post)).post;
- expect(epsilonPost).toBeUndefined();
+ await expect(resolvePost(epsilon, postRes.post_view.post)).rejects.toBe(
+ "couldnt_find_object",
+ );
});
test("Create a post in a non-existent community", async () => {
- let postRes = (await createPost(alpha, -2)) as any;
- expect(postRes.error).toBe("couldnt_find_community");
+ await expect(createPost(alpha, -2)).rejects.toBe("couldnt_find_community");
});
test("Unlike a post", async () => {
assertPostFederation(betaPost, updatedPost.post_view);
// Make sure lemmy beta cannot update the post
- let updatedPostBeta = (await editPost(beta, betaPost.post)) as any;
- expect(updatedPostBeta.error).toBe("no_post_edit_allowed");
+ await expect(editPost(beta, betaPost.post)).rejects.toBe(
+ "no_post_edit_allowed",
+ );
});
test("Sticky a post", async () => {
expect(alphaPost1.post.locked).toBe(true);
// Try to make a new comment there, on alpha
- let comment: any = await createComment(alpha, alphaPost1.post.id);
- expect(comment["error"]).toBe("locked");
+ await expect(createComment(alpha, alphaPost1.post.id)).rejects.toBe("locked");
// Unlock a post
let unlockedPost = await lockPost(beta, false, betaPost1.post);
expect(deletedPost.post_view.post.name).toBe(postRes.post_view.post.name);
// Make sure lemmy beta sees post is deleted
- let betaPost = (await resolvePost(beta, postRes.post_view.post)).post;
// This will be undefined because of the tombstone
- expect(betaPost).toBeUndefined();
+ await expect(resolvePost(beta, postRes.post_view.post)).rejects.toBe(
+ "couldnt_find_object",
+ );
// Undelete
let undeletedPost = await deletePost(alpha, false, postRes.post_view.post);
assertPostFederation(betaPost2, undeletedPost.post_view);
// Make sure lemmy beta cannot delete the post
- let deletedPostBeta = (await deletePost(beta, true, betaPost2.post)) as any;
- expect(deletedPostBeta.error).toStrictEqual("no_post_edit_allowed");
+ await expect(deletePost(beta, true, betaPost2.post)).rejects.toBe(
+ "no_post_edit_allowed",
+ );
});
test("Remove a post from admin and community on different instance", async () => {
expect(banAlpha.banned).toBe(true);
// ensure that the post by alpha got removed
- let searchAlpha1 = await getPost(alpha, searchBeta1.posts[0].post.id);
- expect(searchAlpha1.post_view.post.removed).toBe(true);
+ await expect(getPost(alpha, searchBeta1.posts[0].post.id)).rejects.toBe(
+ "unknown",
+ );
// Alpha tries to make post on beta, but it fails because of ban
- let postRes2 = await createPost(alpha, betaCommunity.community.id);
- expect(postRes2.post_view).toBeUndefined();
+ await expect(createPost(alpha, betaCommunity.community.id)).rejects.toBe(
+ "banned_from_community",
+ );
// Unban alpha
let unBanAlpha = await banPersonFromCommunity(
await deleteUser(user);
- expect((await resolvePost(alpha, localPost)).post).toBeUndefined();
- expect((await resolveComment(alpha, localComment)).comment).toBeUndefined();
- expect((await resolvePost(alpha, remotePost)).post).toBeUndefined();
- expect((await resolveComment(alpha, remoteComment)).comment).toBeUndefined();
+ await expect(resolvePost(alpha, localPost)).rejects.toBe(
+ "couldnt_find_object",
+ );
+ await expect(resolveComment(alpha, localComment)).rejects.toBe(
+ "couldnt_find_object",
+ );
+ await expect(resolvePost(alpha, remotePost)).rejects.toBe(
+ "couldnt_find_object",
+ );
+ await expect(resolveComment(alpha, remoteComment)).rejects.toBe(
+ "couldnt_find_object",
+ );
});
test("Requests with invalid auth should be treated as unauthenticated", async () => {