2017-08-09 19:31:57 +02:00
|
|
|
set_global('$', global.make_zjquery());
|
|
|
|
|
2017-11-08 20:07:05 +01:00
|
|
|
zrequire('people');
|
|
|
|
zrequire('user_events');
|
2017-01-21 16:49:27 +01:00
|
|
|
|
|
|
|
set_global('activity', {
|
|
|
|
redraw: function () {},
|
|
|
|
});
|
2018-12-08 18:16:37 +01:00
|
|
|
|
2018-12-17 21:28:25 +01:00
|
|
|
set_global('settings_linkifiers', {
|
2018-12-08 18:16:37 +01:00
|
|
|
maybe_disable_widgets: function () {},
|
|
|
|
});
|
|
|
|
set_global('settings_org', {
|
|
|
|
maybe_disable_widgets: function () {},
|
2017-04-08 20:08:35 +02:00
|
|
|
});
|
2018-12-08 18:16:37 +01:00
|
|
|
set_global('settings_profile_fields', {
|
2018-12-06 18:23:57 +01:00
|
|
|
maybe_disable_widgets: function () {},
|
|
|
|
});
|
2018-12-08 18:16:37 +01:00
|
|
|
set_global('settings_streams', {
|
|
|
|
maybe_disable_widgets: function () {},
|
|
|
|
});
|
|
|
|
set_global('settings_users', {
|
|
|
|
update_user_data: function () {},
|
|
|
|
});
|
|
|
|
|
2018-12-06 18:41:56 +01:00
|
|
|
set_global('gear_menu', {
|
|
|
|
update_org_settings_menu_item: function () {},
|
2017-01-21 16:49:27 +01:00
|
|
|
});
|
|
|
|
set_global('page_params', {
|
|
|
|
is_admin: true,
|
|
|
|
});
|
|
|
|
|
2017-01-25 16:23:22 +01:00
|
|
|
set_global('pm_list', {
|
|
|
|
update_private_messages: function () {},
|
|
|
|
});
|
|
|
|
|
2017-06-20 23:41:04 +02:00
|
|
|
set_global('narrow_state', {
|
|
|
|
update_email: function () {},
|
|
|
|
});
|
|
|
|
|
|
|
|
set_global('compose', {
|
|
|
|
update_email: function () {},
|
|
|
|
});
|
|
|
|
|
|
|
|
set_global('settings_account', {
|
|
|
|
update_email: function () {},
|
2018-02-02 01:24:26 +01:00
|
|
|
update_full_name: function () {},
|
2017-06-20 23:41:04 +02:00
|
|
|
});
|
|
|
|
|
2017-01-24 19:12:21 +01:00
|
|
|
set_global('message_live_update', {
|
|
|
|
});
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const me = {
|
2017-01-21 16:49:27 +01:00
|
|
|
email: 'me@example.com',
|
|
|
|
user_id: 30,
|
|
|
|
full_name: 'Me Myself',
|
|
|
|
is_admin: true,
|
|
|
|
};
|
|
|
|
|
|
|
|
function initialize() {
|
|
|
|
people.init();
|
|
|
|
people.add(me);
|
|
|
|
people.initialize_current_user(me.user_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
initialize();
|
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('updates', () => {
|
2019-11-02 00:06:25 +01:00
|
|
|
let person;
|
2017-01-21 16:49:27 +01:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const isaac = {
|
2017-01-21 16:49:27 +01:00
|
|
|
email: 'isaac@example.com',
|
|
|
|
user_id: 32,
|
|
|
|
full_name: 'Isaac Newton',
|
|
|
|
};
|
|
|
|
people.add(isaac);
|
|
|
|
|
2018-10-29 20:49:07 +01:00
|
|
|
user_events.update_person({user_id: isaac.user_id, is_guest: true});
|
|
|
|
person = people.get_by_email(isaac.email);
|
|
|
|
assert(person.is_guest);
|
|
|
|
user_events.update_person({user_id: isaac.user_id, is_guest: false});
|
|
|
|
person = people.get_by_email(isaac.email);
|
|
|
|
assert(!person.is_guest);
|
|
|
|
|
2017-01-21 16:49:27 +01:00
|
|
|
user_events.update_person({user_id: isaac.user_id, is_admin: true});
|
|
|
|
person = people.get_by_email(isaac.email);
|
|
|
|
assert.equal(person.full_name, 'Isaac Newton');
|
|
|
|
assert.equal(person.is_admin, true);
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let user_id;
|
|
|
|
let full_name;
|
2017-01-24 19:12:21 +01:00
|
|
|
global.message_live_update.update_user_full_name = function (user_id_arg, full_name_arg) {
|
|
|
|
user_id = user_id_arg;
|
|
|
|
full_name = full_name_arg;
|
|
|
|
};
|
|
|
|
|
2017-01-21 16:49:27 +01:00
|
|
|
user_events.update_person({user_id: isaac.user_id, full_name: 'Sir Isaac'});
|
|
|
|
person = people.get_by_email(isaac.email);
|
|
|
|
assert.equal(person.full_name, 'Sir Isaac');
|
|
|
|
assert.equal(person.is_admin, true);
|
2017-01-24 19:12:21 +01:00
|
|
|
assert.equal(user_id, isaac.user_id);
|
|
|
|
assert.equal(full_name, 'Sir Isaac');
|
2017-01-21 16:49:27 +01:00
|
|
|
|
|
|
|
user_events.update_person({user_id: me.user_id, is_admin: false});
|
|
|
|
assert(!global.page_params.is_admin);
|
|
|
|
|
|
|
|
user_events.update_person({user_id: me.user_id, full_name: 'Me V2'});
|
|
|
|
assert.equal(people.my_full_name(), 'Me V2');
|
2017-01-24 19:12:21 +01:00
|
|
|
assert.equal(user_id, me.user_id);
|
|
|
|
assert.equal(full_name, 'Me V2');
|
2017-01-21 16:49:27 +01:00
|
|
|
|
2017-06-20 23:41:04 +02:00
|
|
|
user_events.update_person({user_id: isaac.user_id, new_email: 'newton@example.com'});
|
2020-02-05 14:30:59 +01:00
|
|
|
person = people.get_by_user_id(isaac.user_id);
|
2017-06-20 23:41:04 +02:00
|
|
|
assert.equal(person.email, 'newton@example.com');
|
|
|
|
assert.equal(person.full_name, 'Sir Isaac');
|
|
|
|
|
|
|
|
user_events.update_person({user_id: me.user_id, new_email: 'meforu@example.com'});
|
2020-02-05 14:30:59 +01:00
|
|
|
person = people.get_by_user_id(me.user_id);
|
2017-06-20 23:41:04 +02:00
|
|
|
assert.equal(person.email, 'meforu@example.com');
|
|
|
|
assert.equal(person.full_name, 'Me V2');
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let avatar_url;
|
2017-06-20 23:41:04 +02:00
|
|
|
global.message_live_update.update_avatar = function (user_id_arg, avatar_url_arg) {
|
|
|
|
user_id = user_id_arg;
|
|
|
|
avatar_url = avatar_url_arg;
|
|
|
|
};
|
|
|
|
|
|
|
|
user_events.update_person({user_id: isaac.user_id, full_name: 'Sir Isaac'});
|
|
|
|
person = people.get_by_email(isaac.email);
|
|
|
|
assert.equal(person.full_name, 'Sir Isaac');
|
|
|
|
assert.equal(person.is_admin, true);
|
|
|
|
assert.equal(user_id, isaac.user_id);
|
|
|
|
assert.equal(full_name, 'Sir Isaac');
|
|
|
|
|
|
|
|
user_events.update_person({user_id: isaac.user_id, avatar_url: 'http://gravatar.com/123456'});
|
|
|
|
person = people.get_by_email(isaac.email);
|
|
|
|
assert.equal(person.full_name, 'Sir Isaac');
|
|
|
|
assert.equal(user_id, isaac.user_id);
|
|
|
|
assert.equal(person.avatar_url, avatar_url);
|
|
|
|
|
|
|
|
user_events.update_person({user_id: me.user_id, avatar_url: 'http://gravatar.com/789456'});
|
|
|
|
person = people.get_by_email(me.email);
|
|
|
|
assert.equal(person.full_name, 'Me V2');
|
|
|
|
assert.equal(user_id, me.user_id);
|
|
|
|
assert.equal(person.avatar_url, avatar_url);
|
|
|
|
|
|
|
|
user_events.update_person({user_id: me.user_id, timezone: 'UTC'});
|
|
|
|
person = people.get_by_email(me.email);
|
|
|
|
assert(person.timezone);
|
|
|
|
|
2020-04-03 17:18:04 +02:00
|
|
|
blueslip.expect('error', 'Got update_person event for unexpected user 29');
|
|
|
|
blueslip.expect('error', 'Unknown user_id in get_by_user_id: 29');
|
2017-06-20 23:41:04 +02:00
|
|
|
assert(!user_events.update_person({user_id: 29, full_name: 'Sir Isaac Newton'}));
|
|
|
|
|
2018-03-10 14:41:44 +01:00
|
|
|
me.profile_data = {};
|
2018-12-31 07:45:33 +01:00
|
|
|
user_events.update_person({user_id: me.user_id, custom_profile_field: {id: 3, value: 'Value', rendered_value: '<p>Value</p>'}});
|
2018-03-10 14:41:44 +01:00
|
|
|
person = people.get_by_email(me.email);
|
2018-12-31 06:41:06 +01:00
|
|
|
assert.equal(person.profile_data[3].value, 'Value');
|
2018-12-31 07:45:33 +01:00
|
|
|
assert.equal(person.profile_data[3].rendered_value, '<p>Value</p>');
|
2018-08-02 08:54:28 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let updated = false;
|
2018-08-02 08:54:28 +02:00
|
|
|
settings_account.update_email = (email) => {
|
|
|
|
assert.equal(email, 'you@example.org');
|
|
|
|
updated = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
user_events.update_person({user_id: me.user_id, delivery_email: 'you@example.org'});
|
|
|
|
assert(updated);
|
2019-05-29 06:21:54 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const test_bot = {
|
2019-05-29 06:21:54 +02:00
|
|
|
email: 'test-bot@example.com',
|
|
|
|
user_id: 35,
|
|
|
|
full_name: 'Test Bot',
|
|
|
|
is_bot: true,
|
|
|
|
bot_owner_id: isaac.id,
|
|
|
|
};
|
|
|
|
people.add(test_bot);
|
|
|
|
|
|
|
|
user_events.update_person({user_id: test_bot.user_id, bot_owner_id: me.user_id});
|
|
|
|
person = people.get_by_email(test_bot.email);
|
|
|
|
assert.equal(person.bot_owner_id, me.user_id);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|