From: Dessalines Date: Mon, 21 Dec 2020 02:48:29 +0000 (-0500) Subject: Merge branch 'drone-io-dess' into move_views_to_diesel_drone X-Git-Url: http://these/git/readmes/%7B%7D/static/%7B%60https:/%7Burl%7D?a=commitdiff_plain;h=d767dd998e1aab28252e09ea6a61bf574df68a8a;p=lemmy.git Merge branch 'drone-io-dess' into move_views_to_diesel_drone --- d767dd998e1aab28252e09ea6a61bf574df68a8a diff --cc api_tests/src/comment.spec.ts index 8e86a2be,57756a39..b0ca55d0 --- a/api_tests/src/comment.spec.ts +++ b/api_tests/src/comment.spec.ts @@@ -20,10 -20,10 +20,8 @@@ import createCommunity, registerUser, API, - delay, - longDelay, } from './shared'; -import { - Comment, -} from 'lemmy-js-client'; +import { CommentView } from 'lemmy-js-client'; import { PostResponse } from 'lemmy-js-client'; @@@ -34,10 -34,9 +32,9 @@@ 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 + search.communities.find(c => c.community.local == false).community.id ); }); @@@ -61,21 -59,20 +58,20 @@@ function assertCommentFederation } test('Create a comment', async () => { - let commentRes = await createComment(alpha, postRes.post.id); - expect(commentRes.comment.content).toBeDefined(); - expect(commentRes.comment.community_local).toBe(false); - expect(commentRes.comment.creator_local).toBe(true); - expect(commentRes.comment.score).toBe(1); + let commentRes = await createComment(alpha, postRes.post_view.post.id); + expect(commentRes.comment_view.comment.content).toBeDefined(); + expect(commentRes.comment_view.community.local).toBe(false); + expect(commentRes.comment_view.creator.local).toBe(true); + expect(commentRes.comment_view.counts.score).toBe(1); - await longDelay(); // Make sure that comment is liked on beta - let searchBeta = await searchComment(beta, commentRes.comment); + let searchBeta = await searchComment(beta, commentRes.comment_view.comment); let betaComment = searchBeta.comments[0]; expect(betaComment).toBeDefined(); - expect(betaComment.community_local).toBe(true); - expect(betaComment.creator_local).toBe(false); - expect(betaComment.score).toBe(1); - assertCommentFederation(betaComment, commentRes.comment); + expect(betaComment.community.local).toBe(true); + expect(betaComment.creator.local).toBe(false); + expect(betaComment.counts.score).toBe(1); + assertCommentFederation(betaComment, commentRes.comment_view); }); test('Create a comment in a non-existent post', async () => { @@@ -84,99 -81,74 +80,90 @@@ }); test('Update a comment', async () => { - let commentRes = await createComment(alpha, postRes.post.id); + let commentRes = await createComment(alpha, postRes.post_view.post.id); // Federate the comment first - let searchBeta = await searchComment(beta, commentRes.comment); - assertCommentFederation(searchBeta.comments[0], commentRes.comment); + let searchBeta = await searchComment(beta, commentRes.comment_view.comment); + assertCommentFederation(searchBeta.comments[0], commentRes.comment_view); - await delay(); - let updateCommentRes = await updateComment(alpha, commentRes.comment.id); - expect(updateCommentRes.comment.content).toBe( + let updateCommentRes = await editComment( + alpha, + commentRes.comment_view.comment.id + ); + expect(updateCommentRes.comment_view.comment.content).toBe( 'A jest test federated comment update' ); - expect(updateCommentRes.comment.community_local).toBe(false); - expect(updateCommentRes.comment.creator_local).toBe(true); + expect(updateCommentRes.comment_view.community.local).toBe(false); + expect(updateCommentRes.comment_view.creator.local).toBe(true); - await delay(); // Make sure that post is updated on beta - let searchBetaUpdated = await searchComment(beta, commentRes.comment); - assertCommentFederation(searchBetaUpdated.comments[0], updateCommentRes.comment); + let searchBetaUpdated = await searchComment( + beta, + commentRes.comment_view.comment + ); + assertCommentFederation( + searchBetaUpdated.comments[0], + updateCommentRes.comment_view + ); }); test('Delete a comment', async () => { - let commentRes = await createComment(alpha, postRes.post.id); + let commentRes = await createComment(alpha, postRes.post_view.post.id); - await delay(); let deleteCommentRes = await deleteComment( alpha, true, - commentRes.comment.id + commentRes.comment_view.comment.id ); - expect(deleteCommentRes.comment.deleted).toBe(true); + expect(deleteCommentRes.comment_view.comment.deleted).toBe(true); - await delay(); // Make sure that comment is undefined on beta - let searchBeta = await searchComment(beta, commentRes.comment); + let searchBeta = await searchComment(beta, commentRes.comment_view.comment); let betaComment = searchBeta.comments[0]; expect(betaComment).toBeUndefined(); - await delay(); let undeleteCommentRes = await deleteComment( alpha, false, - commentRes.comment.id + commentRes.comment_view.comment.id ); - expect(undeleteCommentRes.comment.deleted).toBe(false); + expect(undeleteCommentRes.comment_view.comment.deleted).toBe(false); - await delay(); // Make sure that comment is undeleted on beta - let searchBeta2 = await searchComment(beta, commentRes.comment); + let searchBeta2 = await searchComment(beta, commentRes.comment_view.comment); let betaComment2 = searchBeta2.comments[0]; - expect(betaComment2.deleted).toBe(false); - assertCommentFederation(searchBeta2.comments[0], undeleteCommentRes.comment); + expect(betaComment2.comment.deleted).toBe(false); + assertCommentFederation( + searchBeta2.comments[0], + undeleteCommentRes.comment_view + ); }); test('Remove a comment from admin and community on the same instance', async () => { - let commentRes = await createComment(alpha, postRes.post.id); + let commentRes = await createComment(alpha, postRes.post_view.post.id); - await delay(); // Get the id for beta - let betaCommentId = (await searchComment(beta, commentRes.comment)) - .comments[0].id; + let betaCommentId = ( + await searchComment(beta, commentRes.comment_view.comment) + ).comments[0].comment.id; // The beta admin removes it (the community lives on beta) let removeCommentRes = await removeComment(beta, true, betaCommentId); - expect(removeCommentRes.comment.removed).toBe(true); + expect(removeCommentRes.comment_view.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); - expect(refetchedPost.comments[0].removed).toBe(true); + let refetchedPost = await getPost(alpha, postRes.post_view.post.id); + expect(refetchedPost.comments[0].comment.removed).toBe(true); let unremoveCommentRes = await removeComment(beta, false, betaCommentId); - expect(unremoveCommentRes.comment.removed).toBe(false); + expect(unremoveCommentRes.comment_view.comment.removed).toBe(false); - await longDelay(); // Make sure that comment is unremoved on beta - let refetchedPost2 = await getPost(alpha, postRes.post.id); - expect(refetchedPost2.comments[0].removed).toBe(false); - assertCommentFederation(refetchedPost2.comments[0], unremoveCommentRes.comment); + let refetchedPost2 = await getPost(alpha, postRes.post_view.post.id); + expect(refetchedPost2.comments[0].comment.removed).toBe(false); + assertCommentFederation( + refetchedPost2.comments[0], + unremoveCommentRes.comment_view + ); }); test('Remove a comment from admin and community on different instance', async () => { @@@ -188,87 -160,66 +175,77 @@@ // New alpha user creates a community, post, and comment. let newCommunity = await createCommunity(newAlphaApi); - await delay(); - let newPost = await createPost(newAlphaApi, newCommunity.community.id); - let commentRes = await createComment(newAlphaApi, newPost.post.id); - expect(commentRes.comment.content).toBeDefined(); + let newPost = await createPost( + newAlphaApi, + newCommunity.community_view.community.id + ); - await delay(); + let commentRes = await createComment(newAlphaApi, newPost.post_view.post.id); + expect(commentRes.comment_view.comment.content).toBeDefined(); - await delay(); // Beta searches that to cache it, then removes it - let searchBeta = await searchComment(beta, commentRes.comment); + let searchBeta = await searchComment(beta, commentRes.comment_view.comment); let betaComment = searchBeta.comments[0]; - let removeCommentRes = await removeComment(beta, true, betaComment.id); - expect(removeCommentRes.comment.removed).toBe(true); + let removeCommentRes = await removeComment( + beta, + true, + betaComment.comment.id + ); + expect(removeCommentRes.comment_view.comment.removed).toBe(true); - await delay(); // Make sure its not removed on alpha - let refetchedPost = await getPost(newAlphaApi, newPost.post.id); - expect(refetchedPost.comments[0].removed).toBe(false); - assertCommentFederation(refetchedPost.comments[0], commentRes.comment); + let refetchedPost = await getPost(newAlphaApi, newPost.post_view.post.id); + expect(refetchedPost.comments[0].comment.removed).toBe(false); + assertCommentFederation(refetchedPost.comments[0], commentRes.comment_view); }); test('Unlike a comment', async () => { - let commentRes = await createComment(alpha, postRes.post.id); - let unlike = await likeComment(alpha, 0, commentRes.comment); - expect(unlike.comment.score).toBe(0); + let commentRes = await createComment(alpha, postRes.post_view.post.id); - await delay(); + let unlike = await likeComment(alpha, 0, commentRes.comment_view.comment); + expect(unlike.comment_view.counts.score).toBe(0); - await delay(); // Make sure that post is unliked on beta - let searchBeta = await searchComment(beta, commentRes.comment); + let searchBeta = await searchComment(beta, commentRes.comment_view.comment); let betaComment = searchBeta.comments[0]; expect(betaComment).toBeDefined(); - expect(betaComment.community_local).toBe(true); - expect(betaComment.creator_local).toBe(false); - expect(betaComment.score).toBe(0); + expect(betaComment.community.local).toBe(true); + expect(betaComment.creator.local).toBe(false); + expect(betaComment.counts.score).toBe(0); }); test('Federated comment like', async () => { - let commentRes = await createComment(alpha, postRes.post.id); + let commentRes = await createComment(alpha, postRes.post_view.post.id); - await longDelay(); // Find the comment on beta - let searchBeta = await searchComment(beta, commentRes.comment); + let searchBeta = await searchComment(beta, commentRes.comment_view.comment); let betaComment = searchBeta.comments[0]; - let like = await likeComment(beta, 1, betaComment); - expect(like.comment.score).toBe(2); + let like = await likeComment(beta, 1, betaComment.comment); + expect(like.comment_view.counts.score).toBe(2); - await longDelay(); // Get the post from alpha, check the likes - let post = await getPost(alpha, postRes.post.id); - expect(post.comments[0].score).toBe(2); + let post = await getPost(alpha, postRes.post_view.post.id); + expect(post.comments[0].counts.score).toBe(2); }); test('Reply to a comment', async () => { // Create a comment on alpha, find it on beta - let commentRes = await createComment(alpha, postRes.post.id); - let searchBeta = await searchComment(beta, commentRes.comment); + let commentRes = await createComment(alpha, postRes.post_view.post.id); - await delay(); + let searchBeta = await searchComment(beta, commentRes.comment_view.comment); let betaComment = searchBeta.comments[0]; // find that comment id on beta // Reply from beta - let replyRes = await createComment(beta, betaComment.post_id, betaComment.id); - expect(replyRes.comment.content).toBeDefined(); - expect(replyRes.comment.community_local).toBe(true); - expect(replyRes.comment.creator_local).toBe(true); - expect(replyRes.comment.parent_id).toBe(betaComment.id); - expect(replyRes.comment.score).toBe(1); + let replyRes = await createComment( + beta, + betaComment.post.id, + betaComment.comment.id + ); + expect(replyRes.comment_view.comment.content).toBeDefined(); + expect(replyRes.comment_view.community.local).toBe(true); + expect(replyRes.comment_view.creator.local).toBe(true); + expect(replyRes.comment_view.comment.parent_id).toBe(betaComment.comment.id); + expect(replyRes.comment_view.counts.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 @@@ -287,42 -238,38 +264,38 @@@ 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); + let commentRes = await createComment(alpha, postRes.post_view.post.id); - await delay(); let mentionRes = await createComment( alpha, - postRes.post.id, - commentRes.comment.id, + postRes.post_view.post.id, + commentRes.comment_view.comment.id, mentionContent ); - expect(mentionRes.comment.content).toBeDefined(); - expect(mentionRes.comment.community_local).toBe(false); - expect(mentionRes.comment.creator_local).toBe(true); - expect(mentionRes.comment.score).toBe(1); + expect(mentionRes.comment_view.comment.content).toBeDefined(); + expect(mentionRes.comment_view.community.local).toBe(false); + expect(mentionRes.comment_view.creator.local).toBe(true); + expect(mentionRes.comment_view.counts.score).toBe(1); - await delay(); let mentionsRes = await getMentions(beta); - expect(mentionsRes.mentions[0].content).toBeDefined(); - expect(mentionsRes.mentions[0].community_local).toBe(true); - expect(mentionsRes.mentions[0].creator_local).toBe(false); - expect(mentionsRes.mentions[0].score).toBe(1); + expect(mentionsRes.mentions[0].comment.content).toBeDefined(); + expect(mentionsRes.mentions[0].community.local).toBe(true); + expect(mentionsRes.mentions[0].creator.local).toBe(false); + expect(mentionsRes.mentions[0].counts.score).toBe(1); }); test('Comment Search', async () => { - let commentRes = await createComment(alpha, postRes.post.id); - let searchBeta = await searchComment(beta, commentRes.comment); - assertCommentFederation(searchBeta.comments[0], commentRes.comment); + let commentRes = await createComment(alpha, postRes.post_view.post.id); - await delay(); + let searchBeta = await searchComment(beta, commentRes.comment_view.comment); + assertCommentFederation(searchBeta.comments[0], commentRes.comment_view); }); test('A and G subscribe to B (center) A posts, G mentions B, it gets announced to A', async () => { // Create a local post let alphaPost = await createPost(alpha, 2); - expect(alphaPost.post.community_local).toBe(true); + expect(alphaPost.post_view.community.local).toBe(true); - await delay(); // Make sure gamma sees it - let search = await searchPost(gamma, alphaPost.post); + let search = await searchPost(gamma, alphaPost.post_view.post); let gammaPost = search.posts[0]; let commentContent = @@@ -333,20 -280,18 +306,18 @@@ undefined, commentContent ); - expect(commentRes.comment.content).toBe(commentContent); - expect(commentRes.comment.community_local).toBe(false); - expect(commentRes.comment.creator_local).toBe(true); - expect(commentRes.comment.score).toBe(1); + expect(commentRes.comment_view.comment.content).toBe(commentContent); + expect(commentRes.comment_view.community.local).toBe(false); + expect(commentRes.comment_view.creator.local).toBe(true); + expect(commentRes.comment_view.counts.score).toBe(1); - await longDelay(); // Make sure alpha sees it - let alphaPost2 = await getPost(alpha, alphaPost.post.id); - expect(alphaPost2.comments[0].content).toBe(commentContent); - expect(alphaPost2.comments[0].community_local).toBe(true); - expect(alphaPost2.comments[0].creator_local).toBe(false); - expect(alphaPost2.comments[0].score).toBe(1); - assertCommentFederation(alphaPost2.comments[0], commentRes.comment); + let alphaPost2 = await getPost(alpha, alphaPost.post_view.post.id); + expect(alphaPost2.comments[0].comment.content).toBe(commentContent); + expect(alphaPost2.comments[0].community.local).toBe(true); + expect(alphaPost2.comments[0].creator.local).toBe(false); + expect(alphaPost2.comments[0].counts.score).toBe(1); + assertCommentFederation(alphaPost2.comments[0], commentRes.comment_view); - await delay(); // Make sure beta has mentions let mentionsRes = await getMentions(beta); @@@ -366,8 -311,7 +337,7 @@@ test('Fetch in_reply_tos: A is unsubbe // B creates a post, and two comments, should be invisible to A let postRes = await createPost(beta, 2); - expect(postRes.post.name).toBeDefined(); + expect(postRes.post_view.post.name).toBeDefined(); - await delay(); let parentCommentContent = 'An invisible top level comment from beta'; let parentCommentRes = await createComment( @@@ -376,49 -320,42 +346,46 @@@ undefined, parentCommentContent ); - expect(parentCommentRes.comment.content).toBe(parentCommentContent); + expect(parentCommentRes.comment_view.comment.content).toBe( + parentCommentContent + ); - await delay(); // B creates a comment, then a child one of that. let childCommentContent = 'An invisible child comment from beta'; let childCommentRes = await createComment( beta, - postRes.post.id, - parentCommentRes.comment.id, + postRes.post_view.post.id, + parentCommentRes.comment_view.comment.id, + childCommentContent + ); + expect(childCommentRes.comment_view.comment.content).toBe( childCommentContent ); - await delay(); - expect(childCommentRes.comment.content).toBe(childCommentContent); // Follow beta again let follow = await followBeta(alpha); - expect(follow.community.local).toBe(false); - expect(follow.community.name).toBe('main'); + expect(follow.community_view.community.local).toBe(false); + expect(follow.community_view.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'; - let updateRes = await updateComment( + let updateRes = await editComment( beta, - childCommentRes.comment.id, + childCommentRes.comment_view.comment.id, updatedCommentContent ); - expect(updateRes.comment.content).toBe(updatedCommentContent); + expect(updateRes.comment_view.comment.content).toBe(updatedCommentContent); - await delay(); // Get the post from alpha - let search = await searchPost(alpha, postRes.post); + let search = await searchPost(alpha, postRes.post_view.post); let alphaPostB = search.posts[0]; - await longDelay(); - let alphaPost = await getPost(alpha, alphaPostB.id); - expect(alphaPost.post.name).toBeDefined(); - assertCommentFederation(alphaPost.comments[1], parentCommentRes.comment); - assertCommentFederation(alphaPost.comments[0], updateRes.comment); - expect(alphaPost.post.community_local).toBe(false); - expect(alphaPost.post.creator_local).toBe(false); + let alphaPost = await getPost(alpha, alphaPostB.post.id); + expect(alphaPost.post_view.post.name).toBeDefined(); + assertCommentFederation(alphaPost.comments[1], parentCommentRes.comment_view); + assertCommentFederation(alphaPost.comments[0], updateRes.comment_view); + expect(alphaPost.post_view.community.local).toBe(false); + expect(alphaPost.post_view.creator.local).toBe(false); + + await unfollowRemotes(alpha); }); diff --cc api_tests/src/community.spec.ts index fcb9130b,90690064..25d8109c --- a/api_tests/src/community.spec.ts +++ b/api_tests/src/community.spec.ts @@@ -9,9 -9,10 +9,8 @@@ import removeCommunity, getCommunity, followCommunity, - delay, } from './shared'; -import { - Community, -} from 'lemmy-js-client'; +import { CommunityView } from 'lemmy-js-client'; beforeAll(async () => { await setupLogins(); @@@ -43,13 -37,12 +42,12 @@@ function assertCommunityFederation test('Create community', async () => { let communityRes = await createCommunity(alpha); - expect(communityRes.community.name).toBeDefined(); + expect(communityRes.community_view.community.name).toBeDefined(); // A dupe check - let prevName = communityRes.community.name; - let communityRes2 = await createCommunity(alpha, prevName); + let prevName = communityRes.community_view.community.name; + let communityRes2: any = 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`; @@@ -60,125 -53,88 +58,112 @@@ 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 searchShort = `!${communityRes.community_view.community.name}@lemmy-beta:8551`; let search = await searchForCommunity(alpha, searchShort); let communityOnAlpha = search.communities[0]; - assertCommunityFederation(communityOnAlpha, communityRes.community); + assertCommunityFederation(communityOnAlpha, communityRes.community_view); - await delay(); // Follow the community from alpha - let follow = await followCommunity(alpha, true, communityOnAlpha.id); + let follow = await followCommunity( + alpha, + true, + communityOnAlpha.community.id + ); // Make sure the follow response went through - expect(follow.community.local).toBe(false); + expect(follow.community_view.community.local).toBe(false); - await delay(); let deleteCommunityRes = await deleteCommunity( beta, true, - communityRes.community.id + communityRes.community_view.community.id ); - expect(deleteCommunityRes.community.deleted).toBe(true); + expect(deleteCommunityRes.community_view.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); + let communityOnAlphaDeleted = await getCommunity( + alpha, + communityOnAlpha.community.id + ); + expect(communityOnAlphaDeleted.community_view.community.deleted).toBe(true); - await delay(); // Undelete let undeleteCommunityRes = await deleteCommunity( beta, false, - communityRes.community.id + communityRes.community_view.community.id ); - expect(undeleteCommunityRes.community.deleted).toBe(false); + expect(undeleteCommunityRes.community_view.community.deleted).toBe(false); - await delay(); // Make sure it got undeleted on A - let communityOnAlphaUnDeleted = await getCommunity(alpha, communityOnAlpha.id); - expect(communityOnAlphaUnDeleted.community.deleted).toBe(false); + let communityOnAlphaUnDeleted = await getCommunity( + alpha, + communityOnAlpha.community.id + ); + expect(communityOnAlphaUnDeleted.community_view.community.deleted).toBe( + false + ); }); 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 searchShort = `!${communityRes.community_view.community.name}@lemmy-beta:8551`; let search = await searchForCommunity(alpha, searchShort); let communityOnAlpha = search.communities[0]; - assertCommunityFederation(communityOnAlpha, communityRes.community); + assertCommunityFederation(communityOnAlpha, communityRes.community_view); - await delay(); // Follow the community from alpha - let follow = await followCommunity(alpha, true, communityOnAlpha.id); + let follow = await followCommunity( + alpha, + true, + communityOnAlpha.community.id + ); // Make sure the follow response went through - expect(follow.community.local).toBe(false); + expect(follow.community_view.community.local).toBe(false); - await delay(); let removeCommunityRes = await removeCommunity( beta, true, - communityRes.community.id + communityRes.community_view.community.id ); - expect(removeCommunityRes.community.removed).toBe(true); + expect(removeCommunityRes.community_view.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); + let communityOnAlphaRemoved = await getCommunity( + alpha, + communityOnAlpha.community.id + ); + expect(communityOnAlphaRemoved.community_view.community.removed).toBe(true); - await delay(); // unremove let unremoveCommunityRes = await removeCommunity( beta, false, - communityRes.community.id + communityRes.community_view.community.id ); - expect(unremoveCommunityRes.community.removed).toBe(false); + expect(unremoveCommunityRes.community_view.community.removed).toBe(false); - await delay(); // Make sure it got undeleted on A - let communityOnAlphaUnRemoved = await getCommunity(alpha, communityOnAlpha.id); - expect(communityOnAlphaUnRemoved.community.removed).toBe(false); + let communityOnAlphaUnRemoved = await getCommunity( + alpha, + communityOnAlpha.community.id + ); + expect(communityOnAlphaUnRemoved.community_view.community.removed).toBe( + false + ); }); test('Search for beta community', async () => { let communityRes = await createCommunity(beta); - expect(communityRes.community.name).toBeDefined(); + expect(communityRes.community_view.community.name).toBeDefined(); - await delay(); - let searchShort = `!${communityRes.community.name}@lemmy-beta:8551`; + let searchShort = `!${communityRes.community_view.community.name}@lemmy-beta:8551`; let search = await searchForCommunity(alpha, searchShort); let communityOnAlpha = search.communities[0]; - assertCommunityFederation(communityOnAlpha, communityRes.community); + assertCommunityFederation(communityOnAlpha, communityRes.community_view); }); diff --cc api_tests/src/follow.spec.ts index 8917efc0,651c526a..0749439c --- a/api_tests/src/follow.spec.ts +++ b/api_tests/src/follow.spec.ts @@@ -20,29 -18,22 +18,26 @@@ afterAll(async () => test('Follow federated community', async () => { let search = await searchForBetaCommunity(alpha); // TODO sometimes this is returning null? - let follow = await followCommunity(alpha, true, search.communities[0].id); + let follow = await followCommunity( + alpha, + true, + search.communities[0].community.id + ); // Make sure the follow response went through - expect(follow.community.local).toBe(false); - expect(follow.community.name).toBe('main'); + expect(follow.community_view.community.local).toBe(false); + expect(follow.community_view.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; + let remoteCommunityId = followCheck.communities.find( + c => c.community.local == false + ).community.id; expect(remoteCommunityId).toBeDefined(); // Test an unfollow let unfollow = await followCommunity(alpha, false, remoteCommunityId); - expect(unfollow.community.local).toBe(false); + expect(unfollow.community_view.community.local).toBe(false); - await delay(); // Make sure you are unsubbed locally let unfollowCheck = await checkFollowedCommunities(alpha); diff --cc api_tests/src/post.spec.ts index 4a34e1ed,44edcb24..01befa60 --- a/api_tests/src/post.spec.ts +++ b/api_tests/src/post.spec.ts @@@ -26,7 -24,12 +24,9 @@@ import searchPostLocal, banUserFromCommunity, } from './shared'; - import { PostView } from 'lemmy-js-client'; -import { - Post, - Community, -} from 'lemmy-js-client'; ++import { PostView, CommunityView } from 'lemmy-js-client'; + -let betaCommunity: Community; ++let betaCommunity: CommunityView; beforeAll(async () => { await setupLogins(); @@@ -42,36 -47,35 +44,33 @@@ async function unfollows() await unfollowRemotes(gamma); await unfollowRemotes(delta); await unfollowRemotes(epsilon); - }); + } -function assertPostFederation( - postOne: Post, - postTwo: Post) { - expect(postOne.ap_id).toBe(postTwo.ap_id); - expect(postOne.name).toBe(postTwo.name); - expect(postOne.body).toBe(postTwo.body); - expect(postOne.url).toBe(postTwo.url); - expect(postOne.nsfw).toBe(postTwo.nsfw); - expect(postOne.embed_title).toBe(postTwo.embed_title); - expect(postOne.embed_description).toBe(postTwo.embed_description); - expect(postOne.embed_html).toBe(postTwo.embed_html); - expect(postOne.published).toBe(postTwo.published); - expect(postOne.community_actor_id).toBe(postTwo.community_actor_id); - expect(postOne.locked).toBe(postTwo.locked); - expect(postOne.removed).toBe(postTwo.removed); - expect(postOne.deleted).toBe(postTwo.deleted); +function assertPostFederation(postOne: PostView, postTwo: PostView) { + expect(postOne.post.ap_id).toBe(postTwo.post.ap_id); + expect(postOne.post.name).toBe(postTwo.post.name); + expect(postOne.post.body).toBe(postTwo.post.body); + expect(postOne.post.url).toBe(postTwo.post.url); + expect(postOne.post.nsfw).toBe(postTwo.post.nsfw); + expect(postOne.post.embed_title).toBe(postTwo.post.embed_title); + expect(postOne.post.embed_description).toBe(postTwo.post.embed_description); + expect(postOne.post.embed_html).toBe(postTwo.post.embed_html); + expect(postOne.post.published).toBe(postTwo.post.published); + expect(postOne.community.actor_id).toBe(postTwo.community.actor_id); + expect(postOne.post.locked).toBe(postTwo.post.locked); + expect(postOne.post.removed).toBe(postTwo.post.removed); + expect(postOne.post.deleted).toBe(postTwo.post.deleted); } test('Create a post', async () => { - let search = await searchForBetaCommunity(alpha); - await delay(); - let postRes = await createPost(alpha, search.communities[0].community.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); ++ let postRes = await createPost(alpha, betaCommunity.community.id); + expect(postRes.post_view.post).toBeDefined(); + expect(postRes.post_view.community.local).toBe(false); + expect(postRes.post_view.creator.local).toBe(true); + expect(postRes.post_view.counts.score).toBe(1); - await longDelay(); // Make sure that post is liked on beta - let searchBeta = await searchPost(beta, postRes.post); + let searchBeta = await searchPost(beta, postRes.post_view.post); let betaPost = searchBeta.posts[0]; expect(betaPost).toBeDefined(); @@@ -95,242 -99,207 +94,208 @@@ test('Create a post in a non-existent c }); test('Unlike a post', async () => { - let search = await searchForBetaCommunity(alpha); - let postRes = await createPost(alpha, search.communities[0].community.id); - await delay(); - let postRes = await createPost(alpha, betaCommunity.id); - let unlike = await likePost(alpha, 0, postRes.post); - expect(unlike.post.score).toBe(0); ++ let postRes = await createPost(alpha, betaCommunity.community.id); + let unlike = await likePost(alpha, 0, postRes.post_view.post); + expect(unlike.post_view.counts.score).toBe(0); - await delay(); // Try to unlike it again, make sure it stays at 0 - let unlike2 = await likePost(alpha, 0, postRes.post); - expect(unlike2.post.score).toBe(0); + let unlike2 = await likePost(alpha, 0, postRes.post_view.post); + expect(unlike2.post_view.counts.score).toBe(0); - await longDelay(); // Make sure that post is unliked on beta - let searchBeta = await searchPost(beta, postRes.post); + let searchBeta = await searchPost(beta, postRes.post_view.post); let betaPost = searchBeta.posts[0]; - expect(betaPost).toBeDefined(); - expect(betaPost.community_local).toBe(true); - expect(betaPost.creator_local).toBe(false); - expect(betaPost.score).toBe(0); - assertPostFederation(betaPost, postRes.post); + expect(betaPost.community.local).toBe(true); + expect(betaPost.creator.local).toBe(false); + expect(betaPost.counts.score).toBe(0); + assertPostFederation(betaPost, postRes.post_view); }); test('Update a post', async () => { - let search = await searchForBetaCommunity(alpha); - let postRes = await createPost(alpha, search.communities[0].community.id); - await delay(); - let postRes = await createPost(alpha, betaCommunity.id); ++ let postRes = await createPost(alpha, betaCommunity.community.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); + let updatedPost = await editPost(alpha, postRes.post_view.post); + expect(updatedPost.post_view.post.name).toBe(updatedName); + expect(updatedPost.post_view.community.local).toBe(false); + expect(updatedPost.post_view.creator.local).toBe(true); - await delay(); // Make sure that post is updated on beta - let searchBeta = await searchPost(beta, postRes.post); + let searchBeta = await searchPost(beta, postRes.post_view.post); let betaPost = searchBeta.posts[0]; - expect(betaPost.community_local).toBe(true); - expect(betaPost.creator_local).toBe(false); - expect(betaPost.name).toBe(updatedName); - assertPostFederation(betaPost, updatedPost.post); + expect(betaPost.community.local).toBe(true); + expect(betaPost.creator.local).toBe(false); + expect(betaPost.post.name).toBe(updatedName); + assertPostFederation(betaPost, updatedPost.post_view); - await delay(); // Make sure lemmy beta cannot update the post - let updatedPostBeta = await updatePost(beta, betaPost); + let updatedPostBeta = await editPost(beta, betaPost.post); expect(updatedPostBeta).toStrictEqual({ error: 'no_post_edit_allowed' }); }); test('Sticky a post', async () => { - let search = await searchForBetaCommunity(alpha); - let postRes = await createPost(alpha, search.communities[0].community.id); - await delay(); - let postRes = await createPost(alpha, betaCommunity.id); ++ let postRes = await createPost(alpha, betaCommunity.community.id); + + let stickiedPostRes = await stickyPost(alpha, true, postRes.post_view.post); + expect(stickiedPostRes.post_view.post.stickied).toBe(true); - await delay(); - let stickiedPostRes = await stickyPost(alpha, true, postRes.post); - expect(stickiedPostRes.post.stickied).toBe(true); // Make sure that post is stickied on beta - let searchBeta = await searchPost(beta, postRes.post); + let searchBeta = await searchPost(beta, postRes.post_view.post); let betaPost = searchBeta.posts[0]; - expect(betaPost.community_local).toBe(true); - expect(betaPost.creator_local).toBe(false); - expect(betaPost.stickied).toBe(true); + expect(betaPost.community.local).toBe(true); + expect(betaPost.creator.local).toBe(false); + expect(betaPost.post.stickied).toBe(true); // Unsticky a post - let unstickiedPost = await stickyPost(alpha, false, postRes.post); - expect(unstickiedPost.post.stickied).toBe(false); + let unstickiedPost = await stickyPost(alpha, false, postRes.post_view.post); + expect(unstickiedPost.post_view.post.stickied).toBe(false); - await delay(); // Make sure that post is unstickied on beta - let searchBeta2 = await searchPost(beta, postRes.post); + let searchBeta2 = await searchPost(beta, postRes.post_view.post); let betaPost2 = searchBeta2.posts[0]; - expect(betaPost2.community_local).toBe(true); - expect(betaPost2.creator_local).toBe(false); - expect(betaPost2.stickied).toBe(false); + expect(betaPost2.community.local).toBe(true); + expect(betaPost2.creator.local).toBe(false); + expect(betaPost2.post.stickied).toBe(false); // Make sure that gamma cannot sticky the post on beta - let searchGamma = await searchPost(gamma, postRes.post); + let searchGamma = await searchPost(gamma, postRes.post_view.post); let gammaPost = searchGamma.posts[0]; - let gammaTrySticky = await stickyPost(gamma, true, gammaPost); - let searchBeta3 = await searchPost(beta, postRes.post); + let gammaTrySticky = await stickyPost(gamma, true, gammaPost.post); - await delay(); + let searchBeta3 = await searchPost(beta, postRes.post_view.post); let betaPost3 = searchBeta3.posts[0]; - expect(gammaTrySticky.post.stickied).toBe(true); - expect(betaPost3.stickied).toBe(false); + expect(gammaTrySticky.post_view.post.stickied).toBe(true); + expect(betaPost3.post.stickied).toBe(false); }); test('Lock a post', async () => { - let search = await searchForBetaCommunity(alpha); - await delay(); - let postRes = await createPost(alpha, search.communities[0].community.id); - await delay(); - let postRes = await createPost(alpha, betaCommunity.id); ++ let postRes = await createPost(alpha, betaCommunity.community.id); // Lock the post - let lockedPostRes = await lockPost(alpha, true, postRes.post); - expect(lockedPostRes.post.locked).toBe(true); + let lockedPostRes = await lockPost(alpha, true, postRes.post_view.post); + expect(lockedPostRes.post_view.post.locked).toBe(true); - await longDelay(); // Make sure that post is locked on beta - let searchBeta = await searchPostLocal(beta, postRes.post); + let searchBeta = await searchPostLocal(beta, postRes.post_view.post); let betaPost1 = searchBeta.posts[0]; - expect(betaPost1.locked).toBe(true); + expect(betaPost1.post.locked).toBe(true); - await delay(); // Try to make a new comment there, on alpha - let comment = await createComment(alpha, postRes.post.id); + let comment: any = await createComment(alpha, postRes.post_view.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); + let unlockedPost = await lockPost(alpha, false, postRes.post_view.post); + expect(unlockedPost.post_view.post.locked).toBe(false); - await delay(); // Make sure that post is unlocked on beta - let searchBeta2 = await searchPost(beta, postRes.post); + let searchBeta2 = await searchPost(beta, postRes.post_view.post); let betaPost2 = searchBeta2.posts[0]; - expect(betaPost2.community_local).toBe(true); - expect(betaPost2.creator_local).toBe(false); - expect(betaPost2.locked).toBe(false); + expect(betaPost2.community.local).toBe(true); + expect(betaPost2.creator.local).toBe(false); + expect(betaPost2.post.locked).toBe(false); // Try to create a new comment, on beta - let commentBeta = await createComment(beta, betaPost2.id); + let commentBeta = await createComment(beta, betaPost2.post.id); expect(commentBeta).toBeDefined(); }); test('Delete a post', async () => { - let search = await searchForBetaCommunity(alpha); - let postRes = await createPost(alpha, search.communities[0].community.id); - await delay(); - let postRes = await createPost(alpha, betaCommunity.id); - expect(postRes.post).toBeDefined(); ++ let postRes = await createPost(alpha, betaCommunity.community.id); ++ expect(postRes.post_view.post).toBeDefined(); - let deletedPost = await deletePost(alpha, true, postRes.post); - expect(deletedPost.post.deleted).toBe(true); + let deletedPost = await deletePost(alpha, true, postRes.post_view.post); + expect(deletedPost.post_view.post.deleted).toBe(true); - await delay(); // Make sure lemmy beta sees post is deleted - let searchBeta = await searchPost(beta, postRes.post); + let searchBeta = await searchPost(beta, postRes.post_view.post); let betaPost = searchBeta.posts[0]; // This will be undefined because of the tombstone expect(betaPost).toBeUndefined(); - await delay(); // Undelete - let undeletedPost = await deletePost(alpha, false, postRes.post); - expect(undeletedPost.post.deleted).toBe(false); + let undeletedPost = await deletePost(alpha, false, postRes.post_view.post); + expect(undeletedPost.post_view.post.deleted).toBe(false); - await delay(); // Make sure lemmy beta sees post is undeleted - let searchBeta2 = await searchPost(beta, postRes.post); + let searchBeta2 = await searchPost(beta, postRes.post_view.post); let betaPost2 = searchBeta2.posts[0]; - expect(betaPost2.deleted).toBe(false); - assertPostFederation(betaPost2, undeletedPost.post); + expect(betaPost2.post.deleted).toBe(false); + assertPostFederation(betaPost2, undeletedPost.post_view); // Make sure lemmy beta cannot delete the post - let deletedPostBeta = await deletePost(beta, true, betaPost2); + let deletedPostBeta = await deletePost(beta, true, betaPost2.post); expect(deletedPostBeta).toStrictEqual({ error: 'no_post_edit_allowed' }); }); test('Remove a post from admin and community on different instance', async () => { - let search = await searchForBetaCommunity(alpha); - let postRes = await createPost(alpha, search.communities[0].community.id); - await delay(); - let postRes = await createPost(alpha, betaCommunity.id); ++ let postRes = await createPost(alpha, betaCommunity.community.id); - let removedPost = await removePost(alpha, true, postRes.post); - expect(removedPost.post.removed).toBe(true); + let removedPost = await removePost(alpha, true, postRes.post_view.post); + expect(removedPost.post_view.post.removed).toBe(true); - await delay(); // Make sure lemmy beta sees post is NOT removed - let searchBeta = await searchPost(beta, postRes.post); + let searchBeta = await searchPost(beta, postRes.post_view.post); let betaPost = searchBeta.posts[0]; - expect(betaPost.removed).toBe(false); + expect(betaPost.post.removed).toBe(false); - await delay(); // Undelete - let undeletedPost = await removePost(alpha, false, postRes.post); - expect(undeletedPost.post.removed).toBe(false); + let undeletedPost = await removePost(alpha, false, postRes.post_view.post); + expect(undeletedPost.post_view.post.removed).toBe(false); - await delay(); // Make sure lemmy beta sees post is undeleted - let searchBeta2 = await searchPost(beta, postRes.post); + let searchBeta2 = await searchPost(beta, postRes.post_view.post); let betaPost2 = searchBeta2.posts[0]; - expect(betaPost2.removed).toBe(false); - assertPostFederation(betaPost2, undeletedPost.post); + expect(betaPost2.post.removed).toBe(false); + assertPostFederation(betaPost2, undeletedPost.post_view); }); test('Remove a post from admin and community on same instance', async () => { - let search = await searchForBetaCommunity(alpha); - let postRes = await createPost(alpha, search.communities[0].community.id); - await longDelay(); + await followBeta(alpha); - let postRes = await createPost(alpha, betaCommunity.id); - expect(postRes.post).toBeDefined(); ++ let postRes = await createPost(alpha, betaCommunity.community.id); ++ expect(postRes.post_view.post).toBeDefined(); // Get the id for beta - let searchBeta = await searchPost(beta, postRes.post_view.post); - let searchBeta = await searchPostLocal(beta, postRes.post); ++ let searchBeta = await searchPostLocal(beta, postRes.post_view.post); let betaPost = searchBeta.posts[0]; - await longDelay(); + expect(betaPost).toBeDefined(); // The beta admin removes it (the community lives on beta) - let removePostRes = await removePost(beta, true, betaPost); - expect(removePostRes.post.removed).toBe(true); + let removePostRes = await removePost(beta, true, betaPost.post); + expect(removePostRes.post_view.post.removed).toBe(true); - await longDelay(); // Make sure lemmy alpha sees post is removed - let alphaPost = await getPost(alpha, postRes.post.id); - // expect(alphaPost.post.removed).toBe(true); // TODO this shouldn't be commented - // assertPostFederation(alphaPost.post, removePostRes.post); + let alphaPost = await getPost(alpha, postRes.post_view.post.id); - expect(alphaPost.post_view.post.removed).toBe(true); - assertPostFederation(alphaPost.post_view, removePostRes.post_view); - await longDelay(); ++ // expect(alphaPost.post_view.post.removed).toBe(true); // TODO this shouldn't be commented ++ // assertPostFederation(alphaPost.post_view, removePostRes.post_view); // Undelete - let undeletedPost = await removePost(beta, false, betaPost); - expect(undeletedPost.post.removed).toBe(false); + let undeletedPost = await removePost(beta, false, betaPost.post); + expect(undeletedPost.post_view.post.removed).toBe(false); - await longDelay(); // 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); + let alphaPost2 = await getPost(alpha, postRes.post_view.post.id); - await delay(); + expect(alphaPost2.post_view.post.removed).toBe(false); + assertPostFederation(alphaPost2.post_view, undeletedPost.post_view); + await unfollowRemotes(alpha); }); test('Search for a post', async () => { - let search = await searchForBetaCommunity(alpha); - await delay(); - let postRes = await createPost(alpha, search.communities[0].community.id); - await delay(); + await unfollowRemotes(alpha); - let postRes = await createPost(alpha, betaCommunity.id); - expect(postRes.post).toBeDefined(); ++ let postRes = await createPost(alpha, betaCommunity.community.id); ++ expect(postRes.post_view.post).toBeDefined(); + - let searchBeta = await searchPost(beta, postRes.post); + let searchBeta = await searchPost(beta, postRes.post_view.post); - expect(searchBeta.posts[0].name).toBeDefined(); + expect(searchBeta.posts[0].post.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].community.id); - await delay(); - let postRes = await createPost(alpha, betaCommunity.id); - expect(postRes.post).toBeDefined(); ++ let postRes = await createPost(alpha, betaCommunity.community.id); ++ expect(postRes.post_view.post).toBeDefined(); - let search2 = await searchPost(gamma, postRes.post); - expect(search2.posts[0].name).toBeDefined(); + let search2 = await searchPost(gamma, postRes.post_view.post); + expect(search2.posts[0].post.name).toBeDefined(); }); test('Enforce site ban for federated user', async () => { @@@ -338,31 -308,25 +303,25 @@@ 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); + let banAlpha = await banUserFromSite(beta, alphaUser.user.id, true); expect(banAlpha.banned).toBe(true); - await longDelay(); // Alpha makes post on beta - let search = await searchForBetaCommunity(alpha); - await delay(); - let postRes = await createPost(alpha, search.communities[0].community.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); ++ let postRes = await createPost(alpha, betaCommunity.community.id); + expect(postRes.post_view.post).toBeDefined(); + expect(postRes.post_view.community.local).toBe(false); + expect(postRes.post_view.creator.local).toBe(true); + expect(postRes.post_view.counts.score).toBe(1); - await longDelay(); // Make sure that post doesn't make it to beta - let searchBeta = await searchPostLocal(beta, postRes.post); + let searchBeta = await searchPostLocal(beta, postRes.post_view.post); let betaPost = searchBeta.posts[0]; expect(betaPost).toBeUndefined(); - await delay(); // Unban alpha - let unBanAlpha = await banUserFromSite(beta, alphaUser.id, false); + let unBanAlpha = await banUserFromSite(beta, alphaUser.user.id, false); expect(unBanAlpha.banned).toBe(false); }); @@@ -371,26 -335,21 +330,21 @@@ test('Enforce community ban for federat 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); + await banUserFromCommunity(beta, alphaUser.user.id, 2, false); + let banAlpha = await banUserFromCommunity(beta, alphaUser.user.id, 2, true); expect(banAlpha.banned).toBe(true); - await longDelay(); // Alpha makes post on beta - let search = await searchForBetaCommunity(alpha); - await delay(); - let postRes = await createPost(alpha, search.communities[0].community.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); ++ let postRes = await createPost(alpha, betaCommunity.community.id); + expect(postRes.post_view.post).toBeDefined(); + expect(postRes.post_view.community.local).toBe(false); + expect(postRes.post_view.creator.local).toBe(true); + expect(postRes.post_view.counts.score).toBe(1); - await longDelay(); // Make sure that post doesn't make it to beta community - let searchBeta = await searchPostLocal(beta, postRes.post); + let searchBeta = await searchPostLocal(beta, postRes.post_view.post); let betaPost = searchBeta.posts[0]; expect(betaPost).toBeUndefined(); diff --cc api_tests/src/private_message.spec.ts index 8bb00e12,4dc0e705..5539b19c --- a/api_tests/src/private_message.spec.ts +++ b/api_tests/src/private_message.spec.ts @@@ -18,8 -16,7 +16,7 @@@ let recipient_id: number beforeAll(async () => { await setupLogins(); let follow = await followBeta(alpha); - await longDelay(); - recipient_id = follow.community.creator_id; + recipient_id = follow.community_view.creator.id; }); afterAll(async () => { @@@ -28,72 -25,49 +25,66 @@@ test('Create a private message', async () => { let pmRes = await createPrivateMessage(alpha, recipient_id); - expect(pmRes.message.content).toBeDefined(); - expect(pmRes.message.local).toBe(true); - expect(pmRes.message.creator_local).toBe(true); - expect(pmRes.message.recipient_local).toBe(false); + expect(pmRes.private_message_view.private_message.content).toBeDefined(); + expect(pmRes.private_message_view.private_message.local).toBe(true); + expect(pmRes.private_message_view.creator.local).toBe(true); + expect(pmRes.private_message_view.recipient.local).toBe(false); - await delay(); let betaPms = await listPrivateMessages(beta); - expect(betaPms.messages[0].content).toBeDefined(); - expect(betaPms.messages[0].local).toBe(false); - expect(betaPms.messages[0].creator_local).toBe(false); - expect(betaPms.messages[0].recipient_local).toBe(true); + expect(betaPms.private_messages[0].private_message.content).toBeDefined(); + expect(betaPms.private_messages[0].private_message.local).toBe(false); + expect(betaPms.private_messages[0].creator.local).toBe(false); + expect(betaPms.private_messages[0].recipient.local).toBe(true); }); test('Update a private message', async () => { let updatedContent = 'A jest test federated private message edited'; let pmRes = await createPrivateMessage(alpha, recipient_id); - let pmUpdated = await updatePrivateMessage(alpha, pmRes.message.id); - expect(pmUpdated.message.content).toBe(updatedContent); + let pmUpdated = await editPrivateMessage( + alpha, + pmRes.private_message_view.private_message.id + ); + expect(pmUpdated.private_message_view.private_message.content).toBe( + updatedContent + ); - await longDelay(); let betaPms = await listPrivateMessages(beta); - expect(betaPms.messages[0].content).toBe(updatedContent); + expect(betaPms.private_messages[0].private_message.content).toBe( + updatedContent + ); }); 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); + let deletedPmRes = await deletePrivateMessage( + alpha, + true, + pmRes.private_message_view.private_message.id + ); + expect(deletedPmRes.private_message_view.private_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); + expect(betaPms2.private_messages.length).toBe( + betaPms1.private_messages.length - 1 + ); - await delay(); // Undelete let undeletedPmRes = await deletePrivateMessage( alpha, false, - pmRes.message.id + pmRes.private_message_view.private_message.id + ); + expect(undeletedPmRes.private_message_view.private_message.deleted).toBe( + false ); - await longDelay(); - expect(undeletedPmRes.message.deleted).toBe(false); let betaPms3 = await listPrivateMessages(beta); - expect(betaPms3.messages.length).toBe(betaPms1.messages.length); + expect(betaPms3.private_messages.length).toBe( + betaPms1.private_messages.length + ); }); diff --cc api_tests/src/shared.ts index 21ab1942,cf1fb7c6..8e6d5334 --- a/api_tests/src/shared.ts +++ b/api_tests/src/shared.ts @@@ -606,13 -602,11 +606,11 @@@ 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); - if (com[0]) { - let follow = await followCommunity(api, true, com[0].id); + let com = search.communities.find(c => c.community.local == false); + if (com) { + let follow = await followCommunity(api, true, com.community.id); return follow; } } diff --cc api_tests/src/user.spec.ts index 53274939,3a327c2a..7886f8eb --- a/api_tests/src/user.spec.ts +++ b/api_tests/src/user.spec.ts @@@ -38,39 -37,27 +37,27 @@@ 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 = { + let form: SaveUserSettings = { show_nsfw: false, - theme: "", - default_sort_type: 0, - default_listing_type: 0, - lang: "", + theme: '', + default_sort_type: SortType.Hot, + default_listing_type: ListingType.All, + lang: '', avatar, banner, - preferred_username: "user321", + 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 --cc lemmy_db/Cargo.toml index d7c0fe3b,f85225e0..5963f32c --- a/lemmy_db/Cargo.toml +++ b/lemmy_db/Cargo.toml @@@ -9,15 -9,16 +9,16 @@@ path = "src/lib.rs [dependencies] lemmy_utils = { path = "../lemmy_utils" } -diesel = { version = "1.4", features = ["postgres","chrono","r2d2","64-column-tables","serde_json"] } -diesel_migrations = "1.4" -chrono = { version = "0.4", features = ["serde"] } -serde = { version = "1.0", features = ["derive"] } -serde_json = { version = "1.0", features = ["preserve_order"]} -strum = "0.19" -strum_macros = "0.19" -log = "0.4" -sha2 = "0.9" -bcrypt = "0.8" -url = { version = "2.1", features = ["serde"] } -lazy_static = "1.3" -regex = "1.3" +diesel = { version = "1.4.5", features = ["postgres","chrono","r2d2","serde_json"] } ++diesel_migrations = "1.4.0" +chrono = { version = "0.4.19", features = ["serde"] } +serde = { version = "1.0.118", features = ["derive"] } +serde_json = { version = "1.0.60", features = ["preserve_order"] } +strum = "0.20.0" +strum_macros = "0.20.1" +log = "0.4.11" +sha2 = "0.9.2" +bcrypt = "0.9.0" +url = { version = "2.2.0", features = ["serde"] } +lazy_static = "1.4.0" +regex = "1.4.2" diff --cc test.sh index 3ea3f830,ef2e608f..21093d0c --- a/test.sh +++ b/test.sh @@@ -1,8 -1,7 +1,9 @@@ #!/bin/sh - export DATABASE_URL=postgres://lemmy:password@localhost:5432/lemmy + set -e + export LEMMY_DATABASE_URL=postgres://lemmy:password@localhost:5432/lemmy +# Commenting since this will overwrite schema.rs, which will break things now +# diesel migration run # Integration tests only work on stable due to a bug in config-rs # https://github.com/mehcode/config-rs/issues/158 RUST_BACKTRACE=1 RUST_TEST_THREADS=1 \