Fix federation test errors with new lemmy-js-client (#3678)

This commit is contained in:
Dessalines 2023-07-21 05:47:56 -04:00 committed by GitHub
parent 417c4d2311
commit e17f0097ff
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 52 additions and 39 deletions

View file

@ -19,7 +19,7 @@
"eslint": "^8.40.0",
"eslint-plugin-prettier": "^4.0.0",
"jest": "^29.5.0",
"lemmy-js-client": "0.17.2-rc.13",
"lemmy-js-client": "0.18.3-rc.3",
"prettier": "^3.0.0",
"ts-jest": "^29.1.0",
"typescript": "^5.0.4"

View file

@ -83,8 +83,7 @@ test("Create a comment", async () => {
});
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 () => {
@ -123,11 +122,9 @@ test("Delete 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,
@ -165,7 +162,6 @@ test("Remove a comment from admin and community on the same instance", async ()
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);

View file

@ -52,8 +52,9 @@ test("Create community", async () => {
// A dupe check
let prevName = communityRes.community_view.community.name;
let communityRes2: any = await createCommunity(alpha, prevName);
expect(communityRes2["error"]).toBe("community_already_exists");
await expect(createCommunity(alpha, prevName)).rejects.toBe(
"community_already_exists",
);
// Cache the community on beta, make sure it has the other fields
let searchShort = `!${prevName}@lemmy-alpha:8541`;

View file

@ -88,17 +88,18 @@ test("Create a post", async () => {
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 () => {
@ -145,8 +146,9 @@ test("Update 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 () => {
@ -210,8 +212,7 @@ test("Lock 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);
@ -242,9 +243,10 @@ test("Delete a post", async () => {
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);
@ -259,8 +261,9 @@ test("Delete a post", async () => {
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 () => {
@ -436,12 +439,14 @@ test("Enforce community ban for federated user", 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(

View file

@ -188,8 +188,11 @@ export async function setupLogins() {
await epsilon.client.editSite(editSiteForm);
// Create the main alpha/beta communities
// Ignore thrown errors of duplicates
try {
await createCommunity(alpha, "main");
await createCommunity(beta, "main");
} catch (_) {}
}
export async function createPost(

View file

@ -92,10 +92,18 @@ test("Delete user", async () => {
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 () => {

View file

@ -2157,10 +2157,10 @@ kleur@^3.0.3:
resolved "https://registry.yarnpkg.com/kleur/-/kleur-3.0.3.tgz#a79c9ecc86ee1ce3fa6206d1216c501f147fc07e"
integrity sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w==
lemmy-js-client@0.17.2-rc.13:
version "0.17.2-rc.13"
resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.17.2-rc.13.tgz#f2a61050c1308e85cb39c0e1f561e392e84e3921"
integrity sha512-4IyR1pisCumJ9L8fEPISC+Su1kVTI4pL/gWLsuOXxZC/lK36mG2+NfaNPiUmIklpCF5TUN+1F7E9bEvtTGogww==
lemmy-js-client@0.18.3-rc.3:
version "0.18.3-rc.3"
resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.18.3-rc.3.tgz#fc6489eb141bd09558bca38d9e46b40771a29f37"
integrity sha512-njixgXk4uMU4gGifnljwhSe9Kf445C4wAXcXhtpTtwPPLXpHQgxA1RASMb9Uq4zblfE6nC2JbrAka8y8N2N/Bw==
dependencies:
cross-fetch "^3.1.5"
form-data "^4.0.0"