mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-26 11:21:02 +00:00
Fix federation test errors with new lemmy-js-client (#3678)
This commit is contained in:
parent
417c4d2311
commit
e17f0097ff
7 changed files with 52 additions and 39 deletions
|
@ -19,7 +19,7 @@
|
||||||
"eslint": "^8.40.0",
|
"eslint": "^8.40.0",
|
||||||
"eslint-plugin-prettier": "^4.0.0",
|
"eslint-plugin-prettier": "^4.0.0",
|
||||||
"jest": "^29.5.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",
|
"prettier": "^3.0.0",
|
||||||
"ts-jest": "^29.1.0",
|
"ts-jest": "^29.1.0",
|
||||||
"typescript": "^5.0.4"
|
"typescript": "^5.0.4"
|
||||||
|
|
|
@ -83,8 +83,7 @@ test("Create a comment", async () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
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)) as any;
|
await expect(createComment(alpha, -1)).rejects.toBe("couldnt_find_post");
|
||||||
expect(commentRes.error).toBe("couldnt_find_post");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("Update a comment", async () => {
|
test("Update a comment", async () => {
|
||||||
|
@ -123,11 +122,9 @@ test("Delete a comment", async () => {
|
||||||
expect(deleteCommentRes.comment_view.comment.deleted).toBe(true);
|
expect(deleteCommentRes.comment_view.comment.deleted).toBe(true);
|
||||||
|
|
||||||
// Make sure that comment is undefined on beta
|
// Make sure that comment is undefined on beta
|
||||||
let betaCommentRes = (await resolveComment(
|
await expect(
|
||||||
beta,
|
resolveComment(beta, commentRes.comment_view.comment),
|
||||||
commentRes.comment_view.comment,
|
).rejects.toBe("couldnt_find_object");
|
||||||
)) as any;
|
|
||||||
expect(betaCommentRes.error).toBe("couldnt_find_object");
|
|
||||||
|
|
||||||
let undeleteCommentRes = await deleteComment(
|
let undeleteCommentRes = await deleteComment(
|
||||||
alpha,
|
alpha,
|
||||||
|
@ -165,7 +162,6 @@ test("Remove a comment from admin and community on the same instance", async ()
|
||||||
alpha,
|
alpha,
|
||||||
commentRes.comment_view.comment.creator_id,
|
commentRes.comment_view.comment.creator_id,
|
||||||
);
|
);
|
||||||
console.log(refetchedPostComments.comments[0].comment);
|
|
||||||
expect(refetchedPostComments.comments[0].comment.removed).toBe(true);
|
expect(refetchedPostComments.comments[0].comment.removed).toBe(true);
|
||||||
|
|
||||||
let unremoveCommentRes = await removeComment(beta, false, betaCommentId);
|
let unremoveCommentRes = await removeComment(beta, false, betaCommentId);
|
||||||
|
|
|
@ -52,8 +52,9 @@ test("Create community", async () => {
|
||||||
|
|
||||||
// A dupe check
|
// A dupe check
|
||||||
let prevName = communityRes.community_view.community.name;
|
let prevName = communityRes.community_view.community.name;
|
||||||
let communityRes2: any = await createCommunity(alpha, prevName);
|
await expect(createCommunity(alpha, prevName)).rejects.toBe(
|
||||||
expect(communityRes2["error"]).toBe("community_already_exists");
|
"community_already_exists",
|
||||||
|
);
|
||||||
|
|
||||||
// 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`;
|
||||||
|
|
|
@ -88,17 +88,18 @@ test("Create a post", async () => {
|
||||||
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;
|
await expect(resolvePost(delta, postRes.post_view.post)).rejects.toBe(
|
||||||
expect(deltaPost).toBeUndefined();
|
"couldnt_find_object",
|
||||||
|
);
|
||||||
|
|
||||||
// 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;
|
await expect(resolvePost(epsilon, postRes.post_view.post)).rejects.toBe(
|
||||||
expect(epsilonPost).toBeUndefined();
|
"couldnt_find_object",
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("Create a post in a non-existent community", async () => {
|
test("Create a post in a non-existent community", async () => {
|
||||||
let postRes = (await createPost(alpha, -2)) as any;
|
await expect(createPost(alpha, -2)).rejects.toBe("couldnt_find_community");
|
||||||
expect(postRes.error).toBe("couldnt_find_community");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("Unlike a post", async () => {
|
test("Unlike a post", async () => {
|
||||||
|
@ -145,8 +146,9 @@ test("Update a post", async () => {
|
||||||
assertPostFederation(betaPost, updatedPost.post_view);
|
assertPostFederation(betaPost, updatedPost.post_view);
|
||||||
|
|
||||||
// Make sure lemmy beta cannot update the post
|
// Make sure lemmy beta cannot update the post
|
||||||
let updatedPostBeta = (await editPost(beta, betaPost.post)) as any;
|
await expect(editPost(beta, betaPost.post)).rejects.toBe(
|
||||||
expect(updatedPostBeta.error).toBe("no_post_edit_allowed");
|
"no_post_edit_allowed",
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("Sticky a post", async () => {
|
test("Sticky a post", async () => {
|
||||||
|
@ -210,8 +212,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);
|
await expect(createComment(alpha, alphaPost1.post.id)).rejects.toBe("locked");
|
||||||
expect(comment["error"]).toBe("locked");
|
|
||||||
|
|
||||||
// Unlock a post
|
// Unlock a post
|
||||||
let unlockedPost = await lockPost(beta, false, betaPost1.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);
|
expect(deletedPost.post_view.post.name).toBe(postRes.post_view.post.name);
|
||||||
|
|
||||||
// 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;
|
|
||||||
// This will be undefined because of the tombstone
|
// 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
|
// Undelete
|
||||||
let undeletedPost = await deletePost(alpha, false, postRes.post_view.post);
|
let undeletedPost = await deletePost(alpha, false, postRes.post_view.post);
|
||||||
|
@ -259,8 +261,9 @@ test("Delete a post", async () => {
|
||||||
assertPostFederation(betaPost2, undeletedPost.post_view);
|
assertPostFederation(betaPost2, undeletedPost.post_view);
|
||||||
|
|
||||||
// Make sure lemmy beta cannot delete the post
|
// Make sure lemmy beta cannot delete the post
|
||||||
let deletedPostBeta = (await deletePost(beta, true, betaPost2.post)) as any;
|
await expect(deletePost(beta, true, betaPost2.post)).rejects.toBe(
|
||||||
expect(deletedPostBeta.error).toStrictEqual("no_post_edit_allowed");
|
"no_post_edit_allowed",
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("Remove a post from admin and community on different instance", async () => {
|
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);
|
expect(banAlpha.banned).toBe(true);
|
||||||
|
|
||||||
// ensure that the post by alpha got removed
|
// ensure that the post by alpha got removed
|
||||||
let searchAlpha1 = await getPost(alpha, searchBeta1.posts[0].post.id);
|
await expect(getPost(alpha, searchBeta1.posts[0].post.id)).rejects.toBe(
|
||||||
expect(searchAlpha1.post_view.post.removed).toBe(true);
|
"unknown",
|
||||||
|
);
|
||||||
|
|
||||||
// Alpha tries to make post on beta, but it fails because of ban
|
// Alpha tries to make post on beta, but it fails because of ban
|
||||||
let postRes2 = await createPost(alpha, betaCommunity.community.id);
|
await expect(createPost(alpha, betaCommunity.community.id)).rejects.toBe(
|
||||||
expect(postRes2.post_view).toBeUndefined();
|
"banned_from_community",
|
||||||
|
);
|
||||||
|
|
||||||
// Unban alpha
|
// Unban alpha
|
||||||
let unBanAlpha = await banPersonFromCommunity(
|
let unBanAlpha = await banPersonFromCommunity(
|
||||||
|
|
|
@ -188,8 +188,11 @@ export async function setupLogins() {
|
||||||
await epsilon.client.editSite(editSiteForm);
|
await epsilon.client.editSite(editSiteForm);
|
||||||
|
|
||||||
// Create the main alpha/beta communities
|
// Create the main alpha/beta communities
|
||||||
|
// Ignore thrown errors of duplicates
|
||||||
|
try {
|
||||||
await createCommunity(alpha, "main");
|
await createCommunity(alpha, "main");
|
||||||
await createCommunity(beta, "main");
|
await createCommunity(beta, "main");
|
||||||
|
} catch (_) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function createPost(
|
export async function createPost(
|
||||||
|
|
|
@ -92,10 +92,18 @@ test("Delete user", async () => {
|
||||||
|
|
||||||
await deleteUser(user);
|
await deleteUser(user);
|
||||||
|
|
||||||
expect((await resolvePost(alpha, localPost)).post).toBeUndefined();
|
await expect(resolvePost(alpha, localPost)).rejects.toBe(
|
||||||
expect((await resolveComment(alpha, localComment)).comment).toBeUndefined();
|
"couldnt_find_object",
|
||||||
expect((await resolvePost(alpha, remotePost)).post).toBeUndefined();
|
);
|
||||||
expect((await resolveComment(alpha, remoteComment)).comment).toBeUndefined();
|
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 () => {
|
test("Requests with invalid auth should be treated as unauthenticated", async () => {
|
||||||
|
|
|
@ -2157,10 +2157,10 @@ 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.2-rc.13:
|
lemmy-js-client@0.18.3-rc.3:
|
||||||
version "0.17.2-rc.13"
|
version "0.18.3-rc.3"
|
||||||
resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.17.2-rc.13.tgz#f2a61050c1308e85cb39c0e1f561e392e84e3921"
|
resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.18.3-rc.3.tgz#fc6489eb141bd09558bca38d9e46b40771a29f37"
|
||||||
integrity sha512-4IyR1pisCumJ9L8fEPISC+Su1kVTI4pL/gWLsuOXxZC/lK36mG2+NfaNPiUmIklpCF5TUN+1F7E9bEvtTGogww==
|
integrity sha512-njixgXk4uMU4gGifnljwhSe9Kf445C4wAXcXhtpTtwPPLXpHQgxA1RASMb9Uq4zblfE6nC2JbrAka8y8N2N/Bw==
|
||||||
dependencies:
|
dependencies:
|
||||||
cross-fetch "^3.1.5"
|
cross-fetch "^3.1.5"
|
||||||
form-data "^4.0.0"
|
form-data "^4.0.0"
|
||||||
|
|
Loading…
Reference in a new issue