getCommentParentId,
resolveCommunity,
getPersonDetails,
+ getReplies,
+ getUnreadCount,
} from "./shared";
import { CommentView } from "lemmy-js-client/dist/types/CommentView";
-let postRes: PostResponse;
+let postOnAlphaRes: PostResponse;
beforeAll(async () => {
await setupLogins();
await followBeta(gamma);
let betaCommunity = (await resolveBetaCommunity(alpha)).community;
if (betaCommunity) {
- postRes = await createPost(alpha, betaCommunity.community.id);
+ postOnAlphaRes = await createPost(alpha, betaCommunity.community.id);
}
});
}
test("Create a comment", async () => {
- let commentRes = await createComment(alpha, postRes.post_view.post.id);
+ let commentRes = await createComment(alpha, postOnAlphaRes.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);
});
test("Update a comment", async () => {
- let commentRes = await createComment(alpha, postRes.post_view.post.id);
+ let commentRes = await createComment(alpha, postOnAlphaRes.post_view.post.id);
// Federate the comment first
let betaComment = (
await resolveComment(beta, commentRes.comment_view.comment)
test("Delete a comment", async () => {
// creating a comment on alpha (remote from home of community)
- let commentRes = await createComment(alpha, postRes.post_view.post.id);
+ let commentRes = await createComment(alpha, postOnAlphaRes.post_view.post.id);
// Find the comment on beta (home of community)
let betaComment = (
});
test.skip("Remove a comment from admin and community on the same instance", async () => {
- let commentRes = await createComment(alpha, postRes.post_view.post.id);
+ let commentRes = await createComment(alpha, postOnAlphaRes.post_view.post.id);
// Get the id for beta
let betaCommentId = (
);
expect(refetchedPostComments.comments[0].comment.removed).toBe(true);
+ // beta will unremove the comment
let unremoveCommentRes = await removeComment(beta, false, betaCommentId);
expect(unremoveCommentRes.comment_view.comment.removed).toBe(false);
- // Make sure that comment is unremoved on beta
+ // Make sure that comment is unremoved on alpha
let refetchedPostComments2 = await getComments(
alpha,
- postRes.post_view.post.id,
+ postOnAlphaRes.post_view.post.id,
);
expect(refetchedPostComments2.comments[0].comment.removed).toBe(false);
assertCommentFederation(
});
test("Unlike a comment", async () => {
- let commentRes = await createComment(alpha, postRes.post_view.post.id);
+ let commentRes = await createComment(alpha, postOnAlphaRes.post_view.post.id);
// Lemmy automatically creates 1 like (vote) by author of comment.
// Make sure that comment is liked (voted up) on gamma, downstream peer
});
test("Federated comment like", async () => {
- let commentRes = await createComment(alpha, postRes.post_view.post.id);
+ let commentRes = await createComment(alpha, postOnAlphaRes.post_view.post.id);
// Find the comment on beta
let betaComment = (
expect(like.comment_view.counts.score).toBe(2);
// Get the post from alpha, check the likes
- let postComments = await getComments(alpha, postRes.post_view.post.id);
+ let postComments = await getComments(alpha, postOnAlphaRes.post_view.post.id);
expect(postComments.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_view.post.id);
+test("Reply to a comment from another instance, get notification", async () => {
+ // 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
let betaComment = (
await resolveComment(beta, commentRes.comment_view.comment)
).comment;
throw "Missing beta comment";
}
- // find that comment id on beta
-
- // Reply from beta
+ // Reply from beta, extending the branch
let replyRes = await createComment(
beta,
betaComment.post.id,
);
expect(replyRes.comment_view.counts.score).toBe(1);
- // Make sure that comment is seen on alpha
+ // Make sure that reply comment is seen on alpha
// 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);
- let postComments = await getComments(alpha, postRes.post_view.post.id);
+ let postComments = await getComments(alpha, postOnAlphaRes.post_view.post.id);
+ // Note: in Lemmy 0.18.3 pre-release this is coming up 7
+ expect(postComments.comments.length).toBeGreaterThanOrEqual(2);
let alphaComment = postComments.comments[0];
expect(alphaComment.comment.content).toBeDefined();
expect(getCommentParentId(alphaComment.comment)).toBe(
expect(alphaComment.creator.local).toBe(false);
expect(alphaComment.counts.score).toBe(1);
assertCommentFederation(alphaComment, replyRes.comment_view);
+
+ // Did alpha get notified of the reply from beta?
+ let alphaUnreadCountRes = await getUnreadCount(alpha);
+ expect(alphaUnreadCountRes.replies).toBe(1);
+
+ // 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);
});
-test("Mention beta", async () => {
- // Create a mention on alpha
+test("Mention beta from alpha", async () => {
+ // 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
let mentionContent = "A test mention of @lemmy_beta@lemmy-beta:8551";
- let commentRes = await createComment(alpha, postRes.post_view.post.id);
let mentionRes = await createComment(
alpha,
- postRes.post_view.post.id,
+ postOnAlphaRes.post_view.post.id,
commentRes.comment_view.comment.id,
mentionContent,
);
expect(mentionRes.comment_view.creator.local).toBe(true);
expect(mentionRes.comment_view.counts.score).toBe(1);
+ // 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
+ let betaPostComments = await getComments(beta, betaPost.post.id);
+ expect(betaPostComments.comments.length).toBeGreaterThanOrEqual(2);
+ // 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);
+
let mentionsRes = await getMentions(beta);
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);
+ // 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,
+ );
});
test("Comment Search", async () => {
- let commentRes = await createComment(alpha, postRes.post_view.post.id);
+ let commentRes = await createComment(alpha, postOnAlphaRes.post_view.post.id);
let betaComment = (
await resolveComment(beta, commentRes.comment_view.comment)
).comment;
).toBe(0);
// B creates a post, and two comments, should be invisible to A
- let postRes = await createPost(beta, 2);
- expect(postRes.post_view.post.name).toBeDefined();
+ let postOnBetaRes = await createPost(beta, 2);
+ expect(postOnBetaRes.post_view.post.name).toBeDefined();
let parentCommentContent = "An invisible top level comment from beta";
let parentCommentRes = await createComment(
beta,
- postRes.post_view.post.id,
+ postOnBetaRes.post_view.post.id,
undefined,
parentCommentContent,
);
let childCommentContent = "An invisible child comment from beta";
let childCommentRes = await createComment(
beta,
- postRes.post_view.post.id,
+ postOnBetaRes.post_view.post.id,
parentCommentRes.comment_view.comment.id,
childCommentContent,
);
expect(updateRes.comment_view.comment.content).toBe(updatedCommentContent);
// Get the post from alpha
- let alphaPostB = (await resolvePost(alpha, postRes.post_view.post)).post;
+ let alphaPostB = (await resolvePost(alpha, postOnBetaRes.post_view.post))
+ .post;
if (!alphaPostB) {
throw "Missing alpha post B";
}
if (!betaCommunity) {
throw "Missing beta community";
}
- let postRes = (await createPost(beta, betaCommunity.community.id)).post_view
- .post;
- expect(postRes).toBeDefined();
- let commentRes = (await createComment(beta, postRes.id)).comment_view.comment;
+ let postOnBetaRes = (await createPost(beta, betaCommunity.community.id))
+ .post_view.post;
+ expect(postOnBetaRes).toBeDefined();
+ let commentRes = (await createComment(beta, postOnBetaRes.id)).comment_view
+ .comment;
expect(commentRes).toBeDefined();
let alphaComment = (await resolveComment(alpha, commentRes)).comment?.comment;