2020-08-01 03:43:15 +02:00
|
|
|
"use strict";
|
|
|
|
|
2020-11-30 23:46:45 +01:00
|
|
|
const {strict: assert} = require("assert");
|
|
|
|
|
2020-07-25 02:02:35 +02:00
|
|
|
const _ = require("lodash");
|
|
|
|
|
2021-03-30 02:21:21 +02:00
|
|
|
const {zrequire} = require("../zjsunit/namespace");
|
2020-12-01 00:39:47 +01:00
|
|
|
const {run_test} = require("../zjsunit/test");
|
2021-03-25 22:35:45 +01:00
|
|
|
const {page_params} = require("../zjsunit/zpage_params");
|
2020-12-01 00:02:16 +01:00
|
|
|
|
2021-03-25 22:35:45 +01:00
|
|
|
page_params.realm_push_notifications_enabled = false;
|
2013-07-28 18:40:50 +02:00
|
|
|
|
2021-03-07 13:57:14 +01:00
|
|
|
const {FoldDict} = zrequire("fold_dict");
|
node tests: Introduce message_store.create_mock_message() helper.
Previously, it was tedious to create actual message
objects in message_store for use in node tests.
This was mainly because, `add_message_metadata`
in message_store has many dependencies and
validation checks. Since it was difficult to create
actual message objects, many tests just mocked
the `message_store.get()` method to return the desired
message.
This commit adds a new helper method (`create_mock_message`)
to message_store, for use in node tests. This just stores
the object passed to it in the `stores_messages` map,
without any validation. We do not add any
default fields to the message object before saving
it from this helper, because doing so would decrease
the utility of this helper, and, if a test
depends on some field having a particular value,
then it would be better to just pass the field: value
pair from the test itself, for readability, rather
than relying on the helper to add the field for us.
This helper allows us to write deeper tests.
This commit also replaces some instances of mocking
`message_store.get()` to use this new helper method.
2021-03-05 06:34:11 +01:00
|
|
|
const message_store = zrequire("message_store");
|
2021-03-30 02:21:21 +02:00
|
|
|
const muting = zrequire("muting");
|
2020-12-01 23:21:38 +01:00
|
|
|
const people = zrequire("people");
|
|
|
|
const stream_data = zrequire("stream_data");
|
2021-04-15 17:02:54 +02:00
|
|
|
const sub_store = zrequire("sub_store");
|
2020-12-01 23:21:38 +01:00
|
|
|
const unread = zrequire("unread");
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const me = {
|
2020-07-15 01:29:15 +02:00
|
|
|
email: "me@example.com",
|
2017-02-14 01:15:26 +01:00
|
|
|
user_id: 30,
|
2020-07-15 01:29:15 +02:00
|
|
|
full_name: "Me Myself",
|
2017-02-14 01:15:26 +01:00
|
|
|
};
|
2020-05-26 22:34:15 +02:00
|
|
|
people.add_active_user(me);
|
2017-02-14 01:15:26 +01:00
|
|
|
people.initialize_current_user(me.user_id);
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const social = {
|
2018-12-13 22:26:10 +01:00
|
|
|
stream_id: 200,
|
2020-07-15 01:29:15 +02:00
|
|
|
name: "social",
|
2018-12-13 22:26:10 +01:00
|
|
|
subscribed: true,
|
2019-05-15 08:54:25 +02:00
|
|
|
is_muted: false,
|
2018-12-13 22:26:10 +01:00
|
|
|
};
|
2020-02-09 22:02:55 +01:00
|
|
|
stream_data.add_sub(social);
|
2018-12-13 22:26:10 +01:00
|
|
|
|
2020-02-12 11:49:02 +01:00
|
|
|
function assert_zero_counts(counts) {
|
|
|
|
assert.equal(counts.private_message_count, 0);
|
|
|
|
assert.equal(counts.home_unread_messages, 0);
|
|
|
|
assert.equal(counts.mentioned_message_count, 0);
|
|
|
|
assert.equal(counts.stream_count.size, 0);
|
|
|
|
assert.equal(counts.pm_count.size, 0);
|
|
|
|
}
|
2013-07-28 18:40:50 +02:00
|
|
|
|
2019-07-20 14:45:56 +02:00
|
|
|
function test_notifiable_count(home_unread_messages, expected_notifiable_count) {
|
2021-03-25 22:35:45 +01:00
|
|
|
page_params.desktop_icon_count_display = 1;
|
2019-11-02 00:06:25 +01:00
|
|
|
let notifiable_counts = unread.get_notifiable_count();
|
2019-07-20 14:45:56 +02:00
|
|
|
assert.deepEqual(notifiable_counts, home_unread_messages);
|
2021-03-25 22:35:45 +01:00
|
|
|
page_params.desktop_icon_count_display = 2;
|
2019-07-20 14:45:56 +02:00
|
|
|
notifiable_counts = unread.get_notifiable_count();
|
|
|
|
assert.deepEqual(notifiable_counts, expected_notifiable_count);
|
2021-03-25 22:35:45 +01:00
|
|
|
page_params.desktop_icon_count_display = 3;
|
2019-08-19 23:33:11 +02:00
|
|
|
notifiable_counts = unread.get_notifiable_count();
|
|
|
|
assert.deepEqual(notifiable_counts, 0);
|
2019-07-20 14:45:56 +02:00
|
|
|
}
|
|
|
|
|
2021-03-09 15:18:57 +01:00
|
|
|
function test(label, f) {
|
2021-06-16 14:38:37 +02:00
|
|
|
run_test(label, ({override}) => {
|
2021-03-09 15:18:57 +01:00
|
|
|
unread.declare_bankruptcy();
|
|
|
|
muting.set_muted_topics([]);
|
2021-06-16 14:38:37 +02:00
|
|
|
f({override});
|
2021-03-09 15:18:57 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
test("empty_counts_while_narrowed", () => {
|
2019-11-02 00:06:25 +01:00
|
|
|
const counts = unread.get_counts();
|
2020-02-12 11:49:02 +01:00
|
|
|
assert_zero_counts(counts);
|
2019-07-20 14:45:56 +02:00
|
|
|
test_notifiable_count(counts.home_unread_messages, 0);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2013-07-28 18:40:50 +02:00
|
|
|
|
2021-03-09 15:18:57 +01:00
|
|
|
test("empty_counts_while_home", () => {
|
2019-11-02 00:06:25 +01:00
|
|
|
const counts = unread.get_counts();
|
2020-02-12 11:49:02 +01:00
|
|
|
assert_zero_counts(counts);
|
2019-07-20 14:45:56 +02:00
|
|
|
test_notifiable_count(counts.home_unread_messages, 0);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2013-07-28 18:40:50 +02:00
|
|
|
|
node tests: Introduce message_store.create_mock_message() helper.
Previously, it was tedious to create actual message
objects in message_store for use in node tests.
This was mainly because, `add_message_metadata`
in message_store has many dependencies and
validation checks. Since it was difficult to create
actual message objects, many tests just mocked
the `message_store.get()` method to return the desired
message.
This commit adds a new helper method (`create_mock_message`)
to message_store, for use in node tests. This just stores
the object passed to it in the `stores_messages` map,
without any validation. We do not add any
default fields to the message object before saving
it from this helper, because doing so would decrease
the utility of this helper, and, if a test
depends on some field having a particular value,
then it would be better to just pass the field: value
pair from the test itself, for readability, rather
than relying on the helper to add the field for us.
This helper allows us to write deeper tests.
This commit also replaces some instances of mocking
`message_store.get()` to use this new helper method.
2021-03-05 06:34:11 +01:00
|
|
|
test("changing_topics", () => {
|
2018-12-23 16:49:14 +01:00
|
|
|
// Summary: change the topic of a message from 'lunch'
|
2016-08-27 03:29:32 +02:00
|
|
|
// to 'dinner' using update_unread_topics().
|
2020-07-15 01:29:15 +02:00
|
|
|
let count = unread.num_unread_for_topic(social.stream_id, "lunch");
|
2013-07-28 18:40:50 +02:00
|
|
|
assert.equal(count, 0);
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const stream_id = 100;
|
|
|
|
const wrong_stream_id = 110;
|
2017-05-13 19:26:54 +02:00
|
|
|
|
2020-02-04 02:48:42 +01:00
|
|
|
const message = {
|
2013-07-28 18:40:50 +02:00
|
|
|
id: 15,
|
2020-07-15 01:29:15 +02:00
|
|
|
type: "stream",
|
2020-07-20 22:18:43 +02:00
|
|
|
stream_id,
|
2020-07-15 01:29:15 +02:00
|
|
|
topic: "luNch",
|
2017-12-16 21:42:41 +01:00
|
|
|
unread: true,
|
2020-02-04 02:48:42 +01:00
|
|
|
};
|
2013-07-28 18:40:50 +02:00
|
|
|
|
2020-02-04 02:48:42 +01:00
|
|
|
const other_message = {
|
2013-10-15 19:32:29 +02:00
|
|
|
id: 16,
|
2020-07-15 01:29:15 +02:00
|
|
|
type: "stream",
|
2020-07-20 22:18:43 +02:00
|
|
|
stream_id,
|
2020-07-15 01:29:15 +02:00
|
|
|
topic: "lunCH",
|
2017-12-16 21:42:41 +01:00
|
|
|
unread: true,
|
2020-02-04 02:48:42 +01:00
|
|
|
};
|
2013-10-15 19:32:29 +02:00
|
|
|
|
2017-12-16 16:53:27 +01:00
|
|
|
assert.deepEqual(unread.get_unread_message_ids([15, 16]), []);
|
|
|
|
assert.deepEqual(unread.get_unread_messages([message, other_message]), []);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
let msg_ids = unread.get_msg_ids_for_topic(stream_id, "LuNcH");
|
2018-04-25 22:48:51 +02:00
|
|
|
assert.deepEqual(msg_ids, []);
|
|
|
|
|
2018-05-01 21:22:49 +02:00
|
|
|
msg_ids = unread.get_msg_ids_for_stream(stream_id);
|
|
|
|
assert.deepEqual(msg_ids, []);
|
|
|
|
|
2013-10-15 19:32:29 +02:00
|
|
|
unread.process_loaded_messages([message, other_message]);
|
2017-12-16 16:53:27 +01:00
|
|
|
|
2018-05-10 13:11:53 +02:00
|
|
|
assert.deepEqual(unread.get_all_msg_ids(), [15, 16]);
|
2017-12-16 16:53:27 +01:00
|
|
|
assert.deepEqual(unread.get_unread_message_ids([15, 16]), [15, 16]);
|
2020-07-15 00:34:28 +02:00
|
|
|
assert.deepEqual(unread.get_unread_messages([message, other_message]), [
|
|
|
|
message,
|
|
|
|
other_message,
|
|
|
|
]);
|
2013-07-28 18:40:50 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
count = unread.num_unread_for_topic(stream_id, "Lunch");
|
2013-10-15 19:32:29 +02:00
|
|
|
assert.equal(count, 2);
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(unread.topic_has_any_unread(stream_id, "lunch"));
|
|
|
|
assert.ok(!unread.topic_has_any_unread(wrong_stream_id, "lunch"));
|
|
|
|
assert.ok(!unread.topic_has_any_unread(stream_id, "NOT lunch"));
|
2013-07-28 18:40:50 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
count = unread.num_unread_for_topic(stream_id, "NOT lunch");
|
2017-08-03 05:01:47 +02:00
|
|
|
assert.equal(count, 0);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
msg_ids = unread.get_msg_ids_for_topic(stream_id, "NOT lunch");
|
2018-04-25 22:48:51 +02:00
|
|
|
assert.deepEqual(msg_ids, []);
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let event = {
|
2020-07-15 01:29:15 +02:00
|
|
|
topic: "dinner",
|
2013-07-28 18:40:50 +02:00
|
|
|
};
|
|
|
|
|
2016-08-27 03:29:32 +02:00
|
|
|
unread.update_unread_topics(message, event);
|
2013-07-28 18:40:50 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
count = unread.num_unread_for_topic(stream_id, "lUnch");
|
2013-10-15 19:32:29 +02:00
|
|
|
assert.equal(count, 1);
|
2013-07-28 18:40:50 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
count = unread.num_unread_for_topic(stream_id, "dinner");
|
2013-07-28 18:40:50 +02:00
|
|
|
assert.equal(count, 1);
|
|
|
|
|
2013-10-15 19:32:29 +02:00
|
|
|
event = {
|
2020-07-15 01:29:15 +02:00
|
|
|
topic: "snack",
|
2013-10-15 19:32:29 +02:00
|
|
|
};
|
|
|
|
|
2016-08-27 03:29:32 +02:00
|
|
|
unread.update_unread_topics(other_message, event);
|
2013-10-15 19:32:29 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
count = unread.num_unread_for_topic(stream_id, "lunch");
|
2013-10-15 19:32:29 +02:00
|
|
|
assert.equal(count, 0);
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(!unread.topic_has_any_unread(stream_id, "lunch"));
|
|
|
|
assert.ok(!unread.topic_has_any_unread(wrong_stream_id, "lunch"));
|
2013-10-15 19:32:29 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
count = unread.num_unread_for_topic(stream_id, "snack");
|
2013-10-15 19:32:29 +02:00
|
|
|
assert.equal(count, 1);
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(unread.topic_has_any_unread(stream_id, "snack"));
|
|
|
|
assert.ok(!unread.topic_has_any_unread(wrong_stream_id, "snack"));
|
2013-10-15 19:32:29 +02:00
|
|
|
|
|
|
|
// Test defensive code. Trying to update a message we don't know
|
|
|
|
// about should be a no-op.
|
|
|
|
event = {
|
2020-07-15 01:29:15 +02:00
|
|
|
topic: "brunch",
|
2013-10-15 19:32:29 +02:00
|
|
|
};
|
2016-08-27 03:29:32 +02:00
|
|
|
unread.update_unread_topics(other_message, event);
|
2013-10-15 19:32:29 +02:00
|
|
|
|
2017-08-10 20:27:23 +02:00
|
|
|
// Update a message that was never marked as unread.
|
2020-02-04 02:48:42 +01:00
|
|
|
const sticky_message = {
|
2017-08-10 20:27:23 +02:00
|
|
|
id: 17,
|
2020-07-15 01:29:15 +02:00
|
|
|
type: "stream",
|
2020-07-20 22:18:43 +02:00
|
|
|
stream_id,
|
2020-07-15 01:29:15 +02:00
|
|
|
topic: "sticky",
|
2017-12-16 21:42:41 +01:00
|
|
|
unread: true,
|
2020-02-04 02:48:42 +01:00
|
|
|
};
|
|
|
|
|
2021-03-28 17:57:53 +02:00
|
|
|
message_store.update_message_cache(message);
|
|
|
|
message_store.update_message_cache(other_message);
|
|
|
|
message_store.update_message_cache(sticky_message);
|
2017-08-10 20:27:23 +02:00
|
|
|
|
|
|
|
unread.process_loaded_messages([sticky_message]);
|
2020-07-15 01:29:15 +02:00
|
|
|
count = unread.num_unread_for_topic(stream_id, "sticky");
|
2017-08-10 20:27:23 +02:00
|
|
|
assert.equal(count, 1);
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(sticky_message.unread);
|
2017-08-10 20:27:23 +02:00
|
|
|
|
|
|
|
unread.mark_as_read(sticky_message.id);
|
2020-07-15 01:29:15 +02:00
|
|
|
count = unread.num_unread_for_topic(stream_id, "sticky");
|
2017-08-10 20:27:23 +02:00
|
|
|
assert.equal(count, 0);
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(!sticky_message.unread);
|
2017-08-10 20:27:23 +02:00
|
|
|
|
2018-12-23 18:08:37 +01:00
|
|
|
event = {
|
2020-07-15 01:29:15 +02:00
|
|
|
topic: "sticky",
|
2018-12-23 18:08:37 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
unread.update_unread_topics(sticky_message, event);
|
2020-07-15 01:29:15 +02:00
|
|
|
count = unread.num_unread_for_topic(stream_id, "sticky");
|
2017-08-10 20:27:23 +02:00
|
|
|
assert.equal(count, 0);
|
|
|
|
|
2013-07-28 18:40:50 +02:00
|
|
|
// cleanup
|
2017-08-02 21:40:01 +02:00
|
|
|
unread.mark_as_read(message.id);
|
2020-07-15 01:29:15 +02:00
|
|
|
count = unread.num_unread_for_topic(stream_id, "dinner");
|
2013-07-28 18:40:50 +02:00
|
|
|
assert.equal(count, 0);
|
2013-10-15 19:32:29 +02:00
|
|
|
|
2017-08-02 21:40:01 +02:00
|
|
|
unread.mark_as_read(other_message.id);
|
2020-07-15 01:29:15 +02:00
|
|
|
count = unread.num_unread_for_topic(stream_id, "snack");
|
2013-10-15 19:32:29 +02:00
|
|
|
assert.equal(count, 0);
|
2017-08-10 20:27:23 +02:00
|
|
|
|
|
|
|
// test coverage
|
|
|
|
unread.update_unread_topics(sticky_message, {});
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2013-07-28 18:40:50 +02:00
|
|
|
|
2021-03-09 15:18:57 +01:00
|
|
|
test("muting", () => {
|
2019-11-02 00:06:25 +01:00
|
|
|
const stream_id = social.stream_id;
|
|
|
|
const unknown_stream_id = 555;
|
2017-05-13 19:26:54 +02:00
|
|
|
|
2020-02-04 02:48:42 +01:00
|
|
|
const message = {
|
2013-09-28 00:00:44 +02:00
|
|
|
id: 15,
|
2020-07-15 01:29:15 +02:00
|
|
|
type: "stream",
|
2020-07-20 22:18:43 +02:00
|
|
|
stream_id,
|
2020-07-15 01:29:15 +02:00
|
|
|
topic: "test_muting",
|
2017-12-16 21:42:41 +01:00
|
|
|
unread: true,
|
2020-02-04 02:48:42 +01:00
|
|
|
};
|
2013-09-28 00:00:44 +02:00
|
|
|
|
|
|
|
unread.process_loaded_messages([message]);
|
2019-11-02 00:06:25 +01:00
|
|
|
let counts = unread.get_counts();
|
2017-05-13 19:26:54 +02:00
|
|
|
assert.equal(counts.stream_count.get(stream_id), 1);
|
2013-09-28 00:00:44 +02:00
|
|
|
assert.equal(counts.home_unread_messages, 1);
|
2017-05-13 19:26:54 +02:00
|
|
|
assert.equal(unread.num_unread_for_stream(stream_id), 1);
|
2018-05-01 21:22:49 +02:00
|
|
|
assert.deepEqual(unread.get_msg_ids_for_stream(stream_id), [message.id]);
|
2019-07-20 14:45:56 +02:00
|
|
|
test_notifiable_count(counts.home_unread_messages, 0);
|
2013-09-28 00:00:44 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
muting.add_muted_topic(social.stream_id, "test_muting");
|
2013-09-28 00:00:44 +02:00
|
|
|
counts = unread.get_counts();
|
2017-05-13 19:26:54 +02:00
|
|
|
assert.equal(counts.stream_count.get(stream_id), 0);
|
2013-09-28 00:00:44 +02:00
|
|
|
assert.equal(counts.home_unread_messages, 0);
|
2017-05-13 19:26:54 +02:00
|
|
|
assert.equal(unread.num_unread_for_stream(stream_id), 0);
|
2018-05-01 21:22:49 +02:00
|
|
|
assert.deepEqual(unread.get_msg_ids_for_stream(stream_id), []);
|
2019-07-20 14:45:56 +02:00
|
|
|
test_notifiable_count(counts.home_unread_messages, 0);
|
2017-04-03 22:14:46 +02:00
|
|
|
|
2018-05-10 13:11:53 +02:00
|
|
|
// we still find the message id here (muting is ignored)
|
|
|
|
assert.deepEqual(unread.get_all_msg_ids(), [message.id]);
|
|
|
|
|
2017-05-13 19:26:54 +02:00
|
|
|
assert.equal(unread.num_unread_for_stream(unknown_stream_id), 0);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2013-09-28 00:00:44 +02:00
|
|
|
|
2021-06-16 14:38:37 +02:00
|
|
|
test("num_unread_for_topic", ({override}) => {
|
2017-07-31 14:11:18 +02:00
|
|
|
// Test the num_unread_for_topic() function using many
|
2013-07-28 18:40:50 +02:00
|
|
|
// messages.
|
2019-11-02 00:06:25 +01:00
|
|
|
const stream_id = 301;
|
2018-05-01 21:22:49 +02:00
|
|
|
|
2021-04-15 17:02:54 +02:00
|
|
|
override(sub_store, "get", (arg) => {
|
2018-05-01 21:22:49 +02:00
|
|
|
if (arg === stream_id) {
|
2021-05-10 07:02:14 +02:00
|
|
|
return {name: "Some stream"};
|
2018-05-01 21:22:49 +02:00
|
|
|
}
|
2020-09-24 07:50:36 +02:00
|
|
|
throw new Error(`Unknown stream ${arg}`);
|
2021-02-28 00:53:59 +01:00
|
|
|
});
|
2018-05-01 21:22:49 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
let count = unread.num_unread_for_topic(stream_id, "lunch");
|
2013-07-28 18:40:50 +02:00
|
|
|
assert.equal(count, 0);
|
|
|
|
|
2020-02-04 02:48:42 +01:00
|
|
|
const message = {
|
2020-07-15 01:29:15 +02:00
|
|
|
type: "stream",
|
2020-07-20 22:18:43 +02:00
|
|
|
stream_id,
|
2020-07-15 01:29:15 +02:00
|
|
|
topic: "LuncH",
|
2020-02-04 02:48:42 +01:00
|
|
|
unread: true,
|
|
|
|
};
|
|
|
|
|
2018-04-25 22:48:51 +02:00
|
|
|
// Put messages into list in reverse order to try to confuse
|
|
|
|
// our sort.
|
2019-11-02 00:06:25 +01:00
|
|
|
const num_msgs = 500;
|
|
|
|
let i;
|
2018-04-25 22:48:51 +02:00
|
|
|
for (i = num_msgs; i > 0; i -= 1) {
|
2020-02-04 02:48:42 +01:00
|
|
|
message.id = i;
|
2013-07-28 18:40:50 +02:00
|
|
|
unread.process_loaded_messages([message]);
|
|
|
|
}
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
count = unread.num_unread_for_topic(stream_id, "lunch");
|
2013-07-28 18:40:50 +02:00
|
|
|
assert.equal(count, num_msgs);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
let msg_ids = unread.get_msg_ids_for_topic(stream_id, "LuNcH");
|
2018-04-25 22:48:51 +02:00
|
|
|
assert.deepEqual(msg_ids, _.range(1, 501));
|
|
|
|
|
2018-05-01 21:22:49 +02:00
|
|
|
msg_ids = unread.get_msg_ids_for_stream(stream_id);
|
|
|
|
assert.deepEqual(msg_ids, _.range(1, 501));
|
|
|
|
|
2019-12-26 15:34:17 +01:00
|
|
|
const topic_dict = new FoldDict();
|
2018-05-13 11:38:40 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let missing_topics = unread.get_missing_topics({
|
2020-07-20 22:18:43 +02:00
|
|
|
stream_id,
|
|
|
|
topic_dict,
|
2018-05-13 11:38:40 +02:00
|
|
|
});
|
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
assert.deepEqual(missing_topics, [{pretty_name: "LuncH", message_id: 500}]);
|
2018-05-13 11:38:40 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
topic_dict.set("lUNCh", "whatever");
|
2018-05-13 11:38:40 +02:00
|
|
|
|
|
|
|
missing_topics = unread.get_missing_topics({
|
2020-07-20 22:18:43 +02:00
|
|
|
stream_id,
|
|
|
|
topic_dict,
|
2018-05-13 11:38:40 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
assert.deepEqual(missing_topics, []);
|
|
|
|
|
2020-02-04 02:48:42 +01:00
|
|
|
for (i = 0; i < num_msgs; i += 1) {
|
|
|
|
message.id = i + 1;
|
|
|
|
unread.mark_as_read(message.id);
|
2013-07-28 18:40:50 +02:00
|
|
|
}
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
count = unread.num_unread_for_topic(stream_id, "lunch");
|
2013-07-28 18:40:50 +02:00
|
|
|
assert.equal(count, 0);
|
2018-04-25 22:48:51 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
msg_ids = unread.get_msg_ids_for_topic(stream_id, "LuNcH");
|
2018-04-25 22:48:51 +02:00
|
|
|
assert.deepEqual(msg_ids, []);
|
2018-05-01 21:22:49 +02:00
|
|
|
|
|
|
|
msg_ids = unread.get_msg_ids_for_stream(stream_id);
|
|
|
|
assert.deepEqual(msg_ids, []);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2013-07-28 18:40:50 +02:00
|
|
|
|
2021-06-16 14:38:37 +02:00
|
|
|
test("home_messages", ({override}) => {
|
2021-03-07 17:01:11 +01:00
|
|
|
override(stream_data, "is_subscribed", () => true);
|
|
|
|
override(stream_data, "is_muted", () => false);
|
2013-07-28 18:40:50 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const stream_id = 401;
|
2017-05-13 19:26:54 +02:00
|
|
|
|
2021-04-15 17:02:54 +02:00
|
|
|
override(sub_store, "get", () => ({
|
2021-02-23 14:37:26 +01:00
|
|
|
name: "whatever",
|
2021-02-28 00:53:59 +01:00
|
|
|
}));
|
2017-05-13 19:26:54 +02:00
|
|
|
|
2020-02-04 02:48:42 +01:00
|
|
|
const message = {
|
2013-07-28 18:40:50 +02:00
|
|
|
id: 15,
|
2020-07-15 01:29:15 +02:00
|
|
|
type: "stream",
|
2020-07-20 22:18:43 +02:00
|
|
|
stream_id,
|
2020-07-15 01:29:15 +02:00
|
|
|
topic: "lunch",
|
2017-12-16 21:42:41 +01:00
|
|
|
unread: true,
|
2020-02-04 02:48:42 +01:00
|
|
|
};
|
2013-07-28 18:40:50 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let counts = unread.get_counts();
|
2013-07-28 18:40:50 +02:00
|
|
|
assert.equal(counts.home_unread_messages, 0);
|
2019-07-20 14:45:56 +02:00
|
|
|
test_notifiable_count(counts.home_unread_messages, 0);
|
2013-07-28 18:40:50 +02:00
|
|
|
|
|
|
|
unread.process_loaded_messages([message]);
|
|
|
|
|
|
|
|
counts = unread.get_counts();
|
|
|
|
assert.equal(counts.home_unread_messages, 1);
|
2017-05-13 19:26:54 +02:00
|
|
|
assert.equal(counts.stream_count.get(stream_id), 1);
|
2019-07-20 14:45:56 +02:00
|
|
|
test_notifiable_count(counts.home_unread_messages, 0);
|
2017-08-02 21:40:01 +02:00
|
|
|
unread.mark_as_read(message.id);
|
2013-07-28 18:40:50 +02:00
|
|
|
counts = unread.get_counts();
|
|
|
|
assert.equal(counts.home_unread_messages, 0);
|
2019-07-20 14:45:56 +02:00
|
|
|
test_notifiable_count(counts.home_unread_messages, 0);
|
2013-08-23 04:56:11 +02:00
|
|
|
|
|
|
|
unread.process_loaded_messages([message]);
|
|
|
|
counts = unread.get_counts();
|
|
|
|
assert.equal(counts.home_unread_messages, 1);
|
2019-07-20 14:45:56 +02:00
|
|
|
test_notifiable_count(counts.home_unread_messages, 0);
|
2013-08-23 04:56:11 +02:00
|
|
|
|
|
|
|
// Now unsubscribe all our streams.
|
2021-03-07 17:01:11 +01:00
|
|
|
override(stream_data, "is_subscribed", () => false);
|
2013-08-23 04:56:11 +02:00
|
|
|
counts = unread.get_counts();
|
|
|
|
assert.equal(counts.home_unread_messages, 0);
|
2019-07-20 14:45:56 +02:00
|
|
|
test_notifiable_count(counts.home_unread_messages, 0);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2013-07-28 18:40:50 +02:00
|
|
|
|
2021-03-09 15:18:57 +01:00
|
|
|
test("phantom_messages", () => {
|
2020-02-04 02:48:42 +01:00
|
|
|
const message = {
|
2013-09-28 23:09:29 +02:00
|
|
|
id: 999,
|
2020-07-15 01:29:15 +02:00
|
|
|
type: "stream",
|
2017-05-13 19:26:54 +02:00
|
|
|
stream_id: 555,
|
2020-07-15 01:29:15 +02:00
|
|
|
topic: "phantom",
|
2020-02-04 02:48:42 +01:00
|
|
|
};
|
2013-09-28 23:09:29 +02:00
|
|
|
|
2017-08-02 21:40:01 +02:00
|
|
|
unread.mark_as_read(message.id);
|
2019-11-02 00:06:25 +01:00
|
|
|
const counts = unread.get_counts();
|
2013-09-28 23:09:29 +02:00
|
|
|
assert.equal(counts.home_unread_messages, 0);
|
2019-07-20 14:45:56 +02:00
|
|
|
test_notifiable_count(counts.home_unread_messages, 0);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2013-09-28 23:09:29 +02:00
|
|
|
|
2021-03-09 15:18:57 +01:00
|
|
|
test("private_messages", () => {
|
2019-11-02 00:06:25 +01:00
|
|
|
let counts = unread.get_counts();
|
2013-07-28 18:40:50 +02:00
|
|
|
assert.equal(counts.private_message_count, 0);
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const anybody = {
|
2020-07-15 01:29:15 +02:00
|
|
|
email: "anybody@example.com",
|
2016-11-16 00:09:09 +01:00
|
|
|
user_id: 999,
|
2020-07-15 01:29:15 +02:00
|
|
|
full_name: "Any Body",
|
2013-07-28 18:40:50 +02:00
|
|
|
};
|
2020-05-26 22:34:15 +02:00
|
|
|
people.add_active_user(anybody);
|
2013-07-28 18:40:50 +02:00
|
|
|
|
2020-02-04 02:48:42 +01:00
|
|
|
const message = {
|
2017-02-14 01:15:26 +01:00
|
|
|
id: 15,
|
2020-07-15 01:29:15 +02:00
|
|
|
type: "private",
|
2020-07-15 00:34:28 +02:00
|
|
|
display_recipient: [{id: anybody.user_id}, {id: me.user_id}],
|
2017-12-16 21:42:41 +01:00
|
|
|
unread: true,
|
2020-02-04 02:48:42 +01:00
|
|
|
};
|
2017-02-14 01:15:26 +01:00
|
|
|
|
2013-07-28 18:40:50 +02:00
|
|
|
unread.process_loaded_messages([message]);
|
|
|
|
|
|
|
|
counts = unread.get_counts();
|
|
|
|
assert.equal(counts.private_message_count, 1);
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(counts.pm_count.get("999"), 1);
|
2019-07-20 14:45:56 +02:00
|
|
|
test_notifiable_count(counts.home_unread_messages, 1);
|
2017-08-02 21:40:01 +02:00
|
|
|
unread.mark_as_read(message.id);
|
2013-07-28 18:40:50 +02:00
|
|
|
counts = unread.get_counts();
|
|
|
|
assert.equal(counts.private_message_count, 0);
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(counts.pm_count.get("999"), 0);
|
2019-07-20 14:45:56 +02:00
|
|
|
test_notifiable_count(counts.home_unread_messages, 0);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2013-07-28 18:40:50 +02:00
|
|
|
|
2021-03-09 15:18:57 +01:00
|
|
|
test("private_messages", () => {
|
2019-11-02 00:06:25 +01:00
|
|
|
const alice = {
|
2020-07-15 01:29:15 +02:00
|
|
|
email: "alice@example.com",
|
2016-11-16 00:09:09 +01:00
|
|
|
user_id: 101,
|
2020-07-15 01:29:15 +02:00
|
|
|
full_name: "Alice",
|
2016-11-16 00:09:09 +01:00
|
|
|
};
|
2020-05-26 22:34:15 +02:00
|
|
|
people.add_active_user(alice);
|
2013-09-10 23:33:46 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const bob = {
|
2020-07-15 01:29:15 +02:00
|
|
|
email: "bob@example.com",
|
2016-11-16 00:09:09 +01:00
|
|
|
user_id: 102,
|
2020-07-15 01:29:15 +02:00
|
|
|
full_name: "Bob",
|
2016-11-16 00:09:09 +01:00
|
|
|
};
|
2020-05-26 22:34:15 +02:00
|
|
|
people.add_active_user(bob);
|
2016-11-16 00:09:09 +01:00
|
|
|
|
2020-02-01 02:47:48 +01:00
|
|
|
assert.equal(unread.num_unread_for_person(alice.user_id.toString()), 0);
|
|
|
|
assert.equal(unread.num_unread_for_person(bob.user_id.toString()), 0);
|
|
|
|
assert.deepEqual(unread.get_msg_ids_for_person(alice.user_id.toString()), []);
|
|
|
|
assert.deepEqual(unread.get_msg_ids_for_person(bob.user_id.toString()), []);
|
2018-05-02 13:02:32 +02:00
|
|
|
assert.deepEqual(unread.get_msg_ids_for_person(), []);
|
2018-05-02 19:50:25 +02:00
|
|
|
assert.deepEqual(unread.get_msg_ids_for_private(), []);
|
2013-08-22 19:06:04 +02:00
|
|
|
|
2020-02-04 02:48:42 +01:00
|
|
|
const message = {
|
2013-08-22 19:06:04 +02:00
|
|
|
id: 15,
|
2017-02-14 01:15:26 +01:00
|
|
|
display_recipient: [{id: alice.user_id}],
|
2020-07-15 01:29:15 +02:00
|
|
|
type: "private",
|
2017-12-16 21:42:41 +01:00
|
|
|
unread: true,
|
2020-02-04 02:48:42 +01:00
|
|
|
};
|
2013-08-23 03:23:08 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const read_message = {
|
2020-07-15 01:29:15 +02:00
|
|
|
flags: ["read"],
|
2013-08-23 03:23:08 +02:00
|
|
|
};
|
|
|
|
unread.process_loaded_messages([message, read_message]);
|
2020-02-01 02:47:48 +01:00
|
|
|
assert.equal(unread.num_unread_for_person(alice.user_id.toString()), 1);
|
2017-04-03 22:14:46 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(unread.num_unread_for_person(""), 0);
|
2018-05-02 13:02:32 +02:00
|
|
|
|
2020-02-01 02:47:48 +01:00
|
|
|
assert.deepEqual(unread.get_msg_ids_for_person(alice.user_id.toString()), [message.id]);
|
|
|
|
assert.deepEqual(unread.get_msg_ids_for_person(bob.user_id.toString()), []);
|
2018-05-02 19:50:25 +02:00
|
|
|
assert.deepEqual(unread.get_msg_ids_for_private(), [message.id]);
|
2018-05-10 13:11:53 +02:00
|
|
|
assert.deepEqual(unread.get_all_msg_ids(), [message.id]);
|
2019-07-20 13:42:49 +02:00
|
|
|
|
|
|
|
unread.mark_as_read(message.id);
|
2020-02-01 02:47:48 +01:00
|
|
|
assert.equal(unread.num_unread_for_person(alice.user_id.toString()), 0);
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(unread.num_unread_for_person(""), 0);
|
2020-02-01 02:47:48 +01:00
|
|
|
assert.deepEqual(unread.get_msg_ids_for_person(alice.user_id.toString()), []);
|
|
|
|
assert.deepEqual(unread.get_msg_ids_for_person(bob.user_id.toString()), []);
|
2019-07-20 13:42:49 +02:00
|
|
|
assert.deepEqual(unread.get_msg_ids_for_private(), []);
|
|
|
|
assert.deepEqual(unread.get_all_msg_ids(), []);
|
2019-11-02 00:06:25 +01:00
|
|
|
const counts = unread.get_counts();
|
2019-07-20 13:42:49 +02:00
|
|
|
assert.equal(counts.private_message_count, 0);
|
2019-07-20 14:45:56 +02:00
|
|
|
test_notifiable_count(counts.home_unread_messages, 0);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2013-08-22 19:06:04 +02:00
|
|
|
|
2021-03-09 15:18:57 +01:00
|
|
|
test("mentions", () => {
|
2019-11-02 00:06:25 +01:00
|
|
|
let counts = unread.get_counts();
|
2013-07-28 18:40:50 +02:00
|
|
|
assert.equal(counts.mentioned_message_count, 0);
|
2018-05-02 19:54:36 +02:00
|
|
|
assert.deepEqual(unread.get_msg_ids_for_mentions(), []);
|
2019-07-20 14:45:56 +02:00
|
|
|
test_notifiable_count(counts.home_unread_messages, 0);
|
2013-07-28 18:40:50 +02:00
|
|
|
|
2019-09-27 11:11:40 +02:00
|
|
|
const muted_stream_id = 401;
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
muting.add_muted_topic(401, "lunch");
|
2019-09-27 11:11:40 +02:00
|
|
|
|
2020-04-11 03:13:50 +02:00
|
|
|
const already_read_message = {
|
|
|
|
id: 14,
|
2020-07-15 01:29:15 +02:00
|
|
|
type: "stream",
|
2020-04-11 03:13:50 +02:00
|
|
|
stream_id: 400,
|
2020-07-15 01:29:15 +02:00
|
|
|
topic: "lunch",
|
2020-04-11 03:13:50 +02:00
|
|
|
mentioned: true,
|
|
|
|
mentioned_me_directly: true,
|
|
|
|
unread: false,
|
|
|
|
};
|
|
|
|
|
2020-02-04 02:48:42 +01:00
|
|
|
const mention_me_message = {
|
2013-07-28 18:40:50 +02:00
|
|
|
id: 15,
|
2020-07-15 01:29:15 +02:00
|
|
|
type: "stream",
|
2019-09-27 11:11:40 +02:00
|
|
|
stream_id: 400,
|
2020-07-15 01:29:15 +02:00
|
|
|
topic: "lunch",
|
2016-12-03 23:17:57 +01:00
|
|
|
mentioned: true,
|
2019-09-27 11:11:40 +02:00
|
|
|
mentioned_me_directly: true,
|
2018-12-18 19:34:45 +01:00
|
|
|
unread: true,
|
2020-02-04 02:48:42 +01:00
|
|
|
};
|
2013-07-28 18:40:50 +02:00
|
|
|
|
2020-02-04 02:48:42 +01:00
|
|
|
const mention_all_message = {
|
2019-09-27 11:11:40 +02:00
|
|
|
id: 16,
|
2020-07-15 01:29:15 +02:00
|
|
|
type: "stream",
|
2019-09-27 11:11:40 +02:00
|
|
|
stream_id: 400,
|
2020-07-15 01:29:15 +02:00
|
|
|
topic: "lunch",
|
2019-09-27 11:11:40 +02:00
|
|
|
mentioned: true,
|
|
|
|
mentioned_me_directly: false,
|
|
|
|
unread: true,
|
2020-02-04 02:48:42 +01:00
|
|
|
};
|
2019-09-27 11:11:40 +02:00
|
|
|
|
|
|
|
// This message shouldn't affect the unread mention counts.
|
2020-02-04 02:48:42 +01:00
|
|
|
const muted_mention_all_message = {
|
2019-09-27 11:11:40 +02:00
|
|
|
id: 17,
|
2020-07-15 01:29:15 +02:00
|
|
|
type: "stream",
|
2019-09-27 11:11:40 +02:00
|
|
|
stream_id: muted_stream_id,
|
2020-07-15 01:29:15 +02:00
|
|
|
topic: "lunch",
|
2019-09-27 11:11:40 +02:00
|
|
|
mentioned: true,
|
|
|
|
mentioned_me_directly: false,
|
|
|
|
unread: true,
|
2020-02-04 02:48:42 +01:00
|
|
|
};
|
2019-09-27 11:11:40 +02:00
|
|
|
|
2020-04-11 03:13:50 +02:00
|
|
|
unread.process_loaded_messages([
|
|
|
|
already_read_message,
|
|
|
|
mention_me_message,
|
|
|
|
mention_all_message,
|
|
|
|
muted_mention_all_message,
|
|
|
|
]);
|
2013-07-28 18:40:50 +02:00
|
|
|
|
|
|
|
counts = unread.get_counts();
|
2019-09-27 11:11:40 +02:00
|
|
|
assert.equal(counts.mentioned_message_count, 2);
|
2020-07-15 00:34:28 +02:00
|
|
|
assert.deepEqual(unread.get_msg_ids_for_mentions(), [
|
|
|
|
mention_me_message.id,
|
|
|
|
mention_all_message.id,
|
|
|
|
]);
|
|
|
|
assert.deepEqual(unread.get_all_msg_ids(), [
|
|
|
|
mention_me_message.id,
|
|
|
|
mention_all_message.id,
|
|
|
|
muted_mention_all_message.id,
|
|
|
|
]);
|
2019-09-27 11:11:40 +02:00
|
|
|
test_notifiable_count(counts.home_unread_messages, 2);
|
|
|
|
|
|
|
|
unread.mark_as_read(mention_me_message.id);
|
|
|
|
unread.mark_as_read(mention_all_message.id);
|
2013-07-28 18:40:50 +02:00
|
|
|
counts = unread.get_counts();
|
|
|
|
assert.equal(counts.mentioned_message_count, 0);
|
2019-07-20 14:45:56 +02:00
|
|
|
test_notifiable_count(counts.home_unread_messages, 0);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2013-07-28 18:40:50 +02:00
|
|
|
|
2021-03-09 15:18:57 +01:00
|
|
|
test("mention updates", () => {
|
2020-04-11 02:51:45 +02:00
|
|
|
const message = {
|
|
|
|
id: 17,
|
|
|
|
unread: false,
|
2020-07-15 01:29:15 +02:00
|
|
|
type: "stream",
|
2020-04-11 02:51:45 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
function test_counted(counted) {
|
|
|
|
unread.update_message_for_mention(message);
|
2020-07-15 00:34:28 +02:00
|
|
|
assert.equal(unread.unread_mentions_counter.has(message.id), counted);
|
2020-04-11 02:51:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
test_counted(false);
|
|
|
|
|
|
|
|
message.unread = true;
|
|
|
|
message.mentioned = true;
|
|
|
|
test_counted(true);
|
|
|
|
|
|
|
|
message.mentioned = false;
|
|
|
|
test_counted(false);
|
|
|
|
|
|
|
|
message.mentioned = true;
|
|
|
|
test_counted(true);
|
|
|
|
|
|
|
|
message.unread = false;
|
|
|
|
test_counted(false);
|
|
|
|
|
|
|
|
message.unread = true;
|
|
|
|
test_counted(true);
|
|
|
|
});
|
|
|
|
|
2021-03-09 15:18:57 +01:00
|
|
|
test("starring", () => {
|
2018-05-03 22:57:07 +02:00
|
|
|
// We don't need any setup here, because we just hard code
|
|
|
|
// this to [] in the code.
|
|
|
|
assert.deepEqual(unread.get_msg_ids_for_starred(), []);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2018-05-03 22:57:07 +02:00
|
|
|
|
2021-03-09 15:18:57 +01:00
|
|
|
test("declare_bankruptcy", () => {
|
2020-02-04 02:48:42 +01:00
|
|
|
const message = {
|
2017-07-31 14:30:46 +02:00
|
|
|
id: 16,
|
2020-07-15 01:29:15 +02:00
|
|
|
type: "whatever",
|
2017-07-31 14:30:46 +02:00
|
|
|
stream_id: 1999,
|
2020-07-15 01:29:15 +02:00
|
|
|
topic: "whatever",
|
2017-07-31 14:30:46 +02:00
|
|
|
mentioned: true,
|
2020-02-04 02:48:42 +01:00
|
|
|
};
|
2017-07-31 14:30:46 +02:00
|
|
|
|
|
|
|
unread.process_loaded_messages([message]);
|
|
|
|
|
2013-07-28 18:40:50 +02:00
|
|
|
unread.declare_bankruptcy();
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const counts = unread.get_counts();
|
2020-02-12 11:49:02 +01:00
|
|
|
assert_zero_counts(counts);
|
2019-07-20 14:45:56 +02:00
|
|
|
test_notifiable_count(counts.home_unread_messages, 0);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2013-07-28 18:40:50 +02:00
|
|
|
|
2021-03-09 15:18:57 +01:00
|
|
|
test("message_unread", () => {
|
2013-08-23 03:20:42 +02:00
|
|
|
// Test some code that might be overly defensive, for line coverage sake.
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(!unread.message_unread(undefined));
|
|
|
|
assert.ok(unread.message_unread({unread: true}));
|
|
|
|
assert.ok(!unread.message_unread({unread: false}));
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2016-11-16 00:09:09 +01:00
|
|
|
|
2021-03-09 15:18:57 +01:00
|
|
|
test("server_counts", () => {
|
2017-08-01 14:50:40 +02:00
|
|
|
// note that user_id 30 is "me"
|
|
|
|
|
|
|
|
page_params.unread_msgs = {
|
|
|
|
pms: [
|
|
|
|
{
|
|
|
|
sender_id: 101,
|
2020-07-15 00:34:28 +02:00
|
|
|
unread_message_ids: [31, 32, 60, 61, 62, 63],
|
2017-08-01 14:50:40 +02:00
|
|
|
},
|
|
|
|
],
|
|
|
|
huddles: [
|
|
|
|
{
|
|
|
|
user_ids_string: "4,6,30,101",
|
2020-07-15 00:34:28 +02:00
|
|
|
unread_message_ids: [34, 50],
|
2017-08-01 14:50:40 +02:00
|
|
|
},
|
|
|
|
],
|
|
|
|
streams: [
|
|
|
|
{
|
|
|
|
stream_id: 1,
|
|
|
|
topic: "test",
|
2020-07-15 00:34:28 +02:00
|
|
|
unread_message_ids: [33, 35, 36],
|
2017-08-01 14:50:40 +02:00
|
|
|
},
|
|
|
|
],
|
|
|
|
mentions: [31, 34, 40, 41],
|
|
|
|
};
|
|
|
|
|
|
|
|
unread.initialize();
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(unread.num_unread_for_person("101"), 6);
|
|
|
|
assert.equal(unread.num_unread_for_person("4,6,101"), 2);
|
|
|
|
assert.equal(unread.num_unread_for_person("30"), 0);
|
2017-08-01 14:50:40 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(unread.num_unread_for_topic(0, "bogus"), 0);
|
|
|
|
assert.equal(unread.num_unread_for_topic(1, "bogus"), 0);
|
|
|
|
assert.equal(unread.num_unread_for_topic(1, "test"), 3);
|
2017-08-01 14:50:40 +02:00
|
|
|
|
2020-02-01 03:13:57 +01:00
|
|
|
assert.equal(unread.unread_mentions_counter.size, 4);
|
2017-08-01 14:50:40 +02:00
|
|
|
|
|
|
|
unread.mark_as_read(40);
|
2020-02-01 03:13:57 +01:00
|
|
|
assert.equal(unread.unread_mentions_counter.size, 3);
|
2017-08-01 14:50:40 +02:00
|
|
|
|
|
|
|
unread.mark_as_read(35);
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(unread.num_unread_for_topic(1, "test"), 2);
|
2017-08-01 14:50:40 +02:00
|
|
|
|
|
|
|
unread.mark_as_read(34);
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(unread.num_unread_for_person("4,6,101"), 1);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-08-01 14:50:40 +02:00
|
|
|
|
2021-03-09 15:18:57 +01:00
|
|
|
test("empty_cases", () => {
|
2018-04-25 22:48:51 +02:00
|
|
|
const stream_id = 999;
|
2020-07-15 01:29:15 +02:00
|
|
|
let msg_ids = unread.get_msg_ids_for_topic(stream_id, "LuNcH");
|
2018-05-01 21:22:49 +02:00
|
|
|
assert.deepEqual(msg_ids, []);
|
|
|
|
|
|
|
|
msg_ids = unread.get_msg_ids_for_stream(stream_id);
|
2018-04-25 22:48:51 +02:00
|
|
|
assert.deepEqual(msg_ids, []);
|
2018-05-10 13:11:53 +02:00
|
|
|
assert.deepEqual(unread.get_all_msg_ids(), []);
|
2018-05-13 11:38:40 +02:00
|
|
|
|
|
|
|
const missing_topics = unread.get_missing_topics({
|
2020-07-20 22:18:43 +02:00
|
|
|
stream_id,
|
2020-07-15 01:29:15 +02:00
|
|
|
topic_dict: "should-never-be-referenced",
|
2018-05-13 11:38:40 +02:00
|
|
|
});
|
|
|
|
assert.deepEqual(missing_topics, []);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2018-04-25 22:48:51 +02:00
|
|
|
|
2021-03-09 15:18:57 +01:00
|
|
|
test("errors", () => {
|
2016-11-16 00:09:09 +01:00
|
|
|
// Test unknown message leads to zero count
|
2019-11-02 00:06:25 +01:00
|
|
|
const message = {
|
2016-11-16 00:09:09 +01:00
|
|
|
id: 9,
|
2020-07-15 01:29:15 +02:00
|
|
|
type: "private",
|
2017-02-14 01:15:26 +01:00
|
|
|
display_recipient: [{id: 9999}],
|
2016-11-16 00:09:09 +01:00
|
|
|
};
|
|
|
|
|
2017-08-02 21:40:01 +02:00
|
|
|
unread.mark_as_read(message.id);
|
2019-11-02 00:06:25 +01:00
|
|
|
const counts = unread.get_counts();
|
2016-11-16 00:09:09 +01:00
|
|
|
assert.equal(counts.private_message_count, 0);
|
2019-07-20 14:45:56 +02:00
|
|
|
test_notifiable_count(counts.home_unread_messages, 0);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|