2020-08-01 03:43:15 +02:00
|
|
|
"use strict";
|
|
|
|
|
2020-11-30 23:46:45 +01:00
|
|
|
const {strict: assert} = require("assert");
|
|
|
|
|
2023-02-22 23:04:10 +01:00
|
|
|
const {mock_esm, zrequire} = require("./lib/namespace");
|
|
|
|
const {run_test} = require("./lib/test");
|
|
|
|
const blueslip = require("./lib/zblueslip");
|
2020-12-01 00:02:16 +01:00
|
|
|
|
2023-02-22 23:04:10 +01:00
|
|
|
const reload_state = mock_esm("../src/reload_state", {
|
2021-02-26 12:49:16 +01:00
|
|
|
is_in_progress: () => false,
|
2021-03-07 13:57:14 +01:00
|
|
|
});
|
2021-02-28 00:48:19 +01:00
|
|
|
|
2020-12-01 23:21:38 +01:00
|
|
|
const people = zrequire("people");
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const me = {
|
2020-07-15 01:29:15 +02:00
|
|
|
email: "me@example.com",
|
2017-11-06 15:10:33 +01:00
|
|
|
user_id: 30,
|
2020-07-15 01:29:15 +02:00
|
|
|
full_name: "Me Myself",
|
2020-10-27 01:41:00 +01:00
|
|
|
timezone: "America/Los_Angeles",
|
2017-11-06 15:10:33 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
people.init();
|
2020-05-26 22:34:15 +02:00
|
|
|
people.add_active_user(me);
|
2017-11-06 15:10:33 +01:00
|
|
|
people.initialize_current_user(me.user_id);
|
|
|
|
|
2021-06-16 14:38:37 +02:00
|
|
|
run_test("report_late_add", ({override}) => {
|
2020-07-15 01:29:15 +02:00
|
|
|
blueslip.expect("error", "Added user late: user_id=55 email=foo@example.com");
|
|
|
|
people.report_late_add(55, "foo@example.com");
|
2018-04-23 21:13:21 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
blueslip.expect("log", "Added user late: user_id=55 email=foo@example.com");
|
2021-03-10 14:53:41 +01:00
|
|
|
override(reload_state, "is_in_progress", () => true);
|
2020-07-15 01:29:15 +02:00
|
|
|
people.report_late_add(55, "foo@example.com");
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-11-06 17:03:01 +01:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("is_my_user_id", () => {
|
|
|
|
blueslip.expect("error", "user_id is a string in my_user_id: 999");
|
|
|
|
assert.equal(people.is_my_user_id("999"), false);
|
2019-12-31 14:02:30 +01:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
blueslip.expect("error", "user_id is a string in my_user_id: 30");
|
2019-12-31 14:02:30 +01:00
|
|
|
assert.equal(people.is_my_user_id(me.user_id.toString()), true);
|
|
|
|
});
|
|
|
|
|
2022-07-10 01:06:33 +02:00
|
|
|
run_test("blueslip", () => {
|
2019-11-02 00:06:25 +01:00
|
|
|
const unknown_email = "alicebobfred@example.com";
|
2017-11-06 15:10:33 +01:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
blueslip.expect("debug", "User email operand unknown: " + unknown_email);
|
2017-11-06 15:10:33 +01:00
|
|
|
people.id_matches_email_operand(42, unknown_email);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
blueslip.expect("error", "Unknown user_id: 9999");
|
2020-02-16 14:16:46 +01:00
|
|
|
people.get_actual_name_from_user_id(9999);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
blueslip.expect("error", "Unknown email for get_user_id: " + unknown_email);
|
2017-11-06 15:10:33 +01:00
|
|
|
people.get_user_id(unknown_email);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
blueslip.expect("warn", "No user_id provided for person@example.com");
|
2019-11-02 00:06:25 +01:00
|
|
|
const person = {
|
2020-07-15 01:29:15 +02:00
|
|
|
email: "person@example.com",
|
2017-11-06 15:10:33 +01:00
|
|
|
user_id: undefined,
|
2020-07-15 01:29:15 +02:00
|
|
|
full_name: "Person Person",
|
2017-11-06 15:10:33 +01:00
|
|
|
};
|
2020-05-26 22:34:15 +02:00
|
|
|
people.add_active_user(person);
|
2017-11-06 15:10:33 +01:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
blueslip.expect("error", "No user_id found for person@example.com");
|
|
|
|
const user_id = people.get_user_id("person@example.com");
|
2017-11-06 15:10:33 +01:00
|
|
|
assert.equal(user_id, undefined);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
blueslip.expect("warn", "Unknown user ids: 1,2");
|
|
|
|
people.user_ids_string_to_emails_string("1,2");
|
2017-11-06 15:10:33 +01:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
blueslip.expect("warn", "Unknown emails: " + unknown_email);
|
2020-02-08 01:27:04 +01:00
|
|
|
people.email_list_to_user_ids_string([unknown_email]);
|
2017-11-06 15:10:33 +01:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let message = {
|
2020-07-15 01:29:15 +02:00
|
|
|
type: "private",
|
2017-11-06 15:10:33 +01:00
|
|
|
display_recipient: [],
|
|
|
|
sender_id: me.user_id,
|
|
|
|
};
|
2020-07-15 01:29:15 +02:00
|
|
|
blueslip.expect("error", "Empty recipient list in message", 4);
|
2017-11-06 15:10:33 +01:00
|
|
|
people.pm_with_user_ids(message);
|
|
|
|
people.group_pm_with_user_ids(message);
|
2018-10-18 22:05:28 +02:00
|
|
|
people.all_user_ids_in_pm(message);
|
|
|
|
assert.equal(people.pm_perma_link(message), undefined);
|
2017-11-06 15:10:33 +01:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const charles = {
|
2020-07-15 01:29:15 +02:00
|
|
|
email: "charles@example.com",
|
2017-11-06 15:10:33 +01:00
|
|
|
user_id: 451,
|
2020-07-15 01:29:15 +02:00
|
|
|
full_name: "Charles Dickens",
|
|
|
|
avatar_url: "charles.com/foo.png",
|
2017-11-06 15:10:33 +01:00
|
|
|
};
|
2019-11-02 00:06:25 +01:00
|
|
|
const maria = {
|
2020-07-15 01:29:15 +02:00
|
|
|
email: "athens@example.com",
|
2017-11-06 15:10:33 +01:00
|
|
|
user_id: 452,
|
2020-07-15 01:29:15 +02:00
|
|
|
full_name: "Maria Athens",
|
2017-11-06 15:10:33 +01:00
|
|
|
};
|
2020-05-26 22:34:15 +02:00
|
|
|
people.add_active_user(charles);
|
|
|
|
people.add_active_user(maria);
|
2017-11-06 15:10:33 +01:00
|
|
|
|
|
|
|
message = {
|
2020-07-15 01:29:15 +02:00
|
|
|
type: "private",
|
2020-07-15 00:34:28 +02:00
|
|
|
display_recipient: [{id: maria.user_id}, {id: 42}, {id: charles.user_id}],
|
2017-11-06 15:10:33 +01:00
|
|
|
sender_id: charles.user_id,
|
|
|
|
};
|
2020-07-15 01:29:15 +02:00
|
|
|
blueslip.expect("error", "Unknown user id in message: 42");
|
2019-11-02 00:06:25 +01:00
|
|
|
const reply_to = people.pm_reply_to(message);
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(reply_to.includes("?"));
|
2017-11-06 15:10:33 +01:00
|
|
|
|
2022-07-10 01:06:33 +02:00
|
|
|
blueslip.expect("error", "Unknown user_id in get_by_user_id: 42");
|
2020-07-15 01:29:15 +02:00
|
|
|
blueslip.expect("error", "Unknown people in message");
|
2022-07-10 01:06:33 +02:00
|
|
|
const uri = people.pm_with_url({type: "private", display_recipient: [{id: 42}]});
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(uri.indexOf("unk"), uri.length - 3);
|
2020-02-07 22:26:05 +01:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
blueslip.expect("error", "Undefined field id");
|
2020-02-07 22:26:05 +01:00
|
|
|
assert.equal(people.my_custom_profile_data(undefined), undefined);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
blueslip.expect("error", "Trying to set undefined field id");
|
2020-02-07 22:26:05 +01:00
|
|
|
people.set_custom_profile_field_data(maria.user_id, {});
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|