From 179709cc0942d36c78f53572c8a167b9c4fa05b3 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Thu, 17 Dec 2020 14:01:33 -0500 Subject: [PATCH] Fixing drone tests. --- api_tests/run-federation-test.sh | 2 +- api_tests/src/comment.spec.ts | 35 ---------- api_tests/src/community.spec.ts | 17 ----- api_tests/src/follow.spec.ts | 5 -- api_tests/src/post.spec.ts | 96 ++++++--------------------- api_tests/src/private_message.spec.ts | 9 --- api_tests/src/shared.ts | 4 +- api_tests/src/user.spec.ts | 23 ++----- lemmy_utils/src/utils.rs | 5 +- 9 files changed, 29 insertions(+), 167 deletions(-) diff --git a/api_tests/run-federation-test.sh b/api_tests/run-federation-test.sh index 2c707e7e9..d624f9c25 100755 --- a/api_tests/run-federation-test.sh +++ b/api_tests/run-federation-test.sh @@ -17,4 +17,4 @@ killall lemmy_server for INSTANCE in lemmy_alpha lemmy_beta lemmy_gamma lemmy_delta lemmy_epsilon; do psql "$LEMMY_DATABASE_URL" -c "DROP DATABASE $INSTANCE" -done \ No newline at end of file +done diff --git a/api_tests/src/comment.spec.ts b/api_tests/src/comment.spec.ts index 2ee3045c7..693bdaf21 100644 --- a/api_tests/src/comment.spec.ts +++ b/api_tests/src/comment.spec.ts @@ -20,8 +20,6 @@ import { createCommunity, registerUser, API, - delay, - longDelay, } from './shared'; import { Comment, @@ -36,7 +34,6 @@ beforeAll(async () => { await followBeta(alpha); await followBeta(gamma); let search = await searchForBetaCommunity(alpha); - await longDelay(); postRes = await createPost( alpha, search.communities.filter(c => c.local == false)[0].id @@ -67,7 +64,6 @@ test('Create a comment', async () => { expect(commentRes.comment.community_local).toBe(false); expect(commentRes.comment.creator_local).toBe(true); expect(commentRes.comment.score).toBe(1); - await longDelay(); // Make sure that comment is liked on beta let searchBeta = await searchComment(beta, commentRes.comment); @@ -90,14 +86,12 @@ test('Update a comment', async () => { let searchBeta = await searchComment(beta, commentRes.comment); assertCommentFederation(searchBeta.comments[0], commentRes.comment); - await delay(); let updateCommentRes = await updateComment(alpha, commentRes.comment.id); expect(updateCommentRes.comment.content).toBe( 'A jest test federated comment update' ); expect(updateCommentRes.comment.community_local).toBe(false); expect(updateCommentRes.comment.creator_local).toBe(true); - await delay(); // Make sure that post is updated on beta let searchBetaUpdated = await searchComment(beta, commentRes.comment); @@ -106,7 +100,6 @@ test('Update a comment', async () => { test('Delete a comment', async () => { let commentRes = await createComment(alpha, postRes.post.id); - await delay(); let deleteCommentRes = await deleteComment( alpha, @@ -114,13 +107,11 @@ test('Delete a comment', async () => { commentRes.comment.id ); expect(deleteCommentRes.comment.deleted).toBe(true); - await delay(); // Make sure that comment is undefined on beta let searchBeta = await searchComment(beta, commentRes.comment); let betaComment = searchBeta.comments[0]; expect(betaComment).toBeUndefined(); - await delay(); let undeleteCommentRes = await deleteComment( alpha, @@ -128,7 +119,6 @@ test('Delete a comment', async () => { commentRes.comment.id ); expect(undeleteCommentRes.comment.deleted).toBe(false); - await delay(); // Make sure that comment is undeleted on beta let searchBeta2 = await searchComment(beta, commentRes.comment); @@ -139,7 +129,6 @@ test('Delete a comment', async () => { test('Remove a comment from admin and community on the same instance', async () => { let commentRes = await createComment(alpha, postRes.post.id); - await delay(); // Get the id for beta let betaCommentId = (await searchComment(beta, commentRes.comment)) @@ -148,7 +137,6 @@ test('Remove a comment from admin and community on the same instance', async () // The beta admin removes it (the community lives on beta) let removeCommentRes = await removeComment(beta, true, betaCommentId); expect(removeCommentRes.comment.removed).toBe(true); - await longDelay(); // Make sure that comment is removed on alpha (it gets pushed since an admin from beta removed it) let refetchedPost = await getPost(alpha, postRes.post.id); @@ -156,7 +144,6 @@ test('Remove a comment from admin and community on the same instance', async () let unremoveCommentRes = await removeComment(beta, false, betaCommentId); expect(unremoveCommentRes.comment.removed).toBe(false); - await longDelay(); // Make sure that comment is unremoved on beta let refetchedPost2 = await getPost(alpha, postRes.post.id); @@ -173,19 +160,15 @@ test('Remove a comment from admin and community on different instance', async () // New alpha user creates a community, post, and comment. let newCommunity = await createCommunity(newAlphaApi); - await delay(); let newPost = await createPost(newAlphaApi, newCommunity.community.id); - await delay(); let commentRes = await createComment(newAlphaApi, newPost.post.id); expect(commentRes.comment.content).toBeDefined(); - await delay(); // Beta searches that to cache it, then removes it let searchBeta = await searchComment(beta, commentRes.comment); let betaComment = searchBeta.comments[0]; let removeCommentRes = await removeComment(beta, true, betaComment.id); expect(removeCommentRes.comment.removed).toBe(true); - await delay(); // Make sure its not removed on alpha let refetchedPost = await getPost(newAlphaApi, newPost.post.id); @@ -195,10 +178,8 @@ test('Remove a comment from admin and community on different instance', async () test('Unlike a comment', async () => { let commentRes = await createComment(alpha, postRes.post.id); - await delay(); let unlike = await likeComment(alpha, 0, commentRes.comment); expect(unlike.comment.score).toBe(0); - await delay(); // Make sure that post is unliked on beta let searchBeta = await searchComment(beta, commentRes.comment); @@ -211,7 +192,6 @@ test('Unlike a comment', async () => { test('Federated comment like', async () => { let commentRes = await createComment(alpha, postRes.post.id); - await longDelay(); // Find the comment on beta let searchBeta = await searchComment(beta, commentRes.comment); @@ -219,7 +199,6 @@ test('Federated comment like', async () => { let like = await likeComment(beta, 1, betaComment); expect(like.comment.score).toBe(2); - await longDelay(); // Get the post from alpha, check the likes let post = await getPost(alpha, postRes.post.id); @@ -229,7 +208,6 @@ test('Federated comment like', async () => { test('Reply to a comment', async () => { // Create a comment on alpha, find it on beta let commentRes = await createComment(alpha, postRes.post.id); - await delay(); let searchBeta = await searchComment(beta, commentRes.comment); let betaComment = searchBeta.comments[0]; @@ -242,7 +220,6 @@ test('Reply to a comment', async () => { expect(replyRes.comment.creator_local).toBe(true); expect(replyRes.comment.parent_id).toBe(betaComment.id); expect(replyRes.comment.score).toBe(1); - await longDelay(); // Make sure that comment is seen on alpha // TODO not sure why, but a searchComment back to alpha, for the ap_id of betas @@ -262,7 +239,6 @@ test('Mention beta', async () => { // Create a mention on alpha let mentionContent = 'A test mention of @lemmy_beta@lemmy-beta:8551'; let commentRes = await createComment(alpha, postRes.post.id); - await delay(); let mentionRes = await createComment( alpha, postRes.post.id, @@ -273,7 +249,6 @@ test('Mention beta', async () => { expect(mentionRes.comment.community_local).toBe(false); expect(mentionRes.comment.creator_local).toBe(true); expect(mentionRes.comment.score).toBe(1); - await delay(); let mentionsRes = await getMentions(beta); expect(mentionsRes.mentions[0].content).toBeDefined(); @@ -284,7 +259,6 @@ test('Mention beta', async () => { test('Comment Search', async () => { let commentRes = await createComment(alpha, postRes.post.id); - await delay(); let searchBeta = await searchComment(beta, commentRes.comment); assertCommentFederation(searchBeta.comments[0], commentRes.comment); }); @@ -293,7 +267,6 @@ test('A and G subscribe to B (center) A posts, G mentions B, it gets announced t // Create a local post let alphaPost = await createPost(alpha, 2); expect(alphaPost.post.community_local).toBe(true); - await delay(); // Make sure gamma sees it let search = await searchPost(gamma, alphaPost.post); @@ -311,7 +284,6 @@ test('A and G subscribe to B (center) A posts, G mentions B, it gets announced t expect(commentRes.comment.community_local).toBe(false); expect(commentRes.comment.creator_local).toBe(true); expect(commentRes.comment.score).toBe(1); - await longDelay(); // Make sure alpha sees it let alphaPost2 = await getPost(alpha, alphaPost.post.id); @@ -320,7 +292,6 @@ test('A and G subscribe to B (center) A posts, G mentions B, it gets announced t expect(alphaPost2.comments[0].creator_local).toBe(false); expect(alphaPost2.comments[0].score).toBe(1); assertCommentFederation(alphaPost2.comments[0], commentRes.comment); - await delay(); // Make sure beta has mentions let mentionsRes = await getMentions(beta); @@ -341,7 +312,6 @@ test('Fetch in_reply_tos: A is unsubbed from B, B makes a post, and some embedde // B creates a post, and two comments, should be invisible to A let postRes = await createPost(beta, 2); expect(postRes.post.name).toBeDefined(); - await delay(); let parentCommentContent = 'An invisible top level comment from beta'; let parentCommentRes = await createComment( @@ -351,7 +321,6 @@ test('Fetch in_reply_tos: A is unsubbed from B, B makes a post, and some embedde parentCommentContent ); expect(parentCommentRes.comment.content).toBe(parentCommentContent); - await delay(); // B creates a comment, then a child one of that. let childCommentContent = 'An invisible child comment from beta'; @@ -362,13 +331,11 @@ test('Fetch in_reply_tos: A is unsubbed from B, B makes a post, and some embedde childCommentContent ); expect(childCommentRes.comment.content).toBe(childCommentContent); - await delay(); // Follow beta again let follow = await followBeta(alpha); expect(follow.community.local).toBe(false); expect(follow.community.name).toBe('main'); - await delay(); // An update to the child comment on beta, should push the post, parent, and child to alpha now let updatedCommentContent = 'An update child comment from beta'; @@ -378,12 +345,10 @@ test('Fetch in_reply_tos: A is unsubbed from B, B makes a post, and some embedde updatedCommentContent ); expect(updateRes.comment.content).toBe(updatedCommentContent); - await delay(); // Get the post from alpha let search = await searchPost(alpha, postRes.post); let alphaPostB = search.posts[0]; - await longDelay(); let alphaPost = await getPost(alpha, alphaPostB.id); expect(alphaPost.post.name).toBeDefined(); diff --git a/api_tests/src/community.spec.ts b/api_tests/src/community.spec.ts index 7c33f82fd..906900644 100644 --- a/api_tests/src/community.spec.ts +++ b/api_tests/src/community.spec.ts @@ -3,15 +3,12 @@ import { alpha, beta, setupLogins, - searchForBetaCommunity, searchForCommunity, createCommunity, deleteCommunity, removeCommunity, getCommunity, followCommunity, - delay, - longDelay, } from './shared'; import { Community, @@ -46,7 +43,6 @@ test('Create community', async () => { let prevName = communityRes.community.name; let communityRes2 = await createCommunity(alpha, prevName); expect(communityRes2['error']).toBe('community_already_exists'); - await delay(); // Cache the community on beta, make sure it has the other fields let searchShort = `!${prevName}@lemmy-alpha:8541`; @@ -57,21 +53,18 @@ test('Create community', async () => { test('Delete community', async () => { let communityRes = await createCommunity(beta); - await delay(); // Cache the community on Alpha let searchShort = `!${communityRes.community.name}@lemmy-beta:8551`; let search = await searchForCommunity(alpha, searchShort); let communityOnAlpha = search.communities[0]; assertCommunityFederation(communityOnAlpha, communityRes.community); - await delay(); // Follow the community from alpha let follow = await followCommunity(alpha, true, communityOnAlpha.id); // Make sure the follow response went through expect(follow.community.local).toBe(false); - await delay(); let deleteCommunityRes = await deleteCommunity( beta, @@ -79,12 +72,10 @@ test('Delete community', async () => { communityRes.community.id ); expect(deleteCommunityRes.community.deleted).toBe(true); - await delay(); // Make sure it got deleted on A let communityOnAlphaDeleted = await getCommunity(alpha, communityOnAlpha.id); expect(communityOnAlphaDeleted.community.deleted).toBe(true); - await delay(); // Undelete let undeleteCommunityRes = await deleteCommunity( @@ -93,7 +84,6 @@ test('Delete community', async () => { communityRes.community.id ); expect(undeleteCommunityRes.community.deleted).toBe(false); - await delay(); // Make sure it got undeleted on A let communityOnAlphaUnDeleted = await getCommunity(alpha, communityOnAlpha.id); @@ -102,21 +92,18 @@ test('Delete community', async () => { test('Remove community', async () => { let communityRes = await createCommunity(beta); - await delay(); // Cache the community on Alpha let searchShort = `!${communityRes.community.name}@lemmy-beta:8551`; let search = await searchForCommunity(alpha, searchShort); let communityOnAlpha = search.communities[0]; assertCommunityFederation(communityOnAlpha, communityRes.community); - await delay(); // Follow the community from alpha let follow = await followCommunity(alpha, true, communityOnAlpha.id); // Make sure the follow response went through expect(follow.community.local).toBe(false); - await delay(); let removeCommunityRes = await removeCommunity( beta, @@ -124,12 +111,10 @@ test('Remove community', async () => { communityRes.community.id ); expect(removeCommunityRes.community.removed).toBe(true); - await delay(); // Make sure it got Removed on A let communityOnAlphaRemoved = await getCommunity(alpha, communityOnAlpha.id); expect(communityOnAlphaRemoved.community.removed).toBe(true); - await delay(); // unremove let unremoveCommunityRes = await removeCommunity( @@ -138,7 +123,6 @@ test('Remove community', async () => { communityRes.community.id ); expect(unremoveCommunityRes.community.removed).toBe(false); - await delay(); // Make sure it got undeleted on A let communityOnAlphaUnRemoved = await getCommunity(alpha, communityOnAlpha.id); @@ -148,7 +132,6 @@ test('Remove community', async () => { test('Search for beta community', async () => { let communityRes = await createCommunity(beta); expect(communityRes.community.name).toBeDefined(); - await delay(); let searchShort = `!${communityRes.community.name}@lemmy-beta:8551`; let search = await searchForCommunity(alpha, searchShort); diff --git a/api_tests/src/follow.spec.ts b/api_tests/src/follow.spec.ts index e0389f871..651c526a2 100644 --- a/api_tests/src/follow.spec.ts +++ b/api_tests/src/follow.spec.ts @@ -6,8 +6,6 @@ import { followCommunity, checkFollowedCommunities, unfollowRemotes, - delay, - longDelay, } from './shared'; beforeAll(async () => { @@ -25,11 +23,9 @@ test('Follow federated community', async () => { // Make sure the follow response went through expect(follow.community.local).toBe(false); expect(follow.community.name).toBe('main'); - await longDelay(); // Check it from local let followCheck = await checkFollowedCommunities(alpha); - await delay(); let remoteCommunityId = followCheck.communities.filter( c => c.community_local == false )[0].community_id; @@ -38,7 +34,6 @@ test('Follow federated community', async () => { // Test an unfollow let unfollow = await followCommunity(alpha, false, remoteCommunityId); expect(unfollow.community.local).toBe(false); - await delay(); // Make sure you are unsubbed locally let unfollowCheck = await checkFollowedCommunities(alpha); diff --git a/api_tests/src/post.spec.ts b/api_tests/src/post.spec.ts index c68fe2d24..e35880f4c 100644 --- a/api_tests/src/post.spec.ts +++ b/api_tests/src/post.spec.ts @@ -19,8 +19,6 @@ import { removePost, getPost, unfollowRemotes, - delay, - longDelay, searchForUser, banUserFromSite, searchPostLocal, @@ -28,15 +26,15 @@ import { } from './shared'; import { Post, + Community, } from 'lemmy-js-client'; +let betaCommunity: Community; + beforeAll(async () => { await setupLogins(); - await followBeta(alpha); - await followBeta(gamma); - await followBeta(delta); - await followBeta(epsilon); - await longDelay(); + let search = await searchForBetaCommunity(alpha); + betaCommunity = search.communities[0]; }); afterAll(async () => { @@ -65,14 +63,11 @@ function assertPostFederation( } test('Create a post', async () => { - let search = await searchForBetaCommunity(alpha); - await delay(); - let postRes = await createPost(alpha, search.communities[0].id); + let postRes = await createPost(alpha, betaCommunity.id); expect(postRes.post).toBeDefined(); expect(postRes.post.community_local).toBe(false); expect(postRes.post.creator_local).toBe(true); expect(postRes.post.score).toBe(1); - await delay(); // Make sure that post is liked on beta let searchBeta = await searchPost(beta, postRes.post); @@ -99,9 +94,7 @@ test('Create a post in a non-existent community', async () => { }); test('Unlike a post', async () => { - let search = await searchForBetaCommunity(alpha); - await delay(); - let postRes = await createPost(alpha, search.communities[0].id); + let postRes = await createPost(alpha, betaCommunity.id); let unlike = await likePost(alpha, 0, postRes.post); expect(unlike.post.score).toBe(0); @@ -120,16 +113,13 @@ test('Unlike a post', async () => { }); test('Update a post', async () => { - let search = await searchForBetaCommunity(alpha); - let postRes = await createPost(alpha, search.communities[0].id); - await delay(); + let postRes = await createPost(alpha, betaCommunity.id); let updatedName = 'A jest test federated post, updated'; let updatedPost = await updatePost(alpha, postRes.post); expect(updatedPost.post.name).toBe(updatedName); expect(updatedPost.post.community_local).toBe(false); expect(updatedPost.post.creator_local).toBe(true); - await delay(); // Make sure that post is updated on beta let searchBeta = await searchPost(beta, postRes.post); @@ -138,7 +128,6 @@ test('Update a post', async () => { expect(betaPost.creator_local).toBe(false); expect(betaPost.name).toBe(updatedName); assertPostFederation(betaPost, updatedPost.post); - await delay(); // Make sure lemmy beta cannot update the post let updatedPostBeta = await updatePost(beta, betaPost); @@ -146,26 +135,20 @@ test('Update a post', async () => { }); test('Sticky a post', async () => { - let search = await searchForBetaCommunity(alpha); - let postRes = await createPost(alpha, search.communities[0].id); - await delay(); + let postRes = await createPost(alpha, betaCommunity.id); let stickiedPostRes = await stickyPost(alpha, true, postRes.post); expect(stickiedPostRes.post.stickied).toBe(true); - await delay(); - // Make sure that post is stickied on beta let searchBeta = await searchPost(beta, postRes.post); let betaPost = searchBeta.posts[0]; expect(betaPost.community_local).toBe(true); expect(betaPost.creator_local).toBe(false); expect(betaPost.stickied).toBe(true); - await delay(); // Unsticky a post let unstickiedPost = await stickyPost(alpha, false, postRes.post); expect(unstickiedPost.post.stickied).toBe(false); - await delay(); // Make sure that post is unstickied on beta let searchBeta2 = await searchPost(beta, postRes.post); @@ -173,14 +156,11 @@ test('Sticky a post', async () => { expect(betaPost2.community_local).toBe(true); expect(betaPost2.creator_local).toBe(false); expect(betaPost2.stickied).toBe(false); - await delay(); // Make sure that gamma cannot sticky the post on beta let searchGamma = await searchPost(gamma, postRes.post); let gammaPost = searchGamma.posts[0]; - await delay(); let gammaTrySticky = await stickyPost(gamma, true, gammaPost); - await delay(); let searchBeta3 = await searchPost(beta, postRes.post); let betaPost3 = searchBeta3.posts[0]; expect(gammaTrySticky.post.stickied).toBe(true); @@ -188,31 +168,24 @@ test('Sticky a post', async () => { }); test('Lock a post', async () => { - let search = await searchForBetaCommunity(alpha); - await delay(); - let postRes = await createPost(alpha, search.communities[0].id); - await delay(); + let postRes = await createPost(alpha, betaCommunity.id); // Lock the post let lockedPostRes = await lockPost(alpha, true, postRes.post); expect(lockedPostRes.post.locked).toBe(true); - await delay(); // Make sure that post is locked on beta let searchBeta = await searchPostLocal(beta, postRes.post); let betaPost1 = searchBeta.posts[0]; expect(betaPost1.locked).toBe(true); - await delay(); // Try to make a new comment there, on alpha let comment = await createComment(alpha, postRes.post.id); expect(comment['error']).toBe('locked'); - await delay(); // Unlock a post let unlockedPost = await lockPost(alpha, false, postRes.post); expect(unlockedPost.post.locked).toBe(false); - await delay(); // Make sure that post is unlocked on beta let searchBeta2 = await searchPost(beta, postRes.post); @@ -220,7 +193,6 @@ test('Lock a post', async () => { expect(betaPost2.community_local).toBe(true); expect(betaPost2.creator_local).toBe(false); expect(betaPost2.locked).toBe(false); - await delay(); // Try to create a new comment, on beta let commentBeta = await createComment(beta, betaPost2.id); @@ -228,9 +200,7 @@ test('Lock a post', async () => { }); test('Delete a post', async () => { - let search = await searchForBetaCommunity(alpha); - await delay(); - let postRes = await createPost(alpha, search.communities[0].id); + let postRes = await createPost(alpha, betaCommunity.id); let deletedPost = await deletePost(alpha, true, postRes.post); expect(deletedPost.post.deleted).toBe(true); @@ -257,25 +227,19 @@ test('Delete a post', async () => { }); test('Remove a post from admin and community on different instance', async () => { - let search = await searchForBetaCommunity(alpha); - await delay(); - let postRes = await createPost(alpha, search.communities[0].id); - await delay(); + let postRes = await createPost(alpha, betaCommunity.id); let removedPost = await removePost(alpha, true, postRes.post); expect(removedPost.post.removed).toBe(true); - await delay(); // Make sure lemmy beta sees post is NOT removed let searchBeta = await searchPost(beta, postRes.post); let betaPost = searchBeta.posts[0]; expect(betaPost.removed).toBe(false); - await delay(); // Undelete let undeletedPost = await removePost(alpha, false, postRes.post); expect(undeletedPost.post.removed).toBe(false); - await delay(); // Make sure lemmy beta sees post is undeleted let searchBeta2 = await searchPost(beta, postRes.post); @@ -285,52 +249,43 @@ test('Remove a post from admin and community on different instance', async () => }); test('Remove a post from admin and community on same instance', async () => { - let search = await searchForBetaCommunity(alpha); - await delay(); - let postRes = await createPost(alpha, search.communities[0].id); - await delay(); + let postRes = await createPost(alpha, betaCommunity.id); // Get the id for beta let searchBeta = await searchPost(beta, postRes.post); let betaPost = searchBeta.posts[0]; - await delay(); + + await followBeta(alpha); // The beta admin removes it (the community lives on beta) let removePostRes = await removePost(beta, true, betaPost); expect(removePostRes.post.removed).toBe(true); - await delay(); // Make sure lemmy alpha sees post is removed let alphaPost = await getPost(alpha, postRes.post.id); expect(alphaPost.post.removed).toBe(true); assertPostFederation(alphaPost.post, removePostRes.post); - await delay(); // Undelete let undeletedPost = await removePost(beta, false, betaPost); expect(undeletedPost.post.removed).toBe(false); - await delay(); // Make sure lemmy alpha sees post is undeleted let alphaPost2 = await getPost(alpha, postRes.post.id); expect(alphaPost2.post.removed).toBe(false); assertPostFederation(alphaPost2.post, undeletedPost.post); + await unfollowRemotes(alpha); }); test('Search for a post', async () => { - let search = await searchForBetaCommunity(alpha); - await delay(); - let postRes = await createPost(alpha, search.communities[0].id); - await delay(); + let postRes = await createPost(alpha, betaCommunity.id); let searchBeta = await searchPost(beta, postRes.post); expect(searchBeta.posts[0].name).toBeDefined(); }); test('A and G subscribe to B (center) A posts, it gets announced to G', async () => { - let search = await searchForBetaCommunity(alpha); - let postRes = await createPost(alpha, search.communities[0].id); - await delay(); + let postRes = await createPost(alpha, betaCommunity.id); let search2 = await searchPost(gamma, postRes.post); expect(search2.posts[0].name).toBeDefined(); @@ -342,28 +297,22 @@ test('Enforce site ban for federated user', async () => { let userSearch = await searchForUser(beta, alphaShortname); let alphaUser = userSearch.users[0]; expect(alphaUser).toBeDefined(); - await delay(); // ban alpha from beta site let banAlpha = await banUserFromSite(beta, alphaUser.id, true); expect(banAlpha.banned).toBe(true); - await delay(); // Alpha makes post on beta - let search = await searchForBetaCommunity(alpha); - await delay(); - let postRes = await createPost(alpha, search.communities[0].id); + let postRes = await createPost(alpha, betaCommunity.id); expect(postRes.post).toBeDefined(); expect(postRes.post.community_local).toBe(false); expect(postRes.post.creator_local).toBe(true); expect(postRes.post.score).toBe(1); - await delay(); // Make sure that post doesn't make it to beta let searchBeta = await searchPostLocal(beta, postRes.post); let betaPost = searchBeta.posts[0]; expect(betaPost).toBeUndefined(); - await delay(); // Unban alpha let unBanAlpha = await banUserFromSite(beta, alphaUser.id, false); @@ -375,23 +324,18 @@ test('Enforce community ban for federated user', async () => { let userSearch = await searchForUser(beta, alphaShortname); let alphaUser = userSearch.users[0]; expect(alphaUser).toBeDefined(); - await delay(); // ban alpha from beta site await banUserFromCommunity(beta, alphaUser.id, 2, false); let banAlpha = await banUserFromCommunity(beta, alphaUser.id, 2, true); expect(banAlpha.banned).toBe(true); - await delay(); // Alpha makes post on beta - let search = await searchForBetaCommunity(alpha); - await delay(); - let postRes = await createPost(alpha, search.communities[0].id); + let postRes = await createPost(alpha, betaCommunity.id); expect(postRes.post).toBeDefined(); expect(postRes.post.community_local).toBe(false); expect(postRes.post.creator_local).toBe(true); expect(postRes.post.score).toBe(1); - await delay(); // Make sure that post doesn't make it to beta community let searchBeta = await searchPostLocal(beta, postRes.post); diff --git a/api_tests/src/private_message.spec.ts b/api_tests/src/private_message.spec.ts index 3ae714880..4dc0e7059 100644 --- a/api_tests/src/private_message.spec.ts +++ b/api_tests/src/private_message.spec.ts @@ -9,8 +9,6 @@ import { listPrivateMessages, deletePrivateMessage, unfollowRemotes, - delay, - longDelay, } from './shared'; let recipient_id: number; @@ -18,7 +16,6 @@ let recipient_id: number; beforeAll(async () => { await setupLogins(); let follow = await followBeta(alpha); - await longDelay(); recipient_id = follow.community.creator_id; }); @@ -32,7 +29,6 @@ test('Create a private message', async () => { expect(pmRes.message.local).toBe(true); expect(pmRes.message.creator_local).toBe(true); expect(pmRes.message.recipient_local).toBe(false); - await delay(); let betaPms = await listPrivateMessages(beta); expect(betaPms.messages[0].content).toBeDefined(); @@ -47,7 +43,6 @@ test('Update a private message', async () => { let pmRes = await createPrivateMessage(alpha, recipient_id); let pmUpdated = await updatePrivateMessage(alpha, pmRes.message.id); expect(pmUpdated.message.content).toBe(updatedContent); - await longDelay(); let betaPms = await listPrivateMessages(beta); expect(betaPms.messages[0].content).toBe(updatedContent); @@ -55,18 +50,15 @@ test('Update a private message', async () => { test('Delete a private message', async () => { let pmRes = await createPrivateMessage(alpha, recipient_id); - await delay(); let betaPms1 = await listPrivateMessages(beta); let deletedPmRes = await deletePrivateMessage(alpha, true, pmRes.message.id); expect(deletedPmRes.message.deleted).toBe(true); - await delay(); // The GetPrivateMessages filters out deleted, // even though they are in the actual database. // no reason to show them let betaPms2 = await listPrivateMessages(beta); expect(betaPms2.messages.length).toBe(betaPms1.messages.length - 1); - await delay(); // Undelete let undeletedPmRes = await deletePrivateMessage( @@ -75,7 +67,6 @@ test('Delete a private message', async () => { pmRes.message.id ); expect(undeletedPmRes.message.deleted).toBe(false); - await longDelay(); let betaPms3 = await listPrivateMessages(beta); expect(betaPms3.messages.length).toBe(betaPms1.messages.length); diff --git a/api_tests/src/shared.ts b/api_tests/src/shared.ts index be6b53adf..cf1fb7c6d 100644 --- a/api_tests/src/shared.ts +++ b/api_tests/src/shared.ts @@ -602,8 +602,6 @@ export async function unfollowRemotes( } export async function followBeta(api: API): Promise { - await unfollowRemotes(api); - // Cache it let search = await searchForBetaCommunity(api); let com = search.communities.filter(c => c.local == false); @@ -615,7 +613,7 @@ export async function followBeta(api: API): Promise { export function delay(millis: number = 500) { return new Promise((resolve, _reject) => { - setTimeout(_ => resolve(), 10); + setTimeout(_ => resolve(), millis); }); } diff --git a/api_tests/src/user.spec.ts b/api_tests/src/user.spec.ts index bfd56fcbd..3a327c2a1 100644 --- a/api_tests/src/user.spec.ts +++ b/api_tests/src/user.spec.ts @@ -4,7 +4,6 @@ import { beta, registerUser, searchForUser, - saveUserSettingsBio, saveUserSettings, getSite, } from './shared'; @@ -38,23 +37,10 @@ test('Create user', async () => { apShortname = `@${site.my_user.name}@lemmy-alpha:8541`; }); -test('Save user settings, check changed bio from beta', async () => { - let bio = 'a changed bio'; - let userRes = await saveUserSettingsBio(alpha, auth); - expect(userRes.jwt).toBeDefined(); - - let site = await getSite(alpha, auth); - expect(site.my_user.bio).toBe(bio); - let searchAlpha = await searchForUser(alpha, site.my_user.actor_id); - - // Make sure beta sees this bio is changed - let searchBeta = await searchForUser(beta, apShortname); - assertUserFederation(searchAlpha.users[0], searchBeta.users[0]); -}); - -test('Set avatar and banner, check that they are federated', async () => { +test('Set some user settings, check that they are federated', async () => { let avatar = 'https://image.flaticon.com/icons/png/512/35/35896.png'; let banner = 'https://image.flaticon.com/icons/png/512/36/35896.png'; + let bio = 'a changed bio'; let form: UserSettingsForm = { show_nsfw: false, theme: "", @@ -66,11 +52,12 @@ test('Set avatar and banner, check that they are federated', async () => { preferred_username: "user321", show_avatars: false, send_notifications_to_email: false, + bio, auth, } - let settingsRes = await saveUserSettings(alpha, form); + await saveUserSettings(alpha, form); - let searchAlpha = await searchForUser(beta, apShortname); + let searchAlpha = await searchForUser(alpha, apShortname); let userOnAlpha = searchAlpha.users[0]; let searchBeta = await searchForUser(beta, apShortname); let userOnBeta = searchBeta.users[0]; diff --git a/lemmy_utils/src/utils.rs b/lemmy_utils/src/utils.rs index 87aad574a..2260cb65e 100644 --- a/lemmy_utils/src/utils.rs +++ b/lemmy_utils/src/utils.rs @@ -1,6 +1,6 @@ use crate::{settings::Settings, APIError}; use actix_web::dev::ConnectionInfo; -use chrono::{DateTime, FixedOffset, Local, NaiveDateTime}; +use chrono::{DateTime, FixedOffset, NaiveDateTime}; use itertools::Itertools; use rand::{distributions::Alphanumeric, thread_rng, Rng}; use regex::{Regex, RegexBuilder}; @@ -22,8 +22,7 @@ pub fn naive_from_unix(time: i64) -> NaiveDateTime { } pub fn convert_datetime(datetime: NaiveDateTime) -> DateTime { - let now = Local::now(); - DateTime::::from_utc(datetime, *now.offset()) + DateTime::::from_utc(datetime, FixedOffset::east(0)) } pub fn remove_slurs(test: &str) -> String {