Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
recent_topics: Test deleting messages not stored locally.
Aman Agrawald9814e5e1dbb
diff --git a/frontend_tests/node_tests/recent_senders.js b/frontend_tests/node_tests/recent_senders.jsindex 406db848f81..b5dd2fc1578 100644--- a/frontend_tests/node_tests/recent_senders.js+++ b/frontend_tests/node_tests/recent_senders.js@@ -5,13 +5,17 @@ const rs = zrequire("recent_senders");let next_id = 0;const messages = [];-set_global("message_util", {- get_messages_in_topic: (stream_id, topic) =>- messages.filter(- (x) => x.stream_id === stream_id && x.topic.toLowerCase() === topic.toLowerCase(),- ),+set_global("message_store", {+ get: (msg_id) => messages[msg_id - 1],});-+set_global("message_list", {+ all: {+ all_messages() {+ return messages;+ },+ },+});+zrequire("message_util.js");run_test("process_message_for_senders", () => {const stream1 = 1;const stream2 = 2;@@ -197,14 +201,24 @@ run_test("process_message_for_senders", () => {assert.equal(rs.get_topic_recent_senders(stream4, topic3).toString(), "");assert.equal(rs.get_topic_recent_senders(stream5, topic4).toString(), "2,3");- set_global("message_store", {- get: () => message1,+ set_global("message_list", {+ all: {+ all_messages() {+ // messages[0] (message1) and messages[4] (message5) were removed.+ const reduced_msgs = [...messages];+ reduced_msgs.splice(4, 1);+ reduced_msgs.splice(0, 1);+ return reduced_msgs;+ },+ },});-assert.equal(rs.get_topic_recent_senders(stream1, topic1).toString(), "2,1");// delete message1 and message5 sent by sender1- messages.splice(4, 1);- messages.splice(0, 1);rs.update_topics_of_deleted_message_ids([message1.id, message5.id]);assert.equal(rs.get_topic_recent_senders(stream1, topic1).toString(), "2");++ // deleting an old message which isn't locally stored.+ // We are just testing that it doesn't raise an error;+ // no changes should take place in this case.+ rs.update_topics_of_deleted_message_ids([-1]);});diff --git a/frontend_tests/node_tests/recent_topics.js b/frontend_tests/node_tests/recent_topics.jsindex c1d6c16ba87..0405bde075b 100644--- a/frontend_tests/node_tests/recent_topics.js+++ b/frontend_tests/node_tests/recent_topics.js@@ -679,6 +679,9 @@ run_test("test_delete_messages", () => {Array.from(all_topics.keys()).toString(),"4:topic-10,1:topic-7,1:topic-6,1:topic-5,1:topic-4,1:topic-3",);+ // test deleting a message which is not locally+ // stored, doesn't raise any errors.+ rt.update_topics_of_deleted_message_ids([-1]);});run_test("test_topic_edit", () => {diff --git a/tools/test-js-with-node b/tools/test-js-with-nodeindex 06bc1a0ebb2..4d4287a8758 100755--- a/tools/test-js-with-node+++ b/tools/test-js-with-node@@ -97,7 +97,6 @@ EXEMPT_FILES = {'static/js/ready.js','static/js/realm_icon.js','static/js/realm_logo.js',- 'static/js/recent_senders.js','static/js/recent_topics.js','static/js/reload.js','static/js/reload_state.js',