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-02-22 23:04:10 +01:00
|
|
|
const {mock_esm, set_global, zrequire} = require("./lib/namespace");
|
2023-12-14 23:51:33 +01:00
|
|
|
const {run_test, noop} = require("./lib/test");
|
2023-02-22 23:04:10 +01:00
|
|
|
const blueslip = require("./lib/zblueslip");
|
2020-12-01 00:02:16 +01:00
|
|
|
|
2024-06-12 12:04:08 +02:00
|
|
|
mock_esm("../src/settings_data", {
|
|
|
|
user_can_access_all_other_users: () => true,
|
|
|
|
});
|
|
|
|
|
2023-02-22 23:04:10 +01:00
|
|
|
mock_esm("../src/stream_topic_history", {
|
2017-07-26 14:05:25 +02:00
|
|
|
add_message: noop,
|
2017-06-20 00:40:43 +02:00
|
|
|
});
|
|
|
|
|
2023-02-22 23:04:10 +01:00
|
|
|
mock_esm("../src/recent_senders", {
|
2022-11-22 11:45:29 +01:00
|
|
|
process_stream_message: noop,
|
2022-11-19 07:39:00 +01:00
|
|
|
process_private_message: noop,
|
2017-06-20 00:40:43 +02:00
|
|
|
});
|
|
|
|
|
2021-03-09 13:31:47 +01:00
|
|
|
set_global("document", "document-stub");
|
2017-06-20 00:40:43 +02:00
|
|
|
|
2020-12-01 23:21:38 +01:00
|
|
|
const util = zrequire("util");
|
|
|
|
const people = zrequire("people");
|
|
|
|
const pm_conversations = zrequire("pm_conversations");
|
2021-03-28 17:57:53 +02:00
|
|
|
const message_helper = zrequire("message_helper");
|
2020-12-01 23:21:38 +01:00
|
|
|
const message_store = zrequire("message_store");
|
2021-03-28 17:57:53 +02:00
|
|
|
const message_user_ids = zrequire("message_user_ids");
|
2024-10-09 22:44:13 +02:00
|
|
|
const {set_realm} = zrequire("state_data");
|
2024-10-09 08:44:21 +02:00
|
|
|
const {initialize_user_settings} = zrequire("user_settings");
|
|
|
|
|
2024-10-09 22:44:13 +02:00
|
|
|
set_realm({});
|
2024-10-09 08:44:21 +02:00
|
|
|
initialize_user_settings({user_settings: {}});
|
2020-12-01 23:21:38 +01:00
|
|
|
|
2020-07-26 23:39:32 +02:00
|
|
|
const denmark = {
|
|
|
|
subscribed: false,
|
|
|
|
name: "Denmark",
|
|
|
|
stream_id: 20,
|
|
|
|
};
|
|
|
|
|
|
|
|
const devel = {
|
|
|
|
subscribed: true,
|
|
|
|
name: "Devel",
|
|
|
|
stream_id: 21,
|
|
|
|
};
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const me = {
|
2020-07-15 01:29:15 +02:00
|
|
|
email: "me@example.com",
|
2016-11-18 19:08:41 +01:00
|
|
|
user_id: 101,
|
2020-07-15 01:29:15 +02:00
|
|
|
full_name: "Me Myself",
|
2016-11-18 19:08:41 +01:00
|
|
|
};
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const alice = {
|
2020-07-15 01:29:15 +02:00
|
|
|
email: "alice@example.com",
|
2016-11-18 19:08:41 +01:00
|
|
|
user_id: 102,
|
2020-07-15 01:29:15 +02:00
|
|
|
full_name: "Alice",
|
2016-11-18 19:08:41 +01: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-18 19:08:41 +01:00
|
|
|
user_id: 103,
|
2020-07-15 01:29:15 +02:00
|
|
|
full_name: "Bob",
|
2016-11-18 19:08:41 +01:00
|
|
|
};
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const cindy = {
|
2020-07-15 01:29:15 +02:00
|
|
|
email: "cindy@example.com",
|
2016-11-18 19:08:41 +01:00
|
|
|
user_id: 104,
|
2020-07-15 01:29:15 +02:00
|
|
|
full_name: "Cindy",
|
2016-11-18 19:08:41 +01:00
|
|
|
};
|
|
|
|
|
2020-07-16 23:29:01 +02:00
|
|
|
const denise = {
|
2020-07-15 01:29:15 +02:00
|
|
|
email: "denise@example.com",
|
2020-01-02 14:42:55 +01:00
|
|
|
user_id: 105,
|
2020-07-15 01:29:15 +02:00
|
|
|
full_name: "Denise ",
|
2020-01-02 14:42:55 +01:00
|
|
|
};
|
|
|
|
|
2020-05-26 22:34:15 +02:00
|
|
|
people.add_active_user(me);
|
|
|
|
people.add_active_user(alice);
|
|
|
|
people.add_active_user(bob);
|
|
|
|
people.add_active_user(cindy);
|
|
|
|
people.add_active_user(denise);
|
2016-11-18 19:08:41 +01:00
|
|
|
|
2020-03-21 21:54:16 +01:00
|
|
|
people.initialize_current_user(me.user_id);
|
2017-01-19 23:04:52 +01:00
|
|
|
|
2020-01-01 13:02:34 +01:00
|
|
|
function convert_recipients(people) {
|
|
|
|
// Display_recipient uses `id` for user_ids.
|
2020-07-02 01:39:34 +02:00
|
|
|
return people.map((p) => ({
|
js: Convert _.map(a, …) to a.map(…).
And convert the corresponding function expressions to arrow style
while we’re here.
import * as babelParser from "recast/parsers/babel";
import * as recast from "recast";
import * as tsParser from "recast/parsers/typescript";
import { builders as b, namedTypes as n } from "ast-types";
import K from "ast-types/gen/kinds";
import fs from "fs";
import path from "path";
import process from "process";
const checkExpression = (node: n.Node): node is K.ExpressionKind =>
n.Expression.check(node);
for (const file of process.argv.slice(2)) {
console.log("Parsing", file);
const ast = recast.parse(fs.readFileSync(file, { encoding: "utf8" }), {
parser: path.extname(file) === ".ts" ? tsParser : babelParser,
});
let changed = false;
recast.visit(ast, {
visitCallExpression(path) {
const { callee, arguments: args } = path.node;
if (
n.MemberExpression.check(callee) &&
!callee.computed &&
n.Identifier.check(callee.object) &&
callee.object.name === "_" &&
n.Identifier.check(callee.property) &&
callee.property.name === "map" &&
args.length === 2 &&
checkExpression(args[0]) &&
checkExpression(args[1])
) {
const [arr, fn] = args;
path.replace(
b.callExpression(b.memberExpression(arr, b.identifier("map")), [
n.FunctionExpression.check(fn) ||
n.ArrowFunctionExpression.check(fn)
? b.arrowFunctionExpression(
fn.params,
n.BlockStatement.check(fn.body) &&
fn.body.body.length === 1 &&
n.ReturnStatement.check(fn.body.body[0])
? fn.body.body[0].argument || b.identifier("undefined")
: fn.body
)
: fn,
])
);
changed = true;
}
this.traverse(path);
},
});
if (changed) {
console.log("Writing", file);
fs.writeFileSync(file, recast.print(ast).code, { encoding: "utf8" });
}
}
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-08 02:43:49 +01:00
|
|
|
email: p.email,
|
|
|
|
id: p.user_id,
|
|
|
|
full_name: p.full_name,
|
|
|
|
}));
|
2020-01-01 13:02:34 +01:00
|
|
|
}
|
|
|
|
|
2021-03-09 13:51:07 +01:00
|
|
|
function test(label, f) {
|
2022-07-09 23:25:05 +02:00
|
|
|
run_test(label, (helpers) => {
|
2021-03-09 13:51:07 +01:00
|
|
|
message_store.clear_for_testing();
|
2021-04-03 18:23:49 +02:00
|
|
|
message_user_ids.clear_for_testing();
|
2022-07-09 23:25:05 +02:00
|
|
|
f(helpers);
|
2021-03-09 13:51:07 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-03-28 17:57:53 +02:00
|
|
|
test("process_new_message", () => {
|
2019-11-02 00:06:25 +01:00
|
|
|
let message = {
|
2020-07-15 01:29:15 +02:00
|
|
|
sender_email: "me@example.com",
|
2017-01-24 23:10:01 +01:00
|
|
|
sender_id: me.user_id,
|
2020-07-15 01:29:15 +02:00
|
|
|
type: "private",
|
2020-01-01 13:02:34 +01:00
|
|
|
display_recipient: convert_recipients([me, bob, cindy]),
|
2020-07-15 01:29:15 +02:00
|
|
|
flags: ["has_alert_word"],
|
2017-08-27 18:10:36 +02:00
|
|
|
is_me_message: false,
|
2017-06-20 00:40:43 +02:00
|
|
|
id: 2067,
|
2016-11-18 19:08:41 +01:00
|
|
|
};
|
2024-05-28 22:06:15 +02:00
|
|
|
message = message_helper.process_new_message(message);
|
2016-11-18 19:08:41 +01:00
|
|
|
|
2021-03-28 17:57:53 +02:00
|
|
|
assert.deepEqual(message_user_ids.user_ids().sort(), [me.user_id, bob.user_id, cindy.user_id]);
|
2020-01-02 14:42:55 +01:00
|
|
|
|
2016-11-18 19:08:41 +01:00
|
|
|
assert.equal(message.is_private, true);
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(message.reply_to, "bob@example.com,cindy@example.com");
|
|
|
|
assert.equal(message.to_user_ids, "103,104");
|
|
|
|
assert.equal(message.display_reply_to, "Bob, Cindy");
|
2016-11-18 19:08:41 +01:00
|
|
|
assert.equal(message.alerted, true);
|
|
|
|
assert.equal(message.is_me_message, false);
|
2017-06-20 00:40:43 +02:00
|
|
|
|
2024-01-05 07:53:23 +01:00
|
|
|
const retrieved_message = message_store.get(2067);
|
2017-06-20 00:40:43 +02:00
|
|
|
assert.equal(retrieved_message, message);
|
|
|
|
|
|
|
|
// access cached previous message, and test match subject/content
|
|
|
|
message = {
|
|
|
|
id: 2067,
|
2018-11-15 16:59:41 +01:00
|
|
|
match_subject: "topic foo",
|
2017-06-20 00:40:43 +02:00
|
|
|
match_content: "bar content",
|
|
|
|
};
|
2021-03-28 17:57:53 +02:00
|
|
|
message = message_helper.process_new_message(message);
|
2017-06-20 00:40:43 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(message.reply_to, "bob@example.com,cindy@example.com");
|
|
|
|
assert.equal(message.to_user_ids, "103,104");
|
|
|
|
assert.equal(message.display_reply_to, "Bob, Cindy");
|
|
|
|
assert.equal(util.get_match_topic(message), "topic foo");
|
|
|
|
assert.equal(message.match_content, "bar content");
|
2017-06-20 00:40:43 +02:00
|
|
|
|
|
|
|
message = {
|
2020-01-02 14:42:55 +01:00
|
|
|
sender_email: denise.email,
|
|
|
|
sender_id: denise.user_id,
|
2020-07-15 01:29:15 +02:00
|
|
|
type: "stream",
|
|
|
|
display_recipient: "Zoolippy",
|
|
|
|
topic: "cool thing",
|
|
|
|
subject: "the_subject",
|
2017-06-20 00:40:43 +02:00
|
|
|
id: 2068,
|
|
|
|
};
|
|
|
|
|
2024-05-28 22:06:15 +02:00
|
|
|
message = message_helper.process_new_message(message);
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(message.reply_to, "denise@example.com");
|
2018-07-19 19:29:07 +02:00
|
|
|
assert.deepEqual(message.flags, undefined);
|
|
|
|
assert.equal(message.alerted, false);
|
2020-01-02 14:42:55 +01:00
|
|
|
|
2021-03-28 17:57:53 +02:00
|
|
|
assert.deepEqual(message_user_ids.user_ids().sort(), [
|
2020-07-15 00:34:28 +02:00
|
|
|
me.user_id,
|
|
|
|
bob.user_id,
|
|
|
|
cindy.user_id,
|
|
|
|
denise.user_id,
|
|
|
|
]);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-06-20 02:23:34 +02:00
|
|
|
|
2021-03-09 13:51:07 +01:00
|
|
|
test("message_booleans_parity", () => {
|
2019-09-27 11:21:27 +02:00
|
|
|
// We have two code paths that update/set message booleans.
|
|
|
|
// This test asserts that both have identical behavior for the
|
|
|
|
// flags common between them.
|
|
|
|
const assert_bool_match = (flags, expected_message) => {
|
2024-06-03 22:18:33 +02:00
|
|
|
let set_message = {topic: "convert_raw_message_to_message_with_booleans", flags};
|
2020-07-15 01:29:15 +02:00
|
|
|
const update_message = {topic: "update_booleans"};
|
2024-06-03 22:18:33 +02:00
|
|
|
set_message = message_store.convert_raw_message_to_message_with_booleans(set_message);
|
2019-09-27 11:21:27 +02:00
|
|
|
message_store.update_booleans(update_message, flags);
|
2021-01-22 22:29:08 +01:00
|
|
|
for (const key of Object.keys(expected_message)) {
|
2020-07-15 00:34:28 +02:00
|
|
|
assert.equal(
|
|
|
|
set_message[key],
|
|
|
|
expected_message[key],
|
|
|
|
`'${key}' != ${expected_message[key]}`,
|
|
|
|
);
|
2019-09-27 11:21:27 +02:00
|
|
|
assert.equal(update_message[key], expected_message[key]);
|
2021-01-22 22:29:08 +01:00
|
|
|
}
|
2024-06-03 22:18:33 +02:00
|
|
|
assert.equal(set_message.topic, "convert_raw_message_to_message_with_booleans");
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(update_message.topic, "update_booleans");
|
2019-09-27 11:21:27 +02:00
|
|
|
};
|
|
|
|
|
2023-11-03 15:20:44 +01:00
|
|
|
assert_bool_match(["stream_wildcard_mentioned"], {
|
2020-07-15 00:34:28 +02:00
|
|
|
mentioned: true,
|
|
|
|
mentioned_me_directly: false,
|
2023-11-03 15:20:44 +01:00
|
|
|
stream_wildcard_mentioned: true,
|
|
|
|
topic_wildcard_mentioned: false,
|
|
|
|
alerted: false,
|
|
|
|
});
|
|
|
|
|
|
|
|
assert_bool_match(["topic_wildcard_mentioned"], {
|
|
|
|
mentioned: true,
|
|
|
|
mentioned_me_directly: false,
|
|
|
|
stream_wildcard_mentioned: false,
|
|
|
|
topic_wildcard_mentioned: true,
|
2020-07-15 00:34:28 +02:00
|
|
|
alerted: false,
|
|
|
|
});
|
|
|
|
|
|
|
|
assert_bool_match(["mentioned"], {
|
|
|
|
mentioned: true,
|
|
|
|
mentioned_me_directly: true,
|
2023-11-03 15:20:44 +01:00
|
|
|
stream_wildcard_mentioned: false,
|
|
|
|
topic_wildcard_mentioned: false,
|
2020-07-15 00:34:28 +02:00
|
|
|
alerted: false,
|
|
|
|
});
|
|
|
|
|
|
|
|
assert_bool_match(["has_alert_word"], {
|
|
|
|
mentioned: false,
|
|
|
|
mentioned_me_directly: false,
|
2023-11-03 15:20:44 +01:00
|
|
|
stream_wildcard_mentioned: false,
|
|
|
|
topic_wildcard_mentioned: false,
|
2020-07-15 00:34:28 +02:00
|
|
|
alerted: true,
|
|
|
|
});
|
2019-09-27 11:21:27 +02:00
|
|
|
});
|
|
|
|
|
2022-07-09 23:25:05 +02:00
|
|
|
test("errors", ({disallow_rewire}) => {
|
2017-06-20 02:23:34 +02:00
|
|
|
// Test a user that doesn't exist
|
2019-11-02 00:06:25 +01:00
|
|
|
let message = {
|
2020-07-15 01:29:15 +02:00
|
|
|
type: "private",
|
2020-01-01 13:02:34 +01:00
|
|
|
display_recipient: [{id: 92714}],
|
2017-06-20 02:23:34 +02:00
|
|
|
};
|
2017-06-20 03:20:02 +02:00
|
|
|
|
2023-12-01 11:53:45 +01:00
|
|
|
blueslip.expect("error", "Unknown user_id in maybe_get_user_by_id", 1);
|
|
|
|
blueslip.expect("error", "Unknown user id", 1); // From person.js
|
2017-06-20 03:20:02 +02:00
|
|
|
|
|
|
|
// Expect each to throw two blueslip errors
|
2024-02-10 19:50:32 +01:00
|
|
|
// One from message_store.ts, one from person.js
|
2019-11-02 00:06:25 +01:00
|
|
|
const emails = message_store.get_pm_emails(message);
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(emails, "?");
|
2017-06-20 02:23:34 +02:00
|
|
|
|
2023-12-01 11:53:45 +01:00
|
|
|
assert.throws(
|
|
|
|
() => {
|
2024-05-09 07:50:33 +02:00
|
|
|
message_store.get_pm_full_names(people.pm_with_user_ids(message));
|
2023-12-01 11:53:45 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Error",
|
|
|
|
message: "Unknown user_id in get_by_user_id: 92714",
|
|
|
|
},
|
|
|
|
);
|
2018-05-01 01:16:02 +02:00
|
|
|
|
2017-06-20 02:23:34 +02:00
|
|
|
message = {
|
2020-07-15 01:29:15 +02:00
|
|
|
type: "stream",
|
2017-06-20 02:23:34 +02:00
|
|
|
display_recipient: [{}],
|
|
|
|
};
|
|
|
|
|
2021-02-22 19:13:00 +01:00
|
|
|
// This should early return and not run pm_conversations.set_partner
|
2022-07-09 23:25:05 +02:00
|
|
|
disallow_rewire(pm_conversations, "set_partner");
|
|
|
|
pm_conversations.process_message(message);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-06-20 03:20:02 +02:00
|
|
|
|
2021-03-28 19:08:25 +02:00
|
|
|
test("reify_message_id", () => {
|
|
|
|
const message = {type: "private", id: 500};
|
|
|
|
|
|
|
|
message_store.update_message_cache(message);
|
|
|
|
assert.equal(message_store.get_cached_message(500), message);
|
|
|
|
|
|
|
|
message_store.reify_message_id({old_id: 500, new_id: 501});
|
|
|
|
assert.equal(message_store.get_cached_message(500), undefined);
|
|
|
|
assert.equal(message_store.get_cached_message(501), message);
|
|
|
|
});
|
|
|
|
|
2021-03-09 13:51:07 +01:00
|
|
|
test("update_booleans", () => {
|
2019-11-02 00:06:25 +01:00
|
|
|
const message = {};
|
2017-12-16 23:25:31 +01:00
|
|
|
|
|
|
|
// First, test fields that we do actually want to update.
|
|
|
|
message.mentioned = false;
|
|
|
|
message.mentioned_me_directly = false;
|
2023-11-03 15:20:44 +01:00
|
|
|
message.stream_wildcard_mentioned = false;
|
|
|
|
message.topic_wildcard_mentioned = false;
|
2017-12-16 23:25:31 +01:00
|
|
|
message.alerted = false;
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
let flags = ["mentioned", "has_alert_word", "read"];
|
2017-12-16 23:25:31 +01:00
|
|
|
message_store.update_booleans(message, flags);
|
|
|
|
assert.equal(message.mentioned, true);
|
|
|
|
assert.equal(message.mentioned_me_directly, true);
|
2023-11-03 15:20:44 +01:00
|
|
|
assert.equal(message.stream_wildcard_mentioned, false);
|
|
|
|
assert.equal(message.topic_wildcard_mentioned, false);
|
2017-12-16 23:25:31 +01:00
|
|
|
assert.equal(message.alerted, true);
|
|
|
|
|
2023-11-03 15:20:44 +01:00
|
|
|
flags = ["stream_wildcard_mentioned", "unread"];
|
|
|
|
message_store.update_booleans(message, flags);
|
|
|
|
assert.equal(message.mentioned, true);
|
|
|
|
assert.equal(message.mentioned_me_directly, false);
|
|
|
|
assert.equal(message.stream_wildcard_mentioned, true);
|
|
|
|
assert.equal(message.topic_wildcard_mentioned, false);
|
|
|
|
|
|
|
|
flags = ["topic_wildcard_mentioned", "unread"];
|
2019-09-27 11:11:40 +02:00
|
|
|
message_store.update_booleans(message, flags);
|
|
|
|
assert.equal(message.mentioned, true);
|
|
|
|
assert.equal(message.mentioned_me_directly, false);
|
2023-11-03 15:20:44 +01:00
|
|
|
assert.equal(message.stream_wildcard_mentioned, false);
|
|
|
|
assert.equal(message.topic_wildcard_mentioned, true);
|
2019-09-27 11:11:40 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
flags = ["read"];
|
2017-12-16 23:25:31 +01:00
|
|
|
message_store.update_booleans(message, flags);
|
|
|
|
assert.equal(message.mentioned, false);
|
|
|
|
assert.equal(message.mentioned_me_directly, false);
|
|
|
|
assert.equal(message.alerted, false);
|
2023-11-03 15:20:44 +01:00
|
|
|
assert.equal(message.stream_wildcard_mentioned, false);
|
|
|
|
assert.equal(message.topic_wildcard_mentioned, false);
|
2017-12-16 23:25:31 +01:00
|
|
|
|
|
|
|
// Make sure we don't muck with unread.
|
|
|
|
message.unread = false;
|
2020-07-15 01:29:15 +02:00
|
|
|
flags = [""];
|
2017-12-16 23:25:31 +01:00
|
|
|
message_store.update_booleans(message, flags);
|
|
|
|
assert.equal(message.unread, false);
|
|
|
|
|
|
|
|
message.unread = true;
|
2020-07-15 01:29:15 +02:00
|
|
|
flags = ["read"];
|
2017-12-16 23:25:31 +01:00
|
|
|
message_store.update_booleans(message, flags);
|
|
|
|
assert.equal(message.unread, true);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-12-16 23:25:31 +01:00
|
|
|
|
2021-03-09 13:51:07 +01:00
|
|
|
test("update_property", () => {
|
2024-05-28 22:06:15 +02:00
|
|
|
let message1 = {
|
2020-07-26 20:28:40 +02:00
|
|
|
type: "stream",
|
|
|
|
sender_full_name: alice.full_name,
|
|
|
|
sender_id: alice.user_id,
|
2020-07-26 23:17:30 +02:00
|
|
|
small_avatar_url: "alice_url",
|
2020-07-26 23:39:32 +02:00
|
|
|
stream_id: devel.stream_id,
|
2024-05-28 08:11:17 +02:00
|
|
|
topic: "",
|
2020-07-26 23:39:32 +02:00
|
|
|
display_recipient: devel.name,
|
2020-07-26 20:28:40 +02:00
|
|
|
id: 100,
|
|
|
|
};
|
2024-05-28 22:06:15 +02:00
|
|
|
let message2 = {
|
2020-07-26 20:28:40 +02:00
|
|
|
type: "stream",
|
|
|
|
sender_full_name: bob.full_name,
|
|
|
|
sender_id: bob.user_id,
|
2020-07-26 23:17:30 +02:00
|
|
|
small_avatar_url: "bob_url",
|
2020-07-26 23:39:32 +02:00
|
|
|
stream_id: denmark.stream_id,
|
2024-05-28 08:11:17 +02:00
|
|
|
topic: "",
|
2020-07-26 23:39:32 +02:00
|
|
|
display_recipient: denmark.name,
|
2020-07-26 20:28:40 +02:00
|
|
|
id: 101,
|
|
|
|
};
|
2024-05-28 22:06:15 +02:00
|
|
|
message1 = message_helper.process_new_message(message1);
|
|
|
|
message2 = message_helper.process_new_message(message2);
|
2020-07-26 20:28:40 +02:00
|
|
|
|
|
|
|
assert.equal(message1.sender_full_name, alice.full_name);
|
|
|
|
assert.equal(message2.sender_full_name, bob.full_name);
|
2023-12-09 23:33:44 +01:00
|
|
|
message_store.update_sender_full_name(bob.user_id, "Bobby");
|
2020-07-26 20:28:40 +02:00
|
|
|
assert.equal(message1.sender_full_name, alice.full_name);
|
|
|
|
assert.equal(message2.sender_full_name, "Bobby");
|
2020-07-26 23:17:30 +02:00
|
|
|
|
|
|
|
assert.equal(message1.small_avatar_url, "alice_url");
|
|
|
|
assert.equal(message2.small_avatar_url, "bob_url");
|
2023-12-09 23:33:44 +01:00
|
|
|
message_store.update_small_avatar_url(bob.user_id, "bobby_url");
|
2020-07-26 23:17:30 +02:00
|
|
|
assert.equal(message1.small_avatar_url, "alice_url");
|
|
|
|
assert.equal(message2.small_avatar_url, "bobby_url");
|
2020-07-26 23:39:32 +02:00
|
|
|
|
2023-07-26 22:07:21 +02:00
|
|
|
assert.equal(message1.stream_id, devel.stream_id);
|
2020-07-26 23:39:32 +02:00
|
|
|
assert.equal(message1.display_recipient, devel.name);
|
2023-07-26 22:07:21 +02:00
|
|
|
assert.equal(message2.stream_id, denmark.stream_id);
|
2020-07-26 23:39:32 +02:00
|
|
|
assert.equal(message2.display_recipient, denmark.name);
|
2023-12-09 23:33:44 +01:00
|
|
|
message_store.update_stream_name(devel.stream_id, "Prod");
|
2023-07-26 22:07:21 +02:00
|
|
|
assert.equal(message1.stream_id, devel.stream_id);
|
2020-07-26 23:39:32 +02:00
|
|
|
assert.equal(message1.display_recipient, "Prod");
|
2023-07-26 22:07:21 +02:00
|
|
|
assert.equal(message2.stream_id, denmark.stream_id);
|
2020-07-26 23:39:32 +02:00
|
|
|
assert.equal(message2.display_recipient, denmark.name);
|
2020-07-26 20:28:40 +02:00
|
|
|
});
|
2024-06-25 23:36:55 +02:00
|
|
|
|
|
|
|
test("remove", () => {
|
|
|
|
const message1 = {
|
|
|
|
type: "stream",
|
|
|
|
sender_full_name: alice.full_name,
|
|
|
|
sender_id: alice.user_id,
|
|
|
|
stream_id: devel.stream_id,
|
|
|
|
stream: devel.name,
|
|
|
|
display_recipient: devel.name,
|
|
|
|
topic: "test",
|
|
|
|
id: 100,
|
|
|
|
};
|
|
|
|
const message2 = {
|
|
|
|
type: "stream",
|
|
|
|
sender_full_name: bob.full_name,
|
|
|
|
sender_id: bob.user_id,
|
|
|
|
stream_id: denmark.stream_id,
|
|
|
|
stream: denmark.name,
|
|
|
|
display_recipient: denmark.name,
|
|
|
|
topic: "test",
|
|
|
|
id: 101,
|
|
|
|
};
|
|
|
|
const message3 = {
|
|
|
|
type: "stream",
|
|
|
|
sender_full_name: cindy.full_name,
|
|
|
|
sender_id: cindy.user_id,
|
|
|
|
stream_id: denmark.stream_id,
|
|
|
|
stream: denmark.name,
|
|
|
|
display_recipient: denmark.name,
|
|
|
|
topic: "test",
|
|
|
|
id: 102,
|
|
|
|
};
|
|
|
|
for (const message of [message1, message2]) {
|
|
|
|
message_helper.process_new_message(message);
|
|
|
|
}
|
|
|
|
|
|
|
|
const deleted_message_ids = [message1.id, message3.id, 104];
|
|
|
|
message_store.remove(deleted_message_ids);
|
|
|
|
assert.equal(message_store.get(message1.id), undefined);
|
|
|
|
assert.equal(message_store.get(message2.id).id, message2.id);
|
|
|
|
assert.equal(message_store.get(message3.id), undefined);
|
|
|
|
});
|