2020-08-01 03:43:15 +02:00
|
|
|
"use strict";
|
|
|
|
|
2020-11-30 23:46:45 +01:00
|
|
|
const {strict: assert} = require("assert");
|
|
|
|
|
2020-08-20 21:24:06 +02:00
|
|
|
const people = zrequire("people");
|
2018-07-31 07:20:03 +02:00
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
const return_false = function () {
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
const return_true = function () {
|
|
|
|
return true;
|
|
|
|
};
|
2020-07-15 01:29:15 +02:00
|
|
|
set_global("reload_state", {
|
2018-07-31 07:20:03 +02:00
|
|
|
is_in_progress: return_false,
|
2018-04-23 21:13:21 +02:00
|
|
|
});
|
2017-11-06 15:10:33 +01:00
|
|
|
|
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);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("report_late_add", () => {
|
|
|
|
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");
|
2018-08-04 15:40:25 +02:00
|
|
|
reload_state.is_in_progress = return_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);
|
|
|
|
});
|
|
|
|
|
2020-07-15 01:29:15 +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);
|
2020-07-15 01:29:15 +02:00
|
|
|
assert(reply_to.includes("?"));
|
2017-11-06 15:10:33 +01:00
|
|
|
|
2020-08-20 21:33:00 +02:00
|
|
|
people.__Rewire__("pm_with_user_ids", () => [42]);
|
|
|
|
people.__Rewire__("get_by_user_id", () => {});
|
2020-07-15 01:29:15 +02:00
|
|
|
blueslip.expect("error", "Unknown people in message");
|
2019-11-02 00:06:25 +01:00
|
|
|
const uri = people.pm_with_url({});
|
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
|
|
|
});
|