Skip to content

Commit

Permalink
Merge pull request #236 from LemmyNet/main
Browse files Browse the repository at this point in the history
[pull] master from LemmyNet:main
  • Loading branch information
pull[bot] authored Jan 15, 2025
2 parents 3754584 + 3f06317 commit ee42d96
Show file tree
Hide file tree
Showing 79 changed files with 2,253 additions and 1,597 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api_tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"eslint": "^9.18.0",
"eslint-plugin-prettier": "^5.1.3",
"jest": "^29.5.0",
"lemmy-js-client": "0.20.0-modlog-combined.0",
"lemmy-js-client": "0.20.0-inbox-combined.1",
"prettier": "^3.4.2",
"ts-jest": "^29.1.0",
"typescript": "^5.7.3",
Expand Down
10 changes: 5 additions & 5 deletions api_tests/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

75 changes: 39 additions & 36 deletions api_tests/src/comment.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
editComment,
deleteComment,
removeComment,
getMentions,
resolvePost,
unfollowRemotes,
createCommunity,
Expand All @@ -27,7 +26,6 @@ import {
getComments,
getCommentParentId,
resolveCommunity,
getReplies,
getUnreadCount,
waitUntil,
waitForPost,
Expand All @@ -38,11 +36,14 @@ import {
saveUserSettings,
listReports,
listPersonContent,
listInbox,
} from "./shared";
import {
CommentReplyView,
CommentReportView,
CommentView,
CommunityView,
PersonCommentMentionView,
ReportCombinedView,
SaveUserSettings,
} from "lemmy-js-client";
Expand Down Expand Up @@ -356,7 +357,7 @@ test("Federated comment like", async () => {
});

test("Reply to a comment from another instance, get notification", async () => {
await alpha.markAllAsRead();
await alpha.markAllNotificationsAsRead();

let betaCommunity = (
await waitUntil(
Expand Down Expand Up @@ -423,18 +424,18 @@ test("Reply to a comment from another instance, get notification", async () => {
// Did alpha get notified of the reply from beta?
let alphaUnreadCountRes = await waitUntil(
() => getUnreadCount(alpha),
e => e.replies >= 1,
e => e.count >= 1,
);
expect(alphaUnreadCountRes.replies).toBeGreaterThanOrEqual(1);
expect(alphaUnreadCountRes.count).toBeGreaterThanOrEqual(1);

// check inbox of replies on alpha, fetching read/unread both
let alphaRepliesRes = await waitUntil(
() => getReplies(alpha),
r => r.replies.length > 0,
);
const alphaReply = alphaRepliesRes.replies.find(
r => r.comment.id === alphaComment.comment.id,
() => listInbox(alpha, "CommentReply"),
r => r.inbox.length > 0,
);
const alphaReply = alphaRepliesRes.inbox.find(
r => r.type_ == "CommentReply" && r.comment.id === alphaComment.comment.id,
) as CommentReplyView | undefined;
expect(alphaReply).toBeDefined();
if (!alphaReply) throw Error();
expect(alphaReply.comment.content).toBeDefined();
Expand Down Expand Up @@ -463,7 +464,7 @@ test("Bot reply notifications are filtered when bots are hidden", async () => {
throw "Missing alpha community";
}

await alpha.markAllAsRead();
await alpha.markAllNotificationsAsRead();
form = {
show_bot_accounts: false,
};
Expand All @@ -478,10 +479,7 @@ test("Bot reply notifications are filtered when bots are hidden", async () => {
expect(commentRes).toBeDefined();

let alphaUnreadCountRes = await getUnreadCount(alpha);
expect(alphaUnreadCountRes.replies).toBe(0);

let alphaUnreadRepliesRes = await getReplies(alpha, true);
expect(alphaUnreadRepliesRes.replies.length).toBe(0);
expect(alphaUnreadCountRes.count).toBe(0);

// This both restores the original state that may be expected by other tests
// implicitly and is used by the next steps to ensure replies are still
Expand All @@ -492,16 +490,16 @@ test("Bot reply notifications are filtered when bots are hidden", async () => {
await saveUserSettings(alpha, form);

alphaUnreadCountRes = await getUnreadCount(alpha);
expect(alphaUnreadCountRes.replies).toBe(1);
expect(alphaUnreadCountRes.count).toBe(1);

alphaUnreadRepliesRes = await getReplies(alpha, true);
expect(alphaUnreadRepliesRes.replies.length).toBe(1);
expect(alphaUnreadRepliesRes.replies[0].comment.id).toBe(
let alphaUnreadRepliesRes = await listInbox(alpha, "CommentReply", true);
expect(alphaUnreadRepliesRes.inbox.length).toBe(1);
expect((alphaUnreadRepliesRes.inbox[0] as CommentReplyView).comment.id).toBe(
commentRes.comment_view.comment.id,
);
});

test("Mention beta from alpha", async () => {
test("Mention beta from alpha comment", async () => {
if (!betaCommunity) throw Error("no community");
const postOnAlphaRes = await createPost(alpha, betaCommunity.community.id);
// Create a new branch, trunk-level comment branch, from alpha instance
Expand Down Expand Up @@ -548,15 +546,17 @@ test("Mention beta from alpha", async () => {
assertCommentFederation(betaRootComment, commentRes.comment_view);

let mentionsRes = await waitUntil(
() => getMentions(beta),
m => !!m.mentions[0],
() => listInbox(beta, "CommentMention"),
m => !!m.inbox[0],
);
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);

const firstMention = mentionsRes.inbox[0] as PersonCommentMentionView;
expect(firstMention.comment.content).toBeDefined();
expect(firstMention.community.local).toBe(true);
expect(firstMention.creator.local).toBe(false);
expect(firstMention.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(
expect(firstMention.person_comment_mention.comment_id).toBe(
betaPostComments.comments[0].comment.id,
);
});
Expand Down Expand Up @@ -623,15 +623,17 @@ test("A and G subscribe to B (center) A posts, G mentions B, it gets announced t
);

// Make sure beta has mentions
let relevantMention = await waitUntil(
let relevantMention = (await waitUntil(
() =>
getMentions(beta).then(m =>
m.mentions.find(
m => m.comment.ap_id === commentRes.comment_view.comment.ap_id,
listInbox(beta, "CommentMention").then(m =>
m.inbox.find(
m =>
m.type_ == "CommentMention" &&
m.comment.ap_id === commentRes.comment_view.comment.ap_id,
),
),
e => !!e,
);
)) as PersonCommentMentionView | undefined;
if (!relevantMention) throw Error("could not find mention");
expect(relevantMention.comment.content).toBe(commentContent);
expect(relevantMention.community.local).toBe(false);
Expand Down Expand Up @@ -824,6 +826,7 @@ test("Report a comment", async () => {
});

test("Dont send a comment reply to a blocked community", async () => {
await beta.markAllNotificationsAsRead();
let newCommunity = await createCommunity(beta);
let newCommunityId = newCommunity.community_view.community.id;

Expand All @@ -837,7 +840,7 @@ test("Dont send a comment reply to a blocked community", async () => {

// Check beta's inbox count
let unreadCount = await getUnreadCount(beta);
expect(unreadCount.replies).toBe(1);
expect(unreadCount.count).toBe(0);

// Beta blocks the new beta community
let blockRes = await blockCommunity(beta, newCommunityId, true);
Expand All @@ -857,10 +860,10 @@ test("Dont send a comment reply to a blocked community", async () => {

// Check beta's inbox count, make sure it stays the same
unreadCount = await getUnreadCount(beta);
expect(unreadCount.replies).toBe(1);
expect(unreadCount.count).toBe(0);

let replies = await getReplies(beta);
expect(replies.replies.length).toBe(1);
let replies = await listInbox(beta, "CommentReply", true);
expect(replies.inbox.length).toBe(0);

// Unblock the community
blockRes = await blockCommunity(beta, newCommunityId, false);
Expand Down
4 changes: 0 additions & 4 deletions api_tests/src/image.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ test("Upload image and delete it", async () => {
const upload = await alphaImage.uploadImage(upload_form);
expect(upload.image_url).toBeDefined();
expect(upload.filename).toBeDefined();
expect(upload.delete_token).toBeDefined();

// ensure that image download is working. theres probably a better way to do this
const response = await fetch(upload.image_url ?? "");
Expand All @@ -82,7 +81,6 @@ test("Upload image and delete it", async () => {

// delete image
const delete_form: DeleteImageParams = {
token: upload.delete_token,
filename: upload.filename,
};
const delete_ = await alphaImage.deleteImage(delete_form);
Expand Down Expand Up @@ -113,7 +111,6 @@ test("Purge user, uploaded image removed", async () => {
};
const upload = await user.uploadImage(upload_form);
expect(upload.filename).toBeDefined();
expect(upload.delete_token).toBeDefined();
expect(upload.image_url).toBeDefined();

// ensure that image download is working. theres probably a better way to do this
Expand Down Expand Up @@ -144,7 +141,6 @@ test("Purge post, linked image removed", async () => {
};
const upload = await user.uploadImage(upload_form);
expect(upload.filename).toBeDefined();
expect(upload.delete_token).toBeDefined();
expect(upload.image_url).toBeDefined();

// ensure that image download is working. theres probably a better way to do this
Expand Down
40 changes: 40 additions & 0 deletions api_tests/src/post.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@ import {
createCommunity,
listReports,
getMyUser,
listInbox,
} from "./shared";
import { PostView } from "lemmy-js-client/dist/types/PostView";
import { AdminBlockInstanceParams } from "lemmy-js-client/dist/types/AdminBlockInstanceParams";
import {
EditSite,
PersonPostMentionView,
PostReport,
PostReportView,
ReportCombinedView,
Expand Down Expand Up @@ -799,6 +801,44 @@ test("Fetch post with redirect", async () => {
expect(gammaPost2.post).toBeDefined();
});

test("Mention beta from alpha post body", async () => {
if (!betaCommunity) throw Error("no community");
let mentionContent = "A test mention of @lemmy_beta@lemmy-beta:8551";

const postOnAlphaRes = await createPost(
alpha,
betaCommunity.community.id,
undefined,
mentionContent,
);

expect(postOnAlphaRes.post_view.post.body).toBeDefined();
expect(postOnAlphaRes.post_view.community.local).toBe(false);
expect(postOnAlphaRes.post_view.creator.local).toBe(true);
expect(postOnAlphaRes.post_view.counts.score).toBe(1);

// get beta's localized copy of the alpha post
let betaPost = await waitForPost(beta, postOnAlphaRes.post_view.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);
await assertPostFederation(betaPost, postOnAlphaRes.post_view);

let mentionsRes = await waitUntil(
() => listInbox(beta, "PostMention"),
m => !!m.inbox[0],
);

const firstMention = mentionsRes.inbox[0] as PersonPostMentionView;
expect(firstMention.post.body).toBeDefined();
expect(firstMention.community.local).toBe(true);
expect(firstMention.creator.local).toBe(false);
expect(firstMention.counts.score).toBe(1);
expect(firstMention.person_post_mention.post_id).toBe(betaPost.post.id);
});

test("Rewrite markdown links", async () => {
const community = (await resolveBetaCommunity(beta)).community!;

Expand Down
Loading

0 comments on commit ee42d96

Please sign in to comment.