From b9611489caebffe19b1cf78f7c069013fb4e54bb Mon Sep 17 00:00:00 2001 From: Hardik Dharmani Date: Fri, 5 May 2023 19:58:06 +0530 Subject: [PATCH] node_tests: Extend unread.test.js to catch private message mentions bug. In the "mentions" test, an additional unread message with the type "private" and directly mentioning me has been added. This test case checks for the scenario when the stream_id is null during the reverse_lookup, which would have caused the test to fail before the bug fix was implemented which now passes after the fix is applied. --- web/tests/unread.test.js | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/web/tests/unread.test.js b/web/tests/unread.test.js index 770d658186..079c19ea84 100644 --- a/web/tests/unread.test.js +++ b/web/tests/unread.test.js @@ -24,7 +24,14 @@ const me = { user_id: 30, full_name: "Me Myself", }; + +const anybody = { + email: "anybody@example.com", + user_id: 999, + full_name: "Any Body", +}; people.add_active_user(me); +people.add_active_user(anybody); people.initialize_current_user(me.user_id); const social = { @@ -382,13 +389,6 @@ test("private_messages", () => { let counts = unread.get_counts(); assert.equal(counts.private_message_count, 0); - const anybody = { - email: "anybody@example.com", - user_id: 999, - full_name: "Any Body", - }; - people.add_active_user(anybody); - const message = { id: 15, type: "private", @@ -527,32 +527,45 @@ test("mentions", () => { unread: true, }; + const private_mention_me_message = { + id: 19, + type: "private", + display_recipient: [{id: anybody.user_id}], + mentioned: true, + mentioned_me_directly: true, + unread: true, + }; + unread.process_loaded_messages([ already_read_message, mention_me_message, mention_all_message, muted_mention_all_message, muted_direct_mention_message, + private_mention_me_message, ]); counts = unread.get_counts(); - assert.equal(counts.mentioned_message_count, 3); + assert.equal(counts.mentioned_message_count, 4); assert.deepEqual(unread.get_msg_ids_for_mentions(), [ mention_me_message.id, mention_all_message.id, muted_direct_mention_message.id, + private_mention_me_message.id, ]); assert.deepEqual(unread.get_all_msg_ids(), [ mention_me_message.id, mention_all_message.id, muted_mention_all_message.id, muted_direct_mention_message.id, + private_mention_me_message.id, ]); - test_notifiable_count(counts.home_unread_messages, 3); + test_notifiable_count(counts.home_unread_messages, 5); unread.mark_as_read(mention_me_message.id); unread.mark_as_read(mention_all_message.id); unread.mark_as_read(muted_direct_mention_message.id); + unread.mark_as_read(private_mention_me_message.id); counts = unread.get_counts(); assert.equal(counts.mentioned_message_count, 0); test_notifiable_count(counts.home_unread_messages, 0);