From bb51fe075a81d8d8e3bf1c4b03d5c5885ed52048 Mon Sep 17 00:00:00 2001 From: YashRE42 <33805964+YashRE42@users.noreply.github.com> Date: Fri, 19 Mar 2021 17:11:04 +0000 Subject: [PATCH] message_flags: Verify early return from send_read on_sucess. --- frontend_tests/node_tests/message_flags.js | 28 ++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/frontend_tests/node_tests/message_flags.js b/frontend_tests/node_tests/message_flags.js index 4d792b92e2..df7b075f5d 100644 --- a/frontend_tests/node_tests/message_flags.js +++ b/frontend_tests/node_tests/message_flags.js @@ -167,6 +167,34 @@ run_test("read", (override) => { }); }); +run_test("read_empty_data", (override) => { + // Way to capture posted info in every request + let channel_post_opts; + override(channel, "post", (opts) => { + channel_post_opts = opts; + }); + + // For testing purpose limit the batch size value to 5 instead of 1000 + function send_read(messages) { + with_field(message_flags, "_unread_batch_size", 5, () => { + message_flags.send_read(messages); + }); + } + + // send read to obtain success callback + send_read({locally_echoed: false, id: 1}); + + // verify early return on empty data + const success_callback = channel_post_opts.success; + channel_post_opts = {}; + let empty_data; + success_callback(empty_data); + assert.deepEqual(channel_post_opts, {}); + empty_data = {messages: undefined}; + success_callback(empty_data); + assert.deepEqual(channel_post_opts, {}); +}); + run_test("collapse_and_uncollapse", (override) => { // Way to capture posted info in every request let channel_post_opts;