2020-08-01 03:43:15 +02:00
|
|
|
"use strict";
|
|
|
|
|
2024-10-09 00:25:41 +02:00
|
|
|
const assert = require("node:assert/strict");
|
2020-11-30 23:46:45 +01:00
|
|
|
|
2023-04-11 07:12:59 +02:00
|
|
|
const {all_visibility_policies} = require("../src/user_topics");
|
2023-02-22 23:04:10 +01:00
|
|
|
|
|
|
|
const {zrequire} = require("./lib/namespace");
|
|
|
|
const {run_test} = require("./lib/test");
|
|
|
|
const blueslip = require("./lib/zblueslip");
|
2020-12-01 23:21:38 +01:00
|
|
|
|
2022-08-14 15:33:13 +02:00
|
|
|
const user_topics = zrequire("user_topics");
|
2021-02-10 04:53:22 +01:00
|
|
|
const stream_data = zrequire("stream_data");
|
2024-10-09 08:44:21 +02:00
|
|
|
const {initialize_user_settings} = zrequire("user_settings");
|
|
|
|
|
|
|
|
initialize_user_settings({user_settings: {}});
|
2013-08-20 22:05:56 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const design = {
|
2018-12-13 22:26:10 +01:00
|
|
|
stream_id: 100,
|
2020-07-15 01:29:15 +02:00
|
|
|
name: "design",
|
2018-12-13 22:26:10 +01:00
|
|
|
};
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const devel = {
|
2018-12-13 22:26:10 +01:00
|
|
|
stream_id: 101,
|
2020-07-15 01:29:15 +02:00
|
|
|
name: "devel",
|
2018-12-13 22:26:10 +01:00
|
|
|
};
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const office = {
|
2018-12-13 22:26:10 +01:00
|
|
|
stream_id: 102,
|
2020-07-15 01:29:15 +02:00
|
|
|
name: "office",
|
2018-12-13 22:26:10 +01:00
|
|
|
};
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const social = {
|
2018-12-13 22:26:10 +01:00
|
|
|
stream_id: 103,
|
2020-07-15 01:29:15 +02:00
|
|
|
name: "social",
|
2018-12-13 22:26:10 +01:00
|
|
|
};
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const unknown = {
|
2018-12-13 22:26:10 +01:00
|
|
|
stream_id: 999,
|
2020-07-15 01:29:15 +02:00
|
|
|
name: "whatever",
|
2018-12-13 22:26:10 +01:00
|
|
|
};
|
|
|
|
|
2020-02-09 22:02:55 +01:00
|
|
|
stream_data.add_sub(design);
|
|
|
|
stream_data.add_sub(devel);
|
|
|
|
stream_data.add_sub(office);
|
|
|
|
stream_data.add_sub(social);
|
2018-12-13 22:26:10 +01:00
|
|
|
|
2021-03-11 16:50:30 +01:00
|
|
|
function test(label, f) {
|
2021-06-16 14:38:37 +02:00
|
|
|
run_test(label, ({override}) => {
|
2022-08-29 14:16:25 +02:00
|
|
|
user_topics.set_user_topics([]);
|
2021-06-16 14:38:37 +02:00
|
|
|
f({override});
|
2021-03-11 16:50:30 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
test("edge_cases", () => {
|
2023-06-16 17:37:19 +02:00
|
|
|
// direct messages
|
2022-08-14 15:33:13 +02:00
|
|
|
assert.ok(!user_topics.is_topic_muted(undefined, undefined));
|
2021-03-11 16:50:30 +01:00
|
|
|
});
|
|
|
|
|
2021-03-27 12:42:16 +01:00
|
|
|
test("add_and_remove_mutes", () => {
|
2022-08-14 15:33:13 +02:00
|
|
|
assert.ok(!user_topics.is_topic_muted(devel.stream_id, "java"));
|
2024-03-30 23:39:51 +01:00
|
|
|
user_topics.update_user_topics(
|
|
|
|
devel.stream_id,
|
|
|
|
devel.name,
|
|
|
|
"java",
|
|
|
|
all_visibility_policies.MUTED,
|
|
|
|
);
|
2022-08-14 15:33:13 +02:00
|
|
|
assert.ok(user_topics.is_topic_muted(devel.stream_id, "java"));
|
2013-08-27 19:36:31 +02:00
|
|
|
|
2022-02-08 00:13:33 +01:00
|
|
|
// test idempotency
|
2024-03-30 23:39:51 +01:00
|
|
|
user_topics.update_user_topics(
|
|
|
|
devel.stream_id,
|
|
|
|
devel.name,
|
|
|
|
"java",
|
|
|
|
all_visibility_policies.MUTED,
|
|
|
|
);
|
2022-08-14 15:33:13 +02:00
|
|
|
assert.ok(user_topics.is_topic_muted(devel.stream_id, "java"));
|
2013-09-09 20:33:25 +02:00
|
|
|
|
2024-03-30 23:39:51 +01:00
|
|
|
user_topics.update_user_topics(
|
|
|
|
devel.stream_id,
|
|
|
|
devel.name,
|
|
|
|
"java",
|
|
|
|
all_visibility_policies.INHERIT,
|
|
|
|
);
|
2022-08-14 15:33:13 +02:00
|
|
|
assert.ok(!user_topics.is_topic_muted(devel.stream_id, "java"));
|
2013-09-09 20:33:25 +02:00
|
|
|
|
2022-02-08 00:13:33 +01:00
|
|
|
// test idempotency
|
2024-03-30 23:39:51 +01:00
|
|
|
user_topics.update_user_topics(
|
|
|
|
devel.stream_id,
|
|
|
|
devel.name,
|
|
|
|
"java",
|
|
|
|
all_visibility_policies.INHERIT,
|
|
|
|
);
|
2022-08-14 15:33:13 +02:00
|
|
|
assert.ok(!user_topics.is_topic_muted(devel.stream_id, "java"));
|
2013-09-09 20:33:25 +02:00
|
|
|
|
|
|
|
// test unknown stream is harmless too
|
2024-03-30 23:39:51 +01:00
|
|
|
user_topics.update_user_topics(
|
|
|
|
unknown.stream_id,
|
|
|
|
unknown.name,
|
|
|
|
"java",
|
|
|
|
all_visibility_policies.INHERIT,
|
|
|
|
);
|
2022-08-14 15:33:13 +02:00
|
|
|
assert.ok(!user_topics.is_topic_muted(unknown.stream_id, "java"));
|
2021-05-05 05:27:06 +02:00
|
|
|
});
|
|
|
|
|
2023-04-11 07:48:13 +02:00
|
|
|
test("add_and_remove_unmutes", () => {
|
|
|
|
assert.ok(!user_topics.is_topic_unmuted(devel.stream_id, "java"));
|
2024-03-30 23:39:51 +01:00
|
|
|
user_topics.update_user_topics(
|
|
|
|
devel.stream_id,
|
|
|
|
devel.name,
|
|
|
|
"java",
|
|
|
|
all_visibility_policies.UNMUTED,
|
|
|
|
);
|
2023-04-11 07:48:13 +02:00
|
|
|
assert.ok(user_topics.is_topic_unmuted(devel.stream_id, "java"));
|
|
|
|
|
|
|
|
// test idempotency
|
2024-03-30 23:39:51 +01:00
|
|
|
user_topics.update_user_topics(
|
|
|
|
devel.stream_id,
|
|
|
|
devel.name,
|
|
|
|
"java",
|
|
|
|
all_visibility_policies.UNMUTED,
|
|
|
|
);
|
2023-04-11 07:48:13 +02:00
|
|
|
assert.ok(user_topics.is_topic_unmuted(devel.stream_id, "java"));
|
|
|
|
|
2024-03-30 23:39:51 +01:00
|
|
|
user_topics.update_user_topics(
|
|
|
|
devel.stream_id,
|
|
|
|
devel.name,
|
|
|
|
"java",
|
|
|
|
all_visibility_policies.INHERIT,
|
|
|
|
);
|
2023-04-11 07:48:13 +02:00
|
|
|
assert.ok(!user_topics.is_topic_unmuted(devel.stream_id, "java"));
|
|
|
|
|
|
|
|
// test idempotency
|
2024-03-30 23:39:51 +01:00
|
|
|
user_topics.update_user_topics(
|
|
|
|
devel.stream_id,
|
|
|
|
devel.name,
|
|
|
|
"java",
|
|
|
|
all_visibility_policies.INHERIT,
|
|
|
|
);
|
2023-04-11 07:48:13 +02:00
|
|
|
assert.ok(!user_topics.is_topic_unmuted(devel.stream_id, "java"));
|
|
|
|
|
|
|
|
// test unknown stream is harmless too
|
2024-03-30 23:39:51 +01:00
|
|
|
user_topics.update_user_topics(
|
|
|
|
unknown.stream_id,
|
|
|
|
unknown.name,
|
|
|
|
"java",
|
|
|
|
all_visibility_policies.INHERIT,
|
|
|
|
);
|
2023-04-11 07:48:13 +02:00
|
|
|
assert.ok(!user_topics.is_topic_unmuted(unknown.stream_id, "java"));
|
|
|
|
});
|
|
|
|
|
2023-06-14 13:50:12 +02:00
|
|
|
test("add_and_remove_follows", () => {
|
|
|
|
assert.ok(!user_topics.is_topic_followed(devel.stream_id, "java"));
|
2024-03-30 23:39:51 +01:00
|
|
|
user_topics.update_user_topics(
|
|
|
|
devel.stream_id,
|
|
|
|
devel.name,
|
|
|
|
"java",
|
|
|
|
all_visibility_policies.FOLLOWED,
|
|
|
|
);
|
2023-06-14 13:50:12 +02:00
|
|
|
assert.ok(user_topics.is_topic_followed(devel.stream_id, "java"));
|
|
|
|
|
|
|
|
// test idempotency
|
2024-03-30 23:39:51 +01:00
|
|
|
user_topics.update_user_topics(
|
|
|
|
devel.stream_id,
|
|
|
|
devel.name,
|
|
|
|
"java",
|
|
|
|
all_visibility_policies.FOLLOWED,
|
|
|
|
);
|
2023-06-14 13:50:12 +02:00
|
|
|
assert.ok(user_topics.is_topic_followed(devel.stream_id, "java"));
|
|
|
|
|
2024-03-30 23:39:51 +01:00
|
|
|
user_topics.update_user_topics(
|
|
|
|
devel.stream_id,
|
|
|
|
devel.name,
|
|
|
|
"java",
|
|
|
|
all_visibility_policies.INHERIT,
|
|
|
|
);
|
2023-06-14 13:50:12 +02:00
|
|
|
assert.ok(!user_topics.is_topic_followed(devel.stream_id, "java"));
|
|
|
|
|
|
|
|
// test idempotency
|
2024-03-30 23:39:51 +01:00
|
|
|
user_topics.update_user_topics(
|
|
|
|
devel.stream_id,
|
|
|
|
devel.name,
|
|
|
|
"java",
|
|
|
|
all_visibility_policies.INHERIT,
|
|
|
|
);
|
2023-06-14 13:50:12 +02:00
|
|
|
assert.ok(!user_topics.is_topic_followed(devel.stream_id, "java"));
|
|
|
|
|
|
|
|
// test unknown stream is harmless too
|
2024-03-30 23:39:51 +01:00
|
|
|
user_topics.update_user_topics(
|
|
|
|
unknown.stream_id,
|
|
|
|
unknown.name,
|
|
|
|
"java",
|
|
|
|
all_visibility_policies.INHERIT,
|
|
|
|
);
|
2023-06-14 13:50:12 +02:00
|
|
|
assert.ok(!user_topics.is_topic_followed(unknown.stream_id, "java"));
|
|
|
|
});
|
|
|
|
|
2021-03-27 12:42:16 +01:00
|
|
|
test("get_mutes", () => {
|
2023-04-12 11:01:25 +02:00
|
|
|
assert.deepEqual(
|
|
|
|
user_topics.get_user_topics_for_visibility_policy(
|
|
|
|
user_topics.all_visibility_policies.MUTED,
|
|
|
|
),
|
|
|
|
[],
|
|
|
|
);
|
2023-04-11 07:48:13 +02:00
|
|
|
user_topics.update_user_topics(
|
|
|
|
office.stream_id,
|
2024-03-30 23:39:51 +01:00
|
|
|
office.name,
|
2023-04-11 07:48:13 +02:00
|
|
|
"gossip",
|
|
|
|
all_visibility_policies.MUTED,
|
|
|
|
1577836800,
|
|
|
|
);
|
|
|
|
user_topics.update_user_topics(
|
|
|
|
devel.stream_id,
|
2024-03-30 23:39:51 +01:00
|
|
|
devel.name,
|
2023-04-11 07:48:13 +02:00
|
|
|
"java",
|
|
|
|
all_visibility_policies.MUTED,
|
|
|
|
1577836700,
|
|
|
|
);
|
2022-08-14 15:33:13 +02:00
|
|
|
const all_muted_topics = user_topics
|
2023-04-12 11:01:25 +02:00
|
|
|
.get_user_topics_for_visibility_policy(user_topics.all_visibility_policies.MUTED)
|
|
|
|
.sort((a, b) => a.date_updated - b.date_updated);
|
2021-03-11 16:50:30 +01:00
|
|
|
|
2021-06-30 19:26:14 +02:00
|
|
|
assert.deepEqual(all_muted_topics, [
|
2020-02-05 13:14:24 +01:00
|
|
|
{
|
2023-04-12 11:01:25 +02:00
|
|
|
date_updated: 1577836700000,
|
|
|
|
date_updated_str: "Dec 31, 2019",
|
2020-02-05 13:14:24 +01:00
|
|
|
stream: devel.name,
|
|
|
|
stream_id: devel.stream_id,
|
2020-07-15 01:29:15 +02:00
|
|
|
topic: "java",
|
2023-04-24 15:40:26 +02:00
|
|
|
visibility_policy: all_visibility_policies.MUTED,
|
2020-02-05 13:14:24 +01:00
|
|
|
},
|
|
|
|
{
|
2023-04-12 11:01:25 +02:00
|
|
|
date_updated: 1577836800000,
|
|
|
|
date_updated_str: "Jan 1, 2020",
|
2020-02-05 13:14:24 +01:00
|
|
|
stream: office.name,
|
|
|
|
stream_id: office.stream_id,
|
2020-07-15 01:29:15 +02:00
|
|
|
topic: "gossip",
|
2023-04-24 15:40:26 +02:00
|
|
|
visibility_policy: all_visibility_policies.MUTED,
|
2020-07-15 00:34:28 +02:00
|
|
|
},
|
|
|
|
]);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2013-09-10 21:33:59 +02:00
|
|
|
|
2023-06-15 10:06:11 +02:00
|
|
|
test("get_unmutes", () => {
|
|
|
|
assert.deepEqual(
|
|
|
|
user_topics.get_user_topics_for_visibility_policy(
|
|
|
|
user_topics.all_visibility_policies.UNMUTED,
|
|
|
|
),
|
|
|
|
[],
|
|
|
|
);
|
|
|
|
user_topics.update_user_topics(
|
|
|
|
office.stream_id,
|
2024-03-30 23:39:51 +01:00
|
|
|
office.name,
|
2023-06-15 10:06:11 +02:00
|
|
|
"gossip",
|
|
|
|
all_visibility_policies.UNMUTED,
|
|
|
|
1577836800,
|
|
|
|
);
|
|
|
|
user_topics.update_user_topics(
|
|
|
|
devel.stream_id,
|
2024-03-30 23:39:51 +01:00
|
|
|
devel.name,
|
2023-06-15 10:06:11 +02:00
|
|
|
"java",
|
|
|
|
all_visibility_policies.UNMUTED,
|
|
|
|
1577836700,
|
|
|
|
);
|
|
|
|
const all_unmuted_topics = user_topics
|
|
|
|
.get_user_topics_for_visibility_policy(user_topics.all_visibility_policies.UNMUTED)
|
|
|
|
.sort((a, b) => a.date_updated - b.date_updated);
|
|
|
|
|
|
|
|
assert.deepEqual(all_unmuted_topics, [
|
|
|
|
{
|
|
|
|
date_updated: 1577836700000,
|
|
|
|
date_updated_str: "Dec 31, 2019",
|
|
|
|
stream: devel.name,
|
|
|
|
stream_id: devel.stream_id,
|
|
|
|
topic: "java",
|
|
|
|
visibility_policy: all_visibility_policies.UNMUTED,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
date_updated: 1577836800000,
|
|
|
|
date_updated_str: "Jan 1, 2020",
|
|
|
|
stream: office.name,
|
|
|
|
stream_id: office.stream_id,
|
|
|
|
topic: "gossip",
|
|
|
|
visibility_policy: all_visibility_policies.UNMUTED,
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
2023-06-14 13:50:12 +02:00
|
|
|
test("get_follows", () => {
|
|
|
|
assert.deepEqual(
|
|
|
|
user_topics.get_user_topics_for_visibility_policy(
|
|
|
|
user_topics.all_visibility_policies.FOLLOWED,
|
|
|
|
),
|
|
|
|
[],
|
|
|
|
);
|
|
|
|
user_topics.update_user_topics(
|
|
|
|
office.stream_id,
|
2024-03-30 23:39:51 +01:00
|
|
|
office.name,
|
2023-06-14 13:50:12 +02:00
|
|
|
"gossip",
|
|
|
|
all_visibility_policies.FOLLOWED,
|
|
|
|
1577836800,
|
|
|
|
);
|
|
|
|
user_topics.update_user_topics(
|
|
|
|
devel.stream_id,
|
2024-03-30 23:39:51 +01:00
|
|
|
devel.name,
|
2023-06-14 13:50:12 +02:00
|
|
|
"java",
|
|
|
|
all_visibility_policies.FOLLOWED,
|
|
|
|
1577836700,
|
|
|
|
);
|
|
|
|
const all_followed_topics = user_topics
|
|
|
|
.get_user_topics_for_visibility_policy(user_topics.all_visibility_policies.FOLLOWED)
|
|
|
|
.sort((a, b) => a.date_updated - b.date_updated);
|
|
|
|
|
|
|
|
assert.deepEqual(all_followed_topics, [
|
|
|
|
{
|
|
|
|
date_updated: 1577836700000,
|
|
|
|
date_updated_str: "Dec 31, 2019",
|
|
|
|
stream: devel.name,
|
|
|
|
stream_id: devel.stream_id,
|
|
|
|
topic: "java",
|
|
|
|
visibility_policy: all_visibility_policies.FOLLOWED,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
date_updated: 1577836800000,
|
|
|
|
date_updated_str: "Jan 1, 2020",
|
|
|
|
stream: office.name,
|
|
|
|
stream_id: office.stream_id,
|
|
|
|
topic: "gossip",
|
|
|
|
visibility_policy: all_visibility_policies.FOLLOWED,
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
2022-08-25 23:25:19 +02:00
|
|
|
test("set_user_topics", () => {
|
|
|
|
blueslip.expect("warn", "Unknown stream ID in set_user_topic: 999");
|
|
|
|
|
2022-08-29 14:16:25 +02:00
|
|
|
user_topics.set_user_topics([]);
|
2022-08-25 23:25:19 +02:00
|
|
|
assert.ok(!user_topics.is_topic_muted(social.stream_id, "breakfast"));
|
|
|
|
assert.ok(!user_topics.is_topic_muted(design.stream_id, "typography"));
|
2023-06-15 10:06:11 +02:00
|
|
|
assert.ok(!user_topics.is_topic_unmuted(office.stream_id, "lunch"));
|
2023-06-14 13:50:12 +02:00
|
|
|
assert.ok(!user_topics.is_topic_followed(devel.stream_id, "dinner"));
|
2022-08-25 23:25:19 +02:00
|
|
|
|
2023-09-10 14:06:14 +02:00
|
|
|
const test_user_topics_params = [
|
2022-08-25 23:25:19 +02:00
|
|
|
{
|
|
|
|
stream_id: social.stream_id,
|
|
|
|
topic_name: "breakfast",
|
2023-09-10 14:06:14 +02:00
|
|
|
last_updated: 1577836800,
|
2023-04-11 07:12:59 +02:00
|
|
|
visibility_policy: all_visibility_policies.MUTED,
|
2022-08-25 23:25:19 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
stream_id: design.stream_id,
|
|
|
|
topic_name: "typography",
|
2023-09-10 14:06:14 +02:00
|
|
|
last_updated: 1577836800,
|
2023-04-11 07:12:59 +02:00
|
|
|
visibility_policy: all_visibility_policies.MUTED,
|
2022-08-25 23:25:19 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
stream_id: 999, // BOGUS STREAM ID
|
|
|
|
topic_name: "random",
|
2023-09-10 14:06:14 +02:00
|
|
|
last_updated: 1577836800,
|
2023-04-11 07:12:59 +02:00
|
|
|
visibility_policy: all_visibility_policies.MUTED,
|
2022-08-25 23:25:19 +02:00
|
|
|
},
|
2023-06-15 10:06:11 +02:00
|
|
|
{
|
|
|
|
stream_id: office.stream_id,
|
|
|
|
topic_name: "lunch",
|
2023-09-10 14:06:14 +02:00
|
|
|
last_updated: 1577836800,
|
2023-06-15 10:06:11 +02:00
|
|
|
visibility_policy: all_visibility_policies.UNMUTED,
|
|
|
|
},
|
2023-06-14 13:50:12 +02:00
|
|
|
{
|
|
|
|
stream_id: devel.stream_id,
|
|
|
|
topic_name: "dinner",
|
2023-09-10 14:06:14 +02:00
|
|
|
last_updated: 1577836800,
|
2023-06-14 13:50:12 +02:00
|
|
|
visibility_policy: all_visibility_policies.FOLLOWED,
|
|
|
|
},
|
2022-08-25 23:25:19 +02:00
|
|
|
];
|
|
|
|
|
2023-09-10 14:06:14 +02:00
|
|
|
user_topics.initialize({user_topics: test_user_topics_params});
|
2022-08-25 23:25:19 +02:00
|
|
|
|
2023-04-12 11:01:25 +02:00
|
|
|
assert.deepEqual(
|
|
|
|
user_topics
|
|
|
|
.get_user_topics_for_visibility_policy(user_topics.all_visibility_policies.MUTED)
|
|
|
|
.sort(),
|
|
|
|
[
|
|
|
|
{
|
|
|
|
date_updated: 1577836800000,
|
|
|
|
date_updated_str: "Jan 1, 2020",
|
|
|
|
stream: social.name,
|
|
|
|
stream_id: social.stream_id,
|
|
|
|
topic: "breakfast",
|
2023-04-24 15:40:26 +02:00
|
|
|
visibility_policy: all_visibility_policies.MUTED,
|
2023-04-12 11:01:25 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
date_updated: 1577836800000,
|
|
|
|
date_updated_str: "Jan 1, 2020",
|
|
|
|
stream: design.name,
|
|
|
|
stream_id: design.stream_id,
|
|
|
|
topic: "typography",
|
2023-04-24 15:40:26 +02:00
|
|
|
visibility_policy: all_visibility_policies.MUTED,
|
2023-04-12 11:01:25 +02:00
|
|
|
},
|
|
|
|
],
|
|
|
|
);
|
2022-08-25 23:25:19 +02:00
|
|
|
|
2023-06-15 10:06:11 +02:00
|
|
|
assert.deepEqual(
|
|
|
|
user_topics
|
|
|
|
.get_user_topics_for_visibility_policy(user_topics.all_visibility_policies.UNMUTED)
|
|
|
|
.sort(),
|
|
|
|
[
|
|
|
|
{
|
|
|
|
date_updated: 1577836800000,
|
|
|
|
date_updated_str: "Jan 1, 2020",
|
|
|
|
stream: office.name,
|
|
|
|
stream_id: office.stream_id,
|
|
|
|
topic: "lunch",
|
|
|
|
visibility_policy: all_visibility_policies.UNMUTED,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
);
|
|
|
|
|
2023-06-14 13:50:12 +02:00
|
|
|
assert.deepEqual(
|
|
|
|
user_topics
|
|
|
|
.get_user_topics_for_visibility_policy(user_topics.all_visibility_policies.FOLLOWED)
|
|
|
|
.sort(),
|
|
|
|
[
|
|
|
|
{
|
|
|
|
date_updated: 1577836800000,
|
|
|
|
date_updated_str: "Jan 1, 2020",
|
|
|
|
stream: devel.name,
|
|
|
|
stream_id: devel.stream_id,
|
|
|
|
topic: "dinner",
|
|
|
|
visibility_policy: all_visibility_policies.FOLLOWED,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
);
|
|
|
|
|
2022-08-25 23:25:19 +02:00
|
|
|
user_topics.set_user_topic({
|
|
|
|
stream_id: design.stream_id,
|
|
|
|
topic_name: "typography",
|
|
|
|
last_updated: "1577836800",
|
2023-04-11 07:12:59 +02:00
|
|
|
visibility_policy: all_visibility_policies.INHERIT,
|
2022-08-25 23:25:19 +02:00
|
|
|
});
|
|
|
|
assert.ok(!user_topics.is_topic_muted(design.stream_id, "typography"));
|
2023-06-15 10:06:11 +02:00
|
|
|
|
|
|
|
user_topics.set_user_topic({
|
|
|
|
stream_id: office.stream_id,
|
|
|
|
topic_name: "lunch",
|
|
|
|
last_updated: "1577836800",
|
|
|
|
visibility_policy: all_visibility_policies.INHERIT,
|
|
|
|
});
|
|
|
|
assert.ok(!user_topics.is_topic_unmuted(devel.stream_id, "lunch"));
|
2023-06-14 13:50:12 +02:00
|
|
|
|
|
|
|
user_topics.set_user_topic({
|
|
|
|
stream_id: devel.stream_id,
|
|
|
|
topic_name: "dinner",
|
|
|
|
last_updated: "1577836800",
|
|
|
|
visibility_policy: all_visibility_policies.INHERIT,
|
|
|
|
});
|
|
|
|
assert.ok(!user_topics.is_topic_followed(devel.stream_id, "dinner"));
|
2022-08-25 23:25:19 +02:00
|
|
|
});
|
|
|
|
|
2021-03-11 16:50:30 +01:00
|
|
|
test("case_insensitivity", () => {
|
2022-08-29 14:16:25 +02:00
|
|
|
user_topics.set_user_topics([]);
|
2022-08-14 15:33:13 +02:00
|
|
|
assert.ok(!user_topics.is_topic_muted(social.stream_id, "breakfast"));
|
2022-08-29 14:16:25 +02:00
|
|
|
user_topics.set_user_topics([
|
2022-08-26 22:59:07 +02:00
|
|
|
{
|
|
|
|
stream_id: social.stream_id,
|
|
|
|
topic_name: "breakfast",
|
|
|
|
last_updated: "1577836800",
|
2023-04-11 07:12:59 +02:00
|
|
|
visibility_policy: all_visibility_policies.MUTED,
|
2022-08-26 22:59:07 +02:00
|
|
|
},
|
|
|
|
]);
|
2022-08-14 15:33:13 +02:00
|
|
|
assert.ok(user_topics.is_topic_muted(social.stream_id, "breakfast"));
|
|
|
|
assert.ok(user_topics.is_topic_muted(social.stream_id, "breakFAST"));
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|