From e17f0097ff593be704269da70a7853caef5d26ea Mon Sep 17 00:00:00 2001 From: Dessalines Date: Fri, 21 Jul 2023 05:47:56 -0400 Subject: [PATCH] Fix federation test errors with new lemmy-js-client (#3678) --- api_tests/package.json | 2 +- api_tests/src/comment.spec.ts | 12 ++++------ api_tests/src/community.spec.ts | 5 ++-- api_tests/src/post.spec.ts | 41 ++++++++++++++++++--------------- api_tests/src/shared.ts | 7 ++++-- api_tests/src/user.spec.ts | 16 +++++++++---- api_tests/yarn.lock | 8 +++---- 7 files changed, 52 insertions(+), 39 deletions(-) diff --git a/api_tests/package.json b/api_tests/package.json index d81ef235d..ec692e1b5 100644 --- a/api_tests/package.json +++ b/api_tests/package.json @@ -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" diff --git a/api_tests/src/comment.spec.ts b/api_tests/src/comment.spec.ts index d1b20d77e..932c7ffeb 100644 --- a/api_tests/src/comment.spec.ts +++ b/api_tests/src/comment.spec.ts @@ -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); diff --git a/api_tests/src/community.spec.ts b/api_tests/src/community.spec.ts index d9a76cf87..a5a202ace 100644 --- a/api_tests/src/community.spec.ts +++ b/api_tests/src/community.spec.ts @@ -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`; diff --git a/api_tests/src/post.spec.ts b/api_tests/src/post.spec.ts index 8c48dc874..8ea3ea912 100644 --- a/api_tests/src/post.spec.ts +++ b/api_tests/src/post.spec.ts @@ -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( diff --git a/api_tests/src/shared.ts b/api_tests/src/shared.ts index 251f3ed96..bbd4eaaeb 100644 --- a/api_tests/src/shared.ts +++ b/api_tests/src/shared.ts @@ -188,8 +188,11 @@ export async function setupLogins() { await epsilon.client.editSite(editSiteForm); // Create the main alpha/beta communities - await createCommunity(alpha, "main"); - await createCommunity(beta, "main"); + // Ignore thrown errors of duplicates + try { + await createCommunity(alpha, "main"); + await createCommunity(beta, "main"); + } catch (_) {} } export async function createPost( diff --git a/api_tests/src/user.spec.ts b/api_tests/src/user.spec.ts index afe21d1a0..f488ebe1e 100644 --- a/api_tests/src/user.spec.ts +++ b/api_tests/src/user.spec.ts @@ -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 () => { diff --git a/api_tests/yarn.lock b/api_tests/yarn.lock index a404dc52d..30f13014b 100644 --- a/api_tests/yarn.lock +++ b/api_tests/yarn.lock @@ -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"