2020-10-01 13:32:01 +00:00
jest . setTimeout ( 180000 ) ;
2022-07-30 03:55:59 +00:00
2023-04-26 04:26:10 +00:00
import { PostResponse } from "lemmy-js-client/dist/types/PostResponse" ;
2020-08-04 14:57:37 +00:00
import {
alpha ,
beta ,
gamma ,
setupLogins ,
createPost ,
getPost ,
2021-08-23 15:25:39 +00:00
resolveComment ,
2020-08-04 14:57:37 +00:00
likeComment ,
followBeta ,
2021-08-23 15:25:39 +00:00
resolveBetaCommunity ,
2020-08-04 14:57:37 +00:00
createComment ,
2020-12-20 21:16:57 +00:00
editComment ,
2020-08-04 14:57:37 +00:00
deleteComment ,
removeComment ,
getMentions ,
2021-08-23 15:25:39 +00:00
resolvePost ,
2020-08-04 14:57:37 +00:00
unfollowRemotes ,
2020-08-06 18:30:01 +00:00
createCommunity ,
registerUser ,
2021-10-15 14:37:33 +00:00
reportComment ,
listCommentReports ,
randomString ,
2020-08-06 18:30:01 +00:00
API ,
2022-03-22 19:50:47 +00:00
unfollows ,
2022-07-30 03:55:59 +00:00
getComments ,
getCommentParentId ,
2022-10-13 16:30:31 +00:00
resolveCommunity ,
2023-07-20 14:36:16 +00:00
getPersonDetails ,
2023-08-01 13:14:40 +00:00
getReplies ,
getUnreadCount ,
2023-09-09 16:25:03 +00:00
waitUntil ,
delay ,
2022-10-27 09:24:07 +00:00
} from "./shared" ;
2023-04-26 04:26:10 +00:00
import { CommentView } from "lemmy-js-client/dist/types/CommentView" ;
2023-09-18 18:09:18 +00:00
import { CommunityView } from "lemmy-js-client" ;
2020-08-04 14:57:37 +00:00
2023-09-18 18:09:18 +00:00
let betaCommunity : CommunityView | undefined ;
2023-08-01 13:14:40 +00:00
let postOnAlphaRes : PostResponse ;
2020-08-04 14:57:37 +00:00
beforeAll ( async ( ) = > {
await setupLogins ( ) ;
2022-03-22 19:50:47 +00:00
await unfollows ( ) ;
2023-09-18 16:29:08 +00:00
await Promise . all ( [ followBeta ( alpha ) , followBeta ( gamma ) ] ) ;
2023-09-18 18:09:18 +00:00
betaCommunity = ( await resolveBetaCommunity ( alpha ) ) . community ;
2023-01-04 15:59:26 +00:00
if ( betaCommunity ) {
2023-08-01 13:14:40 +00:00
postOnAlphaRes = await createPost ( alpha , betaCommunity . community . id ) ;
2023-01-04 15:59:26 +00:00
}
2020-08-04 14:57:37 +00:00
} ) ;
afterAll ( async ( ) = > {
2022-03-22 19:50:47 +00:00
await unfollows ( ) ;
2020-08-04 14:57:37 +00:00
} ) ;
2020-09-17 15:41:51 +00:00
function assertCommentFederation (
2023-01-04 15:59:26 +00:00
commentOne? : CommentView ,
2023-07-06 13:10:38 +00:00
commentTwo? : CommentView ,
2020-12-20 21:16:57 +00:00
) {
2023-01-04 15:59:26 +00:00
expect ( commentOne ? . comment . ap_id ) . toBe ( commentTwo ? . comment . ap_id ) ;
expect ( commentOne ? . comment . content ) . toBe ( commentTwo ? . comment . content ) ;
expect ( commentOne ? . creator . name ) . toBe ( commentTwo ? . creator . name ) ;
expect ( commentOne ? . community . actor_id ) . toBe ( commentTwo ? . community . actor_id ) ;
expect ( commentOne ? . comment . published ) . toBe ( commentTwo ? . comment . published ) ;
expect ( commentOne ? . comment . updated ) . toBe ( commentOne ? . comment . updated ) ;
expect ( commentOne ? . comment . deleted ) . toBe ( commentOne ? . comment . deleted ) ;
expect ( commentOne ? . comment . removed ) . toBe ( commentOne ? . comment . removed ) ;
2020-09-17 15:41:51 +00:00
}
2022-10-27 09:24:07 +00:00
test ( "Create a comment" , async ( ) = > {
2023-08-01 13:14:40 +00:00
let commentRes = await createComment ( alpha , postOnAlphaRes . post_view . post . id ) ;
2020-12-20 21:16:57 +00:00
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 ) ;
2020-08-04 14:57:37 +00:00
// Make sure that comment is liked on beta
2022-10-27 09:24:07 +00:00
let betaComment = (
2023-09-09 16:25:03 +00:00
await waitUntil (
( ) = > resolveComment ( beta , commentRes . comment_view . comment ) ,
c = > c . comment ? . counts . score === 1 ,
)
2023-01-04 15:59:26 +00:00
) . comment ;
2020-08-04 14:57:37 +00:00
expect ( betaComment ) . toBeDefined ( ) ;
2023-01-04 15:59:26 +00:00
expect ( betaComment ? . community . local ) . toBe ( true ) ;
expect ( betaComment ? . creator . local ) . toBe ( false ) ;
expect ( betaComment ? . counts . score ) . toBe ( 1 ) ;
2020-12-20 21:16:57 +00:00
assertCommentFederation ( betaComment , commentRes . comment_view ) ;
2020-08-04 14:57:37 +00:00
} ) ;
2022-10-27 09:24:07 +00:00
test ( "Create a comment in a non-existent post" , async ( ) = > {
2023-07-21 09:47:56 +00:00
await expect ( createComment ( alpha , - 1 ) ) . rejects . toBe ( "couldnt_find_post" ) ;
2020-08-20 12:44:22 +00:00
} ) ;
2022-10-27 09:24:07 +00:00
test ( "Update a comment" , async ( ) = > {
2023-08-01 13:14:40 +00:00
let commentRes = await createComment ( alpha , postOnAlphaRes . post_view . post . id ) ;
2020-09-17 15:41:51 +00:00
// Federate the comment first
2022-10-27 09:24:07 +00:00
let betaComment = (
await resolveComment ( beta , commentRes . comment_view . comment )
) . comment ;
2023-01-04 15:59:26 +00:00
assertCommentFederation ( betaComment , commentRes . comment_view ) ;
2020-09-17 15:41:51 +00:00
2020-12-20 21:16:57 +00:00
let updateCommentRes = await editComment (
alpha ,
2023-07-06 13:10:38 +00:00
commentRes . comment_view . comment . id ,
2020-12-20 21:16:57 +00:00
) ;
expect ( updateCommentRes . comment_view . comment . content ) . toBe (
2023-07-06 13:10:38 +00:00
"A jest test federated comment update" ,
2020-08-04 14:57:37 +00:00
) ;
2020-12-20 21:16:57 +00:00
expect ( updateCommentRes . comment_view . community . local ) . toBe ( false ) ;
expect ( updateCommentRes . comment_view . creator . local ) . toBe ( true ) ;
2020-08-04 14:57:37 +00:00
// Make sure that post is updated on beta
2022-10-27 09:24:07 +00:00
let betaCommentUpdated = (
2023-09-09 16:25:03 +00:00
await waitUntil (
( ) = > resolveComment ( beta , commentRes . comment_view . comment ) ,
c = >
c . comment ? . comment . content === "A jest test federated comment update" ,
)
2023-01-04 15:59:26 +00:00
) . comment ;
2022-10-27 09:24:07 +00:00
assertCommentFederation ( betaCommentUpdated , updateCommentRes . comment_view ) ;
2020-08-04 14:57:37 +00:00
} ) ;
2022-10-27 09:24:07 +00:00
test ( "Delete a comment" , async ( ) = > {
2023-07-27 10:17:40 +00:00
// creating a comment on alpha (remote from home of community)
2023-08-01 13:14:40 +00:00
let commentRes = await createComment ( alpha , postOnAlphaRes . post_view . post . id ) ;
2020-08-31 13:48:02 +00:00
2023-07-27 10:17:40 +00:00
// Find the comment on beta (home of community)
let betaComment = (
await resolveComment ( beta , commentRes . comment_view . comment )
) . comment ;
if ( ! betaComment ) {
throw "Missing beta comment before delete" ;
}
// Find the comment on remote instance gamma
let gammaComment = (
2023-09-09 16:25:03 +00:00
await waitUntil (
( ) = >
resolveComment ( gamma , commentRes . comment_view . comment ) . catch ( e = > e ) ,
r = > r !== "couldnt_find_object" ,
)
2023-07-27 10:17:40 +00:00
) . comment ;
if ( ! gammaComment ) {
throw "Missing gamma comment (remote-home-remote replication) before delete" ;
}
2020-08-04 14:57:37 +00:00
let deleteCommentRes = await deleteComment (
alpha ,
true ,
2023-07-06 13:10:38 +00:00
commentRes . comment_view . comment . id ,
2020-08-04 14:57:37 +00:00
) ;
2020-12-20 21:16:57 +00:00
expect ( deleteCommentRes . comment_view . comment . deleted ) . toBe ( true ) ;
2020-08-04 14:57:37 +00:00
2020-08-31 13:48:02 +00:00
// Make sure that comment is undefined on beta
2023-09-09 16:25:03 +00:00
await waitUntil (
( ) = > resolveComment ( beta , commentRes . comment_view . comment ) . catch ( e = > e ) ,
e = > e === "couldnt_find_object" ,
) ;
2020-08-04 14:57:37 +00:00
2023-07-27 10:17:40 +00:00
// Make sure that comment is undefined on gamma after delete
2023-09-09 16:25:03 +00:00
await waitUntil (
( ) = > resolveComment ( gamma , commentRes . comment_view . comment ) . catch ( e = > e ) ,
e = > e === "couldnt_find_object" ,
) ;
2023-07-27 10:17:40 +00:00
// Test undeleting the comment
2020-08-04 14:57:37 +00:00
let undeleteCommentRes = await deleteComment (
alpha ,
false ,
2023-07-06 13:10:38 +00:00
commentRes . comment_view . comment . id ,
2020-08-04 14:57:37 +00:00
) ;
2020-12-20 21:16:57 +00:00
expect ( undeleteCommentRes . comment_view . comment . deleted ) . toBe ( false ) ;
2020-08-04 14:57:37 +00:00
// Make sure that comment is undeleted on beta
2022-10-27 09:24:07 +00:00
let betaComment2 = (
2023-09-09 16:25:03 +00:00
await waitUntil (
( ) = > resolveComment ( beta , commentRes . comment_view . comment ) . catch ( e = > e ) ,
e = > e !== "couldnt_find_object" ,
)
2023-01-04 15:59:26 +00:00
) . comment ;
expect ( betaComment2 ? . comment . deleted ) . toBe ( false ) ;
2022-10-27 09:24:07 +00:00
assertCommentFederation ( betaComment2 , undeleteCommentRes . comment_view ) ;
2020-08-04 14:57:37 +00:00
} ) ;
2023-07-26 16:15:18 +00:00
test . skip ( "Remove a comment from admin and community on the same instance" , async ( ) = > {
2023-08-01 13:14:40 +00:00
let commentRes = await createComment ( alpha , postOnAlphaRes . post_view . post . id ) ;
2020-08-06 18:30:01 +00:00
// Get the id for beta
2020-12-20 21:16:57 +00:00
let betaCommentId = (
2021-08-23 15:25:39 +00:00
await resolveComment ( beta , commentRes . comment_view . comment )
2023-01-04 15:59:26 +00:00
) . comment ? . comment . id ;
if ( ! betaCommentId ) {
throw "beta comment id is missing" ;
}
2020-08-06 18:30:01 +00:00
// The beta admin removes it (the community lives on beta)
let removeCommentRes = await removeComment ( beta , true , betaCommentId ) ;
2020-12-20 21:16:57 +00:00
expect ( removeCommentRes . comment_view . comment . removed ) . toBe ( true ) ;
2020-08-04 14:57:37 +00:00
2020-08-06 18:30:01 +00:00
// Make sure that comment is removed on alpha (it gets pushed since an admin from beta removed it)
2023-07-20 14:36:16 +00:00
let refetchedPostComments = await getPersonDetails (
2022-10-27 09:24:07 +00:00
alpha ,
2023-07-20 14:36:16 +00:00
commentRes . comment_view . comment . creator_id ,
2022-10-27 09:24:07 +00:00
) ;
2022-07-30 03:55:59 +00:00
expect ( refetchedPostComments . comments [ 0 ] . comment . removed ) . toBe ( true ) ;
2020-08-04 14:57:37 +00:00
2023-08-01 13:14:40 +00:00
// beta will unremove the comment
2020-08-06 18:30:01 +00:00
let unremoveCommentRes = await removeComment ( beta , false , betaCommentId ) ;
2020-12-20 21:16:57 +00:00
expect ( unremoveCommentRes . comment_view . comment . removed ) . toBe ( false ) ;
2020-08-04 14:57:37 +00:00
2023-08-01 13:14:40 +00:00
// Make sure that comment is unremoved on alpha
2022-10-27 09:24:07 +00:00
let refetchedPostComments2 = await getComments (
alpha ,
2023-08-01 13:14:40 +00:00
postOnAlphaRes . post_view . post . id ,
2022-10-27 09:24:07 +00:00
) ;
2022-07-30 03:55:59 +00:00
expect ( refetchedPostComments2 . comments [ 0 ] . comment . removed ) . toBe ( false ) ;
2020-12-20 21:16:57 +00:00
assertCommentFederation (
2022-07-30 03:55:59 +00:00
refetchedPostComments2 . comments [ 0 ] ,
2023-07-06 13:10:38 +00:00
unremoveCommentRes . comment_view ,
2020-12-20 21:16:57 +00:00
) ;
2020-08-06 18:30:01 +00:00
} ) ;
2022-10-27 09:24:07 +00:00
test ( "Remove a comment from admin and community on different instance" , async ( ) = > {
2022-06-02 14:33:41 +00:00
let alpha_user = await registerUser ( alpha ) ;
2020-08-06 18:30:01 +00:00
let newAlphaApi : API = {
2020-08-20 14:50:26 +00:00
client : alpha.client ,
2023-01-04 15:59:26 +00:00
auth : alpha_user.jwt ? ? "" ,
2020-08-06 18:30:01 +00:00
} ;
// New alpha user creates a community, post, and comment.
let newCommunity = await createCommunity ( newAlphaApi ) ;
2020-12-20 21:16:57 +00:00
let newPost = await createPost (
newAlphaApi ,
2023-07-06 13:10:38 +00:00
newCommunity . community_view . community . id ,
2020-12-20 21:16:57 +00:00
) ;
2023-01-04 15:59:26 +00:00
let commentRes = await createComment ( newAlphaApi , newPost . post_view . post . id ) ;
2020-12-20 21:16:57 +00:00
expect ( commentRes . comment_view . comment . content ) . toBeDefined ( ) ;
2020-08-06 18:30:01 +00:00
// Beta searches that to cache it, then removes it
2022-10-27 09:24:07 +00:00
let betaComment = (
await resolveComment ( beta , commentRes . comment_view . comment )
2023-01-04 15:59:26 +00:00
) . comment ;
if ( ! betaComment ) {
throw "beta comment missing" ;
}
2020-12-20 21:16:57 +00:00
let removeCommentRes = await removeComment (
beta ,
true ,
2023-07-06 13:10:38 +00:00
betaComment . comment . id ,
2020-12-20 21:16:57 +00:00
) ;
expect ( removeCommentRes . comment_view . comment . removed ) . toBe ( true ) ;
2020-08-06 18:30:01 +00:00
// Make sure its not removed on alpha
2022-10-27 09:24:07 +00:00
let refetchedPostComments = await getComments (
alpha ,
2023-07-06 13:10:38 +00:00
newPost . post_view . post . id ,
2022-10-27 09:24:07 +00:00
) ;
2022-07-30 03:55:59 +00:00
expect ( refetchedPostComments . comments [ 0 ] . comment . removed ) . toBe ( false ) ;
2022-10-27 09:24:07 +00:00
assertCommentFederation (
refetchedPostComments . comments [ 0 ] ,
2023-07-06 13:10:38 +00:00
commentRes . comment_view ,
2022-10-27 09:24:07 +00:00
) ;
2020-08-04 14:57:37 +00:00
} ) ;
2022-10-27 09:24:07 +00:00
test ( "Unlike a comment" , async ( ) = > {
2023-08-01 13:14:40 +00:00
let commentRes = await createComment ( alpha , postOnAlphaRes . post_view . post . id ) ;
2023-07-27 10:17:40 +00:00
// Lemmy automatically creates 1 like (vote) by author of comment.
// Make sure that comment is liked (voted up) on gamma, downstream peer
// This is testing replication from remote-home-remote (alpha-beta-gamma)
2023-09-09 16:25:03 +00:00
2023-07-27 10:17:40 +00:00
let gammaComment1 = (
2023-09-09 16:25:03 +00:00
await waitUntil (
( ) = > resolveComment ( gamma , commentRes . comment_view . comment ) ,
c = > c . comment ? . counts . score === 1 ,
)
2023-07-27 10:17:40 +00:00
) . comment ;
expect ( gammaComment1 ) . toBeDefined ( ) ;
expect ( gammaComment1 ? . community . local ) . toBe ( false ) ;
expect ( gammaComment1 ? . creator . local ) . toBe ( false ) ;
expect ( gammaComment1 ? . counts . score ) . toBe ( 1 ) ;
2020-12-20 21:16:57 +00:00
let unlike = await likeComment ( alpha , 0 , commentRes . comment_view . comment ) ;
expect ( unlike . comment_view . counts . score ) . toBe ( 0 ) ;
2020-08-04 14:57:37 +00:00
2023-07-27 10:17:40 +00:00
// Make sure that comment is unliked on beta
2022-10-27 09:24:07 +00:00
let betaComment = (
2023-09-09 16:25:03 +00:00
await waitUntil (
( ) = > resolveComment ( beta , commentRes . comment_view . comment ) ,
c = > c . comment ? . counts . score === 0 ,
)
2023-01-04 15:59:26 +00:00
) . comment ;
2020-08-04 14:57:37 +00:00
expect ( betaComment ) . toBeDefined ( ) ;
2023-01-04 15:59:26 +00:00
expect ( betaComment ? . community . local ) . toBe ( true ) ;
expect ( betaComment ? . creator . local ) . toBe ( false ) ;
expect ( betaComment ? . counts . score ) . toBe ( 0 ) ;
2023-07-27 10:17:40 +00:00
// Make sure that comment is unliked on gamma, downstream peer
// This is testing replication from remote-home-remote (alpha-beta-gamma)
let gammaComment = (
2023-09-09 16:25:03 +00:00
await waitUntil (
( ) = > resolveComment ( gamma , commentRes . comment_view . comment ) ,
c = > c . comment ? . counts . score === 0 ,
)
2023-07-27 10:17:40 +00:00
) . comment ;
expect ( gammaComment ) . toBeDefined ( ) ;
expect ( gammaComment ? . community . local ) . toBe ( false ) ;
expect ( gammaComment ? . creator . local ) . toBe ( false ) ;
expect ( gammaComment ? . counts . score ) . toBe ( 0 ) ;
2020-08-04 14:57:37 +00:00
} ) ;
2022-10-27 09:24:07 +00:00
test ( "Federated comment like" , async ( ) = > {
2023-08-01 13:14:40 +00:00
let commentRes = await createComment ( alpha , postOnAlphaRes . post_view . post . id ) ;
2023-09-09 16:25:03 +00:00
await waitUntil (
( ) = > resolveComment ( beta , commentRes . comment_view . comment ) ,
c = > c . comment ? . counts . score === 1 ,
) ;
2020-08-04 14:57:37 +00:00
// Find the comment on beta
2022-10-27 09:24:07 +00:00
let betaComment = (
await resolveComment ( beta , commentRes . comment_view . comment )
2023-01-04 15:59:26 +00:00
) . comment ;
if ( ! betaComment ) {
throw "Missing beta comment" ;
}
2020-08-04 14:57:37 +00:00
2020-12-20 21:16:57 +00:00
let like = await likeComment ( beta , 1 , betaComment . comment ) ;
expect ( like . comment_view . counts . score ) . toBe ( 2 ) ;
2020-08-04 14:57:37 +00:00
// Get the post from alpha, check the likes
2023-09-09 16:25:03 +00:00
let postComments = await waitUntil (
( ) = > getComments ( alpha , postOnAlphaRes . post_view . post . id ) ,
c = > c . comments [ 0 ] . counts . score === 2 ,
) ;
2022-07-30 03:55:59 +00:00
expect ( postComments . comments [ 0 ] . counts . score ) . toBe ( 2 ) ;
2020-08-04 14:57:37 +00:00
} ) ;
2023-08-01 13:14:40 +00:00
test ( "Reply to a comment from another instance, get notification" , async ( ) = > {
2023-09-09 16:25:03 +00:00
let betaCommunity = ( await resolveBetaCommunity ( alpha ) ) . community ;
if ( ! betaCommunity ) {
throw "Missing beta community" ;
}
const postOnAlphaRes = await createPost ( alpha , betaCommunity . community . id ) ;
2023-08-01 13:14:40 +00:00
// Create a root-level trunk-branch comment on alpha
let commentRes = await createComment ( alpha , postOnAlphaRes . post_view . post . id ) ;
// find that comment id on beta
2022-10-27 09:24:07 +00:00
let betaComment = (
await resolveComment ( beta , commentRes . comment_view . comment )
2023-01-04 15:59:26 +00:00
) . comment ;
if ( ! betaComment ) {
throw "Missing beta comment" ;
}
2020-08-04 14:57:37 +00:00
2023-08-01 13:14:40 +00:00
// Reply from beta, extending the branch
2020-12-20 21:16:57 +00:00
let replyRes = await createComment (
beta ,
betaComment . post . id ,
2023-07-06 13:10:38 +00:00
betaComment . comment . id ,
2020-12-20 21:16:57 +00:00
) ;
expect ( replyRes . comment_view . comment . content ) . toBeDefined ( ) ;
expect ( replyRes . comment_view . community . local ) . toBe ( true ) ;
expect ( replyRes . comment_view . creator . local ) . toBe ( true ) ;
2023-01-04 15:59:26 +00:00
expect ( getCommentParentId ( replyRes . comment_view . comment ) ) . toBe (
2023-07-06 13:10:38 +00:00
betaComment . comment . id ,
2022-10-27 09:24:07 +00:00
) ;
2020-12-20 21:16:57 +00:00
expect ( replyRes . comment_view . counts . score ) . toBe ( 1 ) ;
2020-08-04 14:57:37 +00:00
2023-08-01 13:14:40 +00:00
// Make sure that reply comment is seen on alpha
2020-08-04 14:57:37 +00:00
// TODO not sure why, but a searchComment back to alpha, for the ap_id of betas
// comment, isn't working.
// let searchAlpha = await searchComment(alpha, replyRes.comment);
2023-09-09 16:25:03 +00:00
let postComments = await waitUntil (
( ) = > getComments ( alpha , postOnAlphaRes . post_view . post . id ) ,
pc = > pc . comments . length >= 2 ,
) ;
// Note: this test fails when run twice and this count will differ
2023-08-01 13:14:40 +00:00
expect ( postComments . comments . length ) . toBeGreaterThanOrEqual ( 2 ) ;
2022-07-30 03:55:59 +00:00
let alphaComment = postComments . comments [ 0 ] ;
2020-12-20 21:16:57 +00:00
expect ( alphaComment . comment . content ) . toBeDefined ( ) ;
2023-09-09 16:25:03 +00:00
2023-01-04 15:59:26 +00:00
expect ( getCommentParentId ( alphaComment . comment ) ) . toBe (
2023-07-06 13:10:38 +00:00
postComments . comments [ 1 ] . comment . id ,
2022-10-27 09:24:07 +00:00
) ;
2020-12-20 21:16:57 +00:00
expect ( alphaComment . community . local ) . toBe ( false ) ;
expect ( alphaComment . creator . local ) . toBe ( false ) ;
expect ( alphaComment . counts . score ) . toBe ( 1 ) ;
assertCommentFederation ( alphaComment , replyRes . comment_view ) ;
2023-08-01 13:14:40 +00:00
// Did alpha get notified of the reply from beta?
2023-09-09 16:25:03 +00:00
let alphaUnreadCountRes = await waitUntil (
( ) = > getUnreadCount ( alpha ) ,
e = > e . replies >= 1 ,
) ;
2023-09-18 18:09:18 +00:00
expect ( alphaUnreadCountRes . replies ) . toBeGreaterThanOrEqual ( 1 ) ;
2023-08-01 13:14:40 +00:00
// check inbox of replies on alpha, fetching read/unread both
let alphaRepliesRes = await getReplies ( alpha ) ;
expect ( alphaRepliesRes . replies . length ) . toBe ( 1 ) ;
expect ( alphaRepliesRes . replies [ 0 ] . comment . content ) . toBeDefined ( ) ;
expect ( alphaRepliesRes . replies [ 0 ] . community . local ) . toBe ( false ) ;
expect ( alphaRepliesRes . replies [ 0 ] . creator . local ) . toBe ( false ) ;
expect ( alphaRepliesRes . replies [ 0 ] . counts . score ) . toBe ( 1 ) ;
// ToDo: interesting alphaRepliesRes.replies[0].comment_reply.id is 1, meaning? how did that come about?
expect ( alphaRepliesRes . replies [ 0 ] . comment . id ) . toBe ( alphaComment . comment . id ) ;
// this is a new notification, getReplies fetch was for read/unread both, confirm it is unread.
expect ( alphaRepliesRes . replies [ 0 ] . comment_reply . read ) . toBe ( false ) ;
assertCommentFederation ( alphaRepliesRes . replies [ 0 ] , replyRes . comment_view ) ;
2020-08-04 14:57:37 +00:00
} ) ;
2023-08-01 13:14:40 +00:00
test ( "Mention beta from alpha" , async ( ) = > {
2023-09-18 18:09:18 +00:00
if ( ! betaCommunity ) throw Error ( "no community" ) ;
const postOnAlphaRes = await createPost ( alpha , betaCommunity . community . id ) ;
2023-08-01 13:14:40 +00:00
// Create a new branch, trunk-level comment branch, from alpha instance
let commentRes = await createComment ( alpha , postOnAlphaRes . post_view . post . id ) ;
// Create a reply comment to previous comment, this has a mention in body
2022-10-27 09:24:07 +00:00
let mentionContent = "A test mention of @lemmy_beta@lemmy-beta:8551" ;
2020-08-04 14:57:37 +00:00
let mentionRes = await createComment (
alpha ,
2023-08-01 13:14:40 +00:00
postOnAlphaRes . post_view . post . id ,
2023-01-04 15:59:26 +00:00
commentRes . comment_view . comment . id ,
2023-07-06 13:10:38 +00:00
mentionContent ,
2020-08-04 14:57:37 +00:00
) ;
2020-12-20 21:16:57 +00:00
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 ) ;
2020-08-04 14:57:37 +00:00
2023-08-01 13:14:40 +00:00
// get beta's localized copy of the alpha post
let betaPost = ( await resolvePost ( beta , postOnAlphaRes . post_view . post ) ) . post ;
if ( ! betaPost ) {
throw "unable to locate post on beta" ;
}
expect ( betaPost . post . ap_id ) . toBe ( postOnAlphaRes . post_view . post . ap_id ) ;
expect ( betaPost . post . name ) . toBe ( postOnAlphaRes . post_view . post . name ) ;
// Make sure that both new comments are seen on beta and have parent/child relationship
2023-09-09 16:25:03 +00:00
let betaPostComments = await waitUntil (
( ) = > getComments ( beta , betaPost ! . post . id ) ,
2023-09-18 18:09:18 +00:00
c = > c . comments [ 1 ] ? . counts . score === 1 ,
2023-09-09 16:25:03 +00:00
) ;
2023-09-18 18:09:18 +00:00
expect ( betaPostComments . comments . length ) . toEqual ( 2 ) ;
2023-08-01 13:14:40 +00:00
// the trunk-branch root comment will be older than the mention reply comment, so index 1
let betaRootComment = betaPostComments . comments [ 1 ] ;
// the trunk-branch root comment should not have a parent
expect ( getCommentParentId ( betaRootComment . comment ) ) . toBeUndefined ( ) ;
expect ( betaRootComment . comment . content ) . toBeDefined ( ) ;
// the mention reply comment should have parent that points to the branch root level comment
expect ( getCommentParentId ( betaPostComments . comments [ 0 ] . comment ) ) . toBe (
betaPostComments . comments [ 1 ] . comment . id ,
) ;
expect ( betaRootComment . community . local ) . toBe ( true ) ;
expect ( betaRootComment . creator . local ) . toBe ( false ) ;
expect ( betaRootComment . counts . score ) . toBe ( 1 ) ;
assertCommentFederation ( betaRootComment , commentRes . comment_view ) ;
2020-08-04 14:57:37 +00:00
let mentionsRes = await getMentions ( beta ) ;
2020-12-20 21:16:57 +00:00
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 ) ;
2023-08-01 13:14:40 +00:00
// the reply comment with mention should be the most fresh, newest, index 0
expect ( mentionsRes . mentions [ 0 ] . person_mention . comment_id ) . toBe (
betaPostComments . comments [ 0 ] . comment . id ,
) ;
2020-08-04 14:57:37 +00:00
} ) ;
2022-10-27 09:24:07 +00:00
test ( "Comment Search" , async ( ) = > {
2023-08-01 13:14:40 +00:00
let commentRes = await createComment ( alpha , postOnAlphaRes . post_view . post . id ) ;
2022-10-27 09:24:07 +00:00
let betaComment = (
await resolveComment ( beta , commentRes . comment_view . comment )
2023-01-04 15:59:26 +00:00
) . comment ;
2021-08-23 15:25:39 +00:00
assertCommentFederation ( betaComment , commentRes . comment_view ) ;
2020-08-04 14:57:37 +00:00
} ) ;
2022-10-27 09:24:07 +00:00
test ( "A and G subscribe to B (center) A posts, G mentions B, it gets announced to A" , async ( ) = > {
2020-08-04 14:57:37 +00:00
// Create a local post
2023-01-04 15:59:26 +00:00
let alphaCommunity = ( await resolveCommunity ( alpha , "!main@lemmy-alpha:8541" ) )
. community ;
if ( ! alphaCommunity ) {
throw "Missing alpha community" ;
}
2022-10-13 16:30:31 +00:00
let alphaPost = await createPost ( alpha , alphaCommunity . community . id ) ;
2020-12-20 21:16:57 +00:00
expect ( alphaPost . post_view . community . local ) . toBe ( true ) ;
2020-08-04 14:57:37 +00:00
// Make sure gamma sees it
2023-01-04 15:59:26 +00:00
let gammaPost = ( await resolvePost ( gamma , alphaPost . post_view . post ) ) . post ;
if ( ! gammaPost ) {
throw "Missing gamma post" ;
}
2020-08-04 14:57:37 +00:00
let commentContent =
2022-10-27 09:24:07 +00:00
"A jest test federated comment announce, lets mention @lemmy_beta@lemmy-beta:8551" ;
2020-08-04 14:57:37 +00:00
let commentRes = await createComment (
gamma ,
2020-12-20 21:16:57 +00:00
gammaPost . post . id ,
2023-01-04 15:59:26 +00:00
undefined ,
2023-07-06 13:10:38 +00:00
commentContent ,
2020-08-04 14:57:37 +00:00
) ;
2020-12-20 21:16:57 +00:00
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 ) ;
2020-08-04 14:57:37 +00:00
// Make sure alpha sees it
2023-09-09 16:25:03 +00:00
let alphaPostComments2 = await waitUntil (
( ) = > getComments ( alpha , alphaPost . post_view . post . id ) ,
2023-09-18 17:04:46 +00:00
e = > e . comments [ 0 ] ? . counts . score === 1 ,
2022-10-27 09:24:07 +00:00
) ;
2022-07-30 03:55:59 +00:00
expect ( alphaPostComments2 . comments [ 0 ] . comment . content ) . toBe ( commentContent ) ;
expect ( alphaPostComments2 . comments [ 0 ] . community . local ) . toBe ( true ) ;
expect ( alphaPostComments2 . comments [ 0 ] . creator . local ) . toBe ( false ) ;
expect ( alphaPostComments2 . comments [ 0 ] . counts . score ) . toBe ( 1 ) ;
2022-10-27 09:24:07 +00:00
assertCommentFederation (
alphaPostComments2 . comments [ 0 ] ,
2023-07-06 13:10:38 +00:00
commentRes . comment_view ,
2022-10-27 09:24:07 +00:00
) ;
2020-08-04 14:57:37 +00:00
// Make sure beta has mentions
2023-09-09 16:25:03 +00:00
let relevantMention = await waitUntil (
( ) = >
getMentions ( beta ) . then ( m = >
m . mentions . find (
m = > m . comment . ap_id === commentRes . comment_view . comment . ap_id ,
) ,
) ,
e = > ! ! e ,
) ;
if ( ! relevantMention ) throw Error ( "could not find mention" ) ;
expect ( relevantMention . comment . content ) . toBe ( commentContent ) ;
expect ( relevantMention . community . local ) . toBe ( false ) ;
expect ( relevantMention . creator . local ) . toBe ( false ) ;
2020-08-04 14:57:37 +00:00
// TODO this is failing because fetchInReplyTos aren't getting score
// expect(mentionsRes.mentions[0].score).toBe(1);
} ) ;
2022-10-27 09:24:07 +00:00
test ( "Check that activity from another instance is sent to third instance" , async ( ) = > {
2021-10-28 20:46:24 +00:00
// Alpha and gamma users follow beta community
let alphaFollow = await followBeta ( alpha ) ;
2022-05-26 15:17:04 +00:00
expect ( alphaFollow . community_view . community . local ) . toBe ( false ) ;
2022-10-27 09:24:07 +00:00
expect ( alphaFollow . community_view . community . name ) . toBe ( "main" ) ;
2021-10-28 20:46:24 +00:00
let gammaFollow = await followBeta ( gamma ) ;
2022-05-26 15:17:04 +00:00
expect ( gammaFollow . community_view . community . local ) . toBe ( false ) ;
2022-10-27 09:24:07 +00:00
expect ( gammaFollow . community_view . community . name ) . toBe ( "main" ) ;
2023-09-09 16:25:03 +00:00
await waitUntil (
( ) = > resolveBetaCommunity ( alpha ) ,
c = > c . community ? . subscribed === "Subscribed" ,
) ;
await waitUntil (
( ) = > resolveBetaCommunity ( gamma ) ,
c = > c . community ? . subscribed === "Subscribed" ,
) ;
2021-10-28 20:46:24 +00:00
// Create a post on beta
let betaPost = await createPost ( beta , 2 ) ;
expect ( betaPost . post_view . community . local ) . toBe ( true ) ;
// Make sure gamma and alpha see it
2023-01-04 15:59:26 +00:00
let gammaPost = ( await resolvePost ( gamma , betaPost . post_view . post ) ) . post ;
if ( ! gammaPost ) {
throw "Missing gamma post" ;
}
2021-10-28 20:46:24 +00:00
expect ( gammaPost . post ) . toBeDefined ( ) ;
2023-01-04 15:59:26 +00:00
let alphaPost = ( await resolvePost ( alpha , betaPost . post_view . post ) ) . post ;
if ( ! alphaPost ) {
throw "Missing alpha post" ;
}
2021-10-28 20:46:24 +00:00
expect ( alphaPost . post ) . toBeDefined ( ) ;
// The bug: gamma comments, and alpha should see it.
2022-10-27 09:24:07 +00:00
let commentContent = "Comment from gamma" ;
2021-10-28 20:46:24 +00:00
let commentRes = await createComment (
gamma ,
gammaPost . post . id ,
2023-01-04 15:59:26 +00:00
undefined ,
2023-07-06 13:10:38 +00:00
commentContent ,
2021-10-28 20:46:24 +00:00
) ;
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 ) ;
// Make sure alpha sees it
2023-09-09 16:25:03 +00:00
let alphaPostComments2 = await waitUntil (
( ) = > getComments ( alpha , alphaPost ! . post . id ) ,
2023-09-18 17:30:02 +00:00
e = > e . comments [ 0 ] ? . counts . score === 1 ,
2023-09-09 16:25:03 +00:00
) ;
2022-07-30 03:55:59 +00:00
expect ( alphaPostComments2 . comments [ 0 ] . comment . content ) . toBe ( commentContent ) ;
expect ( alphaPostComments2 . comments [ 0 ] . community . local ) . toBe ( false ) ;
expect ( alphaPostComments2 . comments [ 0 ] . creator . local ) . toBe ( false ) ;
expect ( alphaPostComments2 . comments [ 0 ] . counts . score ) . toBe ( 1 ) ;
2022-10-27 09:24:07 +00:00
assertCommentFederation (
alphaPostComments2 . comments [ 0 ] ,
2023-07-06 13:10:38 +00:00
commentRes . comment_view ,
2022-10-27 09:24:07 +00:00
) ;
2021-10-28 20:46:24 +00:00
2023-09-18 16:29:08 +00:00
await Promise . all ( [ unfollowRemotes ( alpha ) , unfollowRemotes ( gamma ) ] ) ;
2021-10-28 20:46:24 +00:00
} ) ;
2022-10-27 09:24:07 +00:00
test ( "Fetch in_reply_tos: A is unsubbed from B, B makes a post, and some embedded comments, A subs to B, B updates the lowest level comment, A fetches both the post and all the inreplyto comments for that post." , async ( ) = > {
2020-08-04 14:57:37 +00:00
// Unfollow all remote communities
2021-08-19 20:54:15 +00:00
let site = await unfollowRemotes ( alpha ) ;
2020-08-04 14:57:37 +00:00
expect (
2023-07-06 13:10:38 +00:00
site . my_user ? . follows . filter ( c = > c . community . local == false ) . length ,
2020-08-04 14:57:37 +00:00
) . toBe ( 0 ) ;
// B creates a post, and two comments, should be invisible to A
2023-08-01 13:14:40 +00:00
let postOnBetaRes = await createPost ( beta , 2 ) ;
expect ( postOnBetaRes . post_view . post . name ) . toBeDefined ( ) ;
2020-08-04 14:57:37 +00:00
2022-10-27 09:24:07 +00:00
let parentCommentContent = "An invisible top level comment from beta" ;
2020-08-04 14:57:37 +00:00
let parentCommentRes = await createComment (
beta ,
2023-08-01 13:14:40 +00:00
postOnBetaRes . post_view . post . id ,
2023-01-04 15:59:26 +00:00
undefined ,
2023-07-06 13:10:38 +00:00
parentCommentContent ,
2020-08-04 14:57:37 +00:00
) ;
2020-12-20 21:16:57 +00:00
expect ( parentCommentRes . comment_view . comment . content ) . toBe (
2023-07-06 13:10:38 +00:00
parentCommentContent ,
2020-12-20 21:16:57 +00:00
) ;
2020-08-04 14:57:37 +00:00
// B creates a comment, then a child one of that.
2022-10-27 09:24:07 +00:00
let childCommentContent = "An invisible child comment from beta" ;
2020-08-04 14:57:37 +00:00
let childCommentRes = await createComment (
beta ,
2023-08-01 13:14:40 +00:00
postOnBetaRes . post_view . post . id ,
2023-01-04 15:59:26 +00:00
parentCommentRes . comment_view . comment . id ,
2023-07-06 13:10:38 +00:00
childCommentContent ,
2020-12-20 21:16:57 +00:00
) ;
expect ( childCommentRes . comment_view . comment . content ) . toBe (
2023-07-06 13:10:38 +00:00
childCommentContent ,
2020-08-04 14:57:37 +00:00
) ;
// Follow beta again
let follow = await followBeta ( alpha ) ;
2022-05-26 15:17:04 +00:00
expect ( follow . community_view . community . local ) . toBe ( false ) ;
2022-10-27 09:24:07 +00:00
expect ( follow . community_view . community . name ) . toBe ( "main" ) ;
2020-08-04 14:57:37 +00:00
// An update to the child comment on beta, should push the post, parent, and child to alpha now
2023-01-04 15:59:26 +00:00
let updatedCommentContent = "An update child comment from beta" ;
2020-12-20 21:16:57 +00:00
let updateRes = await editComment (
2020-08-04 14:57:37 +00:00
beta ,
2020-12-20 21:16:57 +00:00
childCommentRes . comment_view . comment . id ,
2023-07-06 13:10:38 +00:00
updatedCommentContent ,
2020-08-04 14:57:37 +00:00
) ;
2023-01-04 15:59:26 +00:00
expect ( updateRes . comment_view . comment . content ) . toBe ( updatedCommentContent ) ;
2020-08-04 14:57:37 +00:00
// Get the post from alpha
2023-08-01 13:14:40 +00:00
let alphaPostB = ( await resolvePost ( alpha , postOnBetaRes . post_view . post ) )
. post ;
2023-01-04 15:59:26 +00:00
if ( ! alphaPostB ) {
throw "Missing alpha post B" ;
}
2020-08-31 13:48:02 +00:00
2020-12-20 21:16:57 +00:00
let alphaPost = await getPost ( alpha , alphaPostB . post . id ) ;
2023-09-09 16:25:03 +00:00
let alphaPostComments = await waitUntil (
( ) = > getComments ( alpha , alphaPostB ! . post . id ) ,
c = >
c . comments [ 1 ] ? . comment . content ===
2023-09-18 16:29:08 +00:00
parentCommentRes . comment_view . comment . content &&
c . comments [ 0 ] ? . comment . content === updateRes . comment_view . comment . content ,
2023-09-09 16:25:03 +00:00
) ;
2020-12-20 21:16:57 +00:00
expect ( alphaPost . post_view . post . name ) . toBeDefined ( ) ;
2022-10-27 09:24:07 +00:00
assertCommentFederation (
alphaPostComments . comments [ 1 ] ,
2023-07-06 13:10:38 +00:00
parentCommentRes . comment_view ,
2022-10-27 09:24:07 +00:00
) ;
assertCommentFederation (
alphaPostComments . comments [ 0 ] ,
2023-07-06 13:10:38 +00:00
updateRes . comment_view ,
2022-10-27 09:24:07 +00:00
) ;
2020-12-20 21:16:57 +00:00
expect ( alphaPost . post_view . community . local ) . toBe ( false ) ;
expect ( alphaPost . post_view . creator . local ) . toBe ( false ) ;
2020-12-17 19:23:15 +00:00
await unfollowRemotes ( alpha ) ;
2020-08-04 14:57:37 +00:00
} ) ;
2021-10-15 14:37:33 +00:00
2022-10-27 09:24:07 +00:00
test ( "Report a comment" , async ( ) = > {
2023-01-04 15:59:26 +00:00
let betaCommunity = ( await resolveBetaCommunity ( beta ) ) . community ;
if ( ! betaCommunity ) {
throw "Missing beta community" ;
}
2023-08-01 13:14:40 +00:00
let postOnBetaRes = ( await createPost ( beta , betaCommunity . community . id ) )
. post_view . post ;
expect ( postOnBetaRes ) . toBeDefined ( ) ;
let commentRes = ( await createComment ( beta , postOnBetaRes . id ) ) . comment_view
. comment ;
2021-10-15 14:37:33 +00:00
expect ( commentRes ) . toBeDefined ( ) ;
2023-01-04 15:59:26 +00:00
let alphaComment = ( await resolveComment ( alpha , commentRes ) ) . comment ? . comment ;
if ( ! alphaComment ) {
throw "Missing alpha comment" ;
}
2023-09-18 18:09:18 +00:00
const reason = randomString ( 10 ) ;
let alphaReport = ( await reportComment ( alpha , alphaComment . id , reason ) )
. comment_report_view . comment_report ;
2021-10-15 14:37:33 +00:00
2023-09-18 18:09:18 +00:00
let betaReport = ( await waitUntil (
( ) = >
listCommentReports ( beta ) . then ( r = >
r . comment_reports . find ( rep = > rep . comment_report . reason === reason ) ,
) ,
e = > ! ! e ,
) ) ! . comment_report ;
2021-10-15 14:37:33 +00:00
expect ( betaReport ) . toBeDefined ( ) ;
expect ( betaReport . resolved ) . toBe ( false ) ;
2022-10-27 09:24:07 +00:00
expect ( betaReport . original_comment_text ) . toBe (
2023-07-06 13:10:38 +00:00
alphaReport . original_comment_text ,
2022-10-27 09:24:07 +00:00
) ;
2021-10-15 14:37:33 +00:00
expect ( betaReport . reason ) . toBe ( alphaReport . reason ) ;
2021-10-28 20:46:24 +00:00
} ) ;