2017-11-03 17:25:47 +01:00
|
|
|
zrequire('util');
|
|
|
|
zrequire('people');
|
2014-02-20 19:50:14 +01:00
|
|
|
|
2018-05-01 05:55:50 +02:00
|
|
|
set_global('blueslip', global.make_zblueslip({
|
|
|
|
error: false, // We check for errors in people_errors.js
|
|
|
|
}));
|
2017-06-02 04:47:53 +02:00
|
|
|
set_global('page_params', {});
|
2017-11-03 17:25:47 +01:00
|
|
|
set_global('md5', function (s) {
|
|
|
|
return 'md5-' + s;
|
|
|
|
});
|
2018-11-02 20:08:24 +01:00
|
|
|
set_global('i18n', global.stub_i18n);
|
2014-02-01 16:14:40 +01:00
|
|
|
|
2017-01-19 23:04:52 +01:00
|
|
|
var me = {
|
|
|
|
email: 'me@example.com',
|
|
|
|
user_id: 30,
|
|
|
|
full_name: 'Me Myself',
|
2017-06-02 06:12:41 +02:00
|
|
|
timezone: 'US/Pacific',
|
2018-11-02 20:08:24 +01:00
|
|
|
is_admin: false,
|
|
|
|
is_guest: false,
|
|
|
|
is_bot: false,
|
2017-01-19 23:04:52 +01:00
|
|
|
};
|
|
|
|
|
2018-02-23 16:16:55 +01:00
|
|
|
var isaac = {
|
|
|
|
email: 'isaac@example.com',
|
|
|
|
user_id: 32,
|
|
|
|
full_name: 'Isaac Newton',
|
|
|
|
};
|
|
|
|
|
2017-01-19 23:04:52 +01:00
|
|
|
function initialize() {
|
|
|
|
people.init();
|
|
|
|
people.add(me);
|
2017-01-20 23:16:28 +01:00
|
|
|
people.initialize_current_user(me.user_id);
|
2017-01-19 23:04:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
initialize();
|
2014-03-12 19:59:17 +01:00
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('basics', () => {
|
2016-11-01 19:36:50 +01:00
|
|
|
var persons = people.get_all_persons();
|
2017-01-19 23:04:52 +01:00
|
|
|
|
2016-11-01 19:36:50 +01:00
|
|
|
assert.equal(_.size(persons), 1);
|
2017-01-19 23:04:52 +01:00
|
|
|
assert.equal(persons[0].full_name, 'Me Myself');
|
2016-11-01 19:36:50 +01:00
|
|
|
|
2016-11-01 19:45:53 +01:00
|
|
|
var realm_persons = people.get_realm_persons();
|
|
|
|
assert.equal(_.size(realm_persons), 0);
|
2017-03-30 18:47:38 +02:00
|
|
|
assert.equal(people.get_realm_count(), 0);
|
2016-11-01 19:45:53 +01:00
|
|
|
|
2014-02-01 16:14:40 +01:00
|
|
|
var full_name = 'Isaac Newton';
|
|
|
|
var email = 'isaac@example.com';
|
2017-03-26 19:32:54 +02:00
|
|
|
|
|
|
|
assert(!people.is_known_user_id(32));
|
2014-02-01 16:14:40 +01:00
|
|
|
people.add(isaac);
|
2018-02-23 16:16:55 +01:00
|
|
|
|
2017-03-26 19:32:54 +02:00
|
|
|
assert(people.is_known_user_id(32));
|
2017-03-30 18:47:38 +02:00
|
|
|
assert.equal(people.get_realm_count(), 0);
|
2014-02-01 16:14:40 +01:00
|
|
|
|
|
|
|
var person = people.get_by_name(full_name);
|
2016-10-30 15:22:24 +01:00
|
|
|
assert.equal(people.get_user_id(email), 32);
|
2014-02-01 16:14:40 +01:00
|
|
|
assert.equal(person.email, email);
|
|
|
|
person = people.get_by_email(email);
|
|
|
|
assert.equal(person.full_name, full_name);
|
2017-10-26 18:52:42 +02:00
|
|
|
person = people.get_active_user_for_email(email);
|
2014-02-01 16:14:40 +01:00
|
|
|
assert(!person);
|
|
|
|
people.add_in_realm(isaac);
|
2017-03-30 18:47:38 +02:00
|
|
|
assert.equal(people.get_realm_count(), 1);
|
2017-10-26 18:52:42 +02:00
|
|
|
person = people.get_active_user_for_email(email);
|
2014-02-01 16:14:40 +01:00
|
|
|
assert.equal(person.email, email);
|
|
|
|
|
2016-11-01 19:45:53 +01:00
|
|
|
realm_persons = people.get_realm_persons();
|
|
|
|
assert.equal(_.size(realm_persons), 1);
|
|
|
|
assert.equal(realm_persons[0].full_name, 'Isaac Newton');
|
|
|
|
|
2017-10-26 18:17:43 +02:00
|
|
|
var active_user_ids = people.get_active_user_ids();
|
|
|
|
assert.deepEqual(active_user_ids, [isaac.user_id]);
|
2017-10-26 21:00:30 +02:00
|
|
|
assert.equal(people.is_active_user_for_popover(isaac.user_id), true);
|
2017-10-26 18:45:08 +02:00
|
|
|
assert(people.is_valid_email_for_compose(isaac.email));
|
2017-10-07 20:10:10 +02:00
|
|
|
|
2016-12-15 22:44:42 +01:00
|
|
|
// Now deactivate isaac
|
|
|
|
people.deactivate(isaac);
|
2017-10-26 18:52:42 +02:00
|
|
|
person = people.get_active_user_for_email(email);
|
2014-02-01 16:14:40 +01:00
|
|
|
assert(!person);
|
2017-03-30 18:47:38 +02:00
|
|
|
assert.equal(people.get_realm_count(), 0);
|
2017-10-26 21:00:30 +02:00
|
|
|
assert.equal(people.is_active_user_for_popover(isaac.user_id), false);
|
2017-10-26 18:45:08 +02:00
|
|
|
assert.equal(people.is_valid_email_for_compose(isaac.email), false);
|
2017-10-14 00:33:36 +02:00
|
|
|
|
2017-10-25 00:59:51 +02:00
|
|
|
var bot_botson = {
|
|
|
|
email: 'botson-bot@example.com',
|
|
|
|
user_id: 35,
|
|
|
|
full_name: 'Bot Botson',
|
|
|
|
is_bot: true,
|
|
|
|
};
|
2017-10-26 21:00:30 +02:00
|
|
|
people.add_in_realm(bot_botson);
|
|
|
|
assert.equal(people.is_active_user_for_popover(bot_botson.user_id), true);
|
2014-03-12 19:59:17 +01:00
|
|
|
|
2017-10-26 21:00:30 +02:00
|
|
|
// Invalid user ID returns false and warns.
|
2018-05-01 05:55:50 +02:00
|
|
|
blueslip.set_test_data('warn', 'Unexpectedly invalid user_id in user popover query: 123412');
|
2017-10-26 21:00:30 +02:00
|
|
|
assert.equal(people.is_active_user_for_popover(123412), false);
|
2018-05-01 05:55:50 +02:00
|
|
|
assert.equal(blueslip.get_test_logs('warn').length, 1);
|
|
|
|
blueslip.clear_test_data();
|
2017-10-25 01:24:03 +02:00
|
|
|
|
2016-12-15 22:44:42 +01:00
|
|
|
// We can still get their info for non-realm needs.
|
|
|
|
person = people.get_by_email(email);
|
|
|
|
assert.equal(person.email, email);
|
|
|
|
|
2017-01-19 23:04:52 +01:00
|
|
|
// The current user should still be there
|
|
|
|
person = people.get_by_email('me@example.com');
|
|
|
|
assert.equal(person.full_name, 'Me Myself');
|
2017-06-02 04:47:53 +02:00
|
|
|
|
|
|
|
// Test undefined people
|
|
|
|
assert.equal(people.is_cross_realm_email('unknown@example.com'), undefined);
|
2017-10-26 18:52:42 +02:00
|
|
|
assert.equal(people.get_active_user_for_email('unknown@example.com'), undefined);
|
2017-06-02 04:47:53 +02:00
|
|
|
|
|
|
|
// Test is_my_user_id function
|
|
|
|
assert.equal(people.is_my_user_id(me.user_id), true);
|
|
|
|
assert.equal(people.is_my_user_id(isaac.user_id), false);
|
|
|
|
assert.equal(people.is_my_user_id(undefined), false);
|
2018-07-28 20:13:20 +02:00
|
|
|
|
|
|
|
// Reactivating issac
|
|
|
|
people.add_in_realm(isaac);
|
|
|
|
var active_human_persons = people.get_active_human_persons();
|
|
|
|
assert.equal(active_human_persons.length, 1);
|
|
|
|
assert.deepEqual(active_human_persons, [isaac]);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-01-19 23:04:52 +01:00
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('pm_lookup_key', () => {
|
2017-08-01 15:51:56 +02:00
|
|
|
assert.equal(people.pm_lookup_key('30'), '30');
|
|
|
|
assert.equal(people.pm_lookup_key('32,30'), '32');
|
|
|
|
assert.equal(people.pm_lookup_key('101,32,30'), '32,101');
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-08-01 15:51:56 +02:00
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('get_recipients', () => {
|
2017-04-03 19:34:14 +02:00
|
|
|
assert.equal(people.get_recipients('30'), 'Me Myself');
|
|
|
|
assert.equal(people.get_recipients('30,32'), 'Isaac Newton');
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-04-03 19:34:14 +02:00
|
|
|
|
2018-02-23 16:16:55 +01:00
|
|
|
run_test('safe_full_names', () => {
|
|
|
|
var names = people.safe_full_names([me.user_id, isaac.user_id]);
|
|
|
|
assert.equal(names, 'Me Myself, Isaac Newton');
|
|
|
|
});
|
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('my_custom_profile_data', () => {
|
2018-02-26 20:09:07 +01:00
|
|
|
var person = people.get_by_email(me.email);
|
|
|
|
person.profile_data = {3: 'My address', 4: 'My phone number'};
|
|
|
|
assert.equal(people.my_custom_profile_data(3), 'My address');
|
|
|
|
assert.equal(people.my_custom_profile_data(4), 'My phone number');
|
|
|
|
assert.equal(people.my_custom_profile_data(undefined), undefined);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2018-02-26 20:09:07 +01:00
|
|
|
|
2019-04-07 17:29:53 +02:00
|
|
|
run_test('bot_custom_profile_data', () => {
|
|
|
|
// If this test fails, then try opening organization settings > bots
|
|
|
|
// http://localhost:9991/#organization/bot-list-admin
|
|
|
|
// and then try to edit any of the bots.
|
|
|
|
var bot = {
|
|
|
|
email: 'bot@example.com',
|
|
|
|
user_id: 31,
|
|
|
|
full_name: 'Bot',
|
|
|
|
is_bot: true,
|
|
|
|
};
|
|
|
|
people.add_in_realm(bot);
|
|
|
|
assert.equal(people.get_custom_profile_data(31, 3), null);
|
|
|
|
});
|
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('user_timezone', () => {
|
2017-06-02 06:12:41 +02:00
|
|
|
var expected_pref = {
|
|
|
|
timezone: 'US/Pacific',
|
2018-10-07 22:52:49 +02:00
|
|
|
format: 'H:mm',
|
2017-06-02 06:12:41 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
global.page_params.twenty_four_hour_time = true;
|
|
|
|
assert.deepEqual(people.get_user_time_preferences(me.user_id), expected_pref);
|
|
|
|
|
2018-10-07 22:52:49 +02:00
|
|
|
expected_pref.format = 'h:mm A';
|
2017-06-02 06:12:41 +02:00
|
|
|
global.page_params.twenty_four_hour_time = false;
|
|
|
|
assert.deepEqual(people.get_user_time_preferences(me.user_id), expected_pref);
|
|
|
|
|
2017-11-08 20:35:50 +01:00
|
|
|
zrequire('actual_moment', 'moment-timezone');
|
|
|
|
set_global('moment', function () { return global.actual_moment('20130208T080910'); });
|
2017-06-02 06:12:41 +02:00
|
|
|
|
|
|
|
global.page_params.twenty_four_hour_time = true;
|
2018-10-07 22:52:49 +02:00
|
|
|
assert.equal(people.get_user_time(me.user_id), '0:09');
|
2017-06-02 06:12:41 +02:00
|
|
|
|
2018-10-07 22:52:49 +02:00
|
|
|
expected_pref.format = 'h:mm A';
|
2017-06-02 06:12:41 +02:00
|
|
|
global.page_params.twenty_four_hour_time = false;
|
|
|
|
assert.equal(people.get_user_time(me.user_id), '12:09 AM');
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-06-02 06:12:41 +02:00
|
|
|
|
2018-11-02 20:08:24 +01:00
|
|
|
run_test('user_type', () => {
|
|
|
|
var realm_admin = {
|
|
|
|
email: 'realm_admin@example.com',
|
|
|
|
user_id: 32,
|
|
|
|
is_admin: true,
|
|
|
|
is_guest: false,
|
|
|
|
is_bot: false,
|
|
|
|
};
|
|
|
|
var guest = {
|
|
|
|
email: 'guest@example.com',
|
|
|
|
user_id: 33,
|
|
|
|
is_admin: false,
|
|
|
|
is_guest: true,
|
|
|
|
is_bot: false,
|
|
|
|
};
|
|
|
|
var bot = {
|
|
|
|
email: 'bot@example.com',
|
|
|
|
user_id: 34,
|
|
|
|
is_admin: false,
|
|
|
|
is_guest: false,
|
|
|
|
is_bot: true,
|
|
|
|
};
|
|
|
|
|
|
|
|
people.add(realm_admin);
|
|
|
|
people.add(guest);
|
|
|
|
people.add(bot);
|
|
|
|
assert.equal(people.get_user_type(me.user_id), i18n.t('Member'));
|
|
|
|
assert.equal(people.get_user_type(realm_admin.user_id), i18n.t('Administrator'));
|
|
|
|
assert.equal(people.get_user_type(guest.user_id), i18n.t('Guest'));
|
|
|
|
assert.equal(people.get_user_type(bot.user_id), i18n.t('Bot'));
|
|
|
|
});
|
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('updates', () => {
|
2017-01-21 00:02:28 +01:00
|
|
|
var person = people.get_by_email('me@example.com');
|
|
|
|
people.set_full_name(person, 'Me the Third');
|
|
|
|
assert.equal(people.my_full_name(), 'Me the Third');
|
|
|
|
assert.equal(person.full_name, 'Me the Third');
|
|
|
|
assert.equal(people.get_by_name('Me the Third').email, 'me@example.com');
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2014-02-20 19:50:14 +01:00
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('get_person_from_user_id', () => {
|
2016-10-31 15:56:57 +01:00
|
|
|
var person = {
|
|
|
|
email: 'mary@example.com',
|
|
|
|
user_id: 42,
|
2016-12-03 23:17:57 +01:00
|
|
|
full_name: 'Mary',
|
2016-10-31 15:56:57 +01:00
|
|
|
};
|
|
|
|
people.add(person);
|
|
|
|
person = people.get_by_email('mary@example.com');
|
|
|
|
assert.equal(person.full_name, 'Mary');
|
|
|
|
person = people.get_person_from_user_id(42);
|
|
|
|
assert.equal(person.email, 'mary@example.com');
|
|
|
|
|
2017-01-21 16:49:27 +01:00
|
|
|
people.set_full_name(person, 'Mary New');
|
2016-10-31 15:56:57 +01:00
|
|
|
person = people.get_person_from_user_id(42);
|
|
|
|
assert.equal(person.full_name, 'Mary New');
|
|
|
|
|
2016-12-15 22:44:42 +01:00
|
|
|
// deactivate() should eventually just take a user_id, but
|
|
|
|
// now it takes a full person object. Note that deactivate()
|
|
|
|
// won't actually make the user disappear completely.
|
|
|
|
people.deactivate(person);
|
2017-10-26 18:52:42 +02:00
|
|
|
person = people.get_active_user_for_email('mary@example.com');
|
2016-10-31 15:56:57 +01:00
|
|
|
assert.equal(person, undefined);
|
|
|
|
person = people.get_person_from_user_id(42);
|
2016-12-15 22:44:42 +01:00
|
|
|
assert.equal(person.user_id, 42);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2016-10-31 15:56:57 +01:00
|
|
|
|
2017-10-26 21:00:30 +02:00
|
|
|
initialize();
|
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('set_custom_profile_field_data', () => {
|
2018-03-10 14:41:44 +01:00
|
|
|
var person = people.get_by_email(me.email);
|
|
|
|
me.profile_data = {};
|
2018-12-31 07:45:33 +01:00
|
|
|
var field = {id: 3, name: 'Custom long field', type: 'text', value: 'Field value', rendered_value: '<p>Field value</p>'};
|
2018-03-10 14:41:44 +01:00
|
|
|
people.set_custom_profile_field_data(person.user_id, {});
|
|
|
|
assert.deepEqual(person.profile_data, {});
|
|
|
|
people.set_custom_profile_field_data(person.user_id, field);
|
2018-12-31 06:41:06 +01:00
|
|
|
assert.equal(person.profile_data[field.id].value, 'Field value');
|
2018-12-31 07:45:33 +01:00
|
|
|
assert.equal(person.profile_data[field.id].rendered_value, '<p>Field value</p>');
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2018-03-10 14:41:44 +01:00
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('get_rest_of_realm', () => {
|
2014-02-20 19:50:14 +01:00
|
|
|
var alice1 = {
|
|
|
|
email: 'alice1@example.com',
|
2016-10-31 15:56:57 +01:00
|
|
|
user_id: 202,
|
2016-12-03 23:17:57 +01:00
|
|
|
full_name: 'Alice',
|
2014-02-20 19:50:14 +01:00
|
|
|
};
|
|
|
|
var alice2 = {
|
|
|
|
email: 'alice2@example.com',
|
2016-10-31 15:56:57 +01:00
|
|
|
user_id: 203,
|
2016-12-03 23:17:57 +01:00
|
|
|
full_name: 'Alice',
|
2014-02-20 19:50:14 +01:00
|
|
|
};
|
|
|
|
var bob = {
|
|
|
|
email: 'bob@example.com',
|
2016-10-31 15:56:57 +01:00
|
|
|
user_id: 204,
|
2016-12-03 23:17:57 +01:00
|
|
|
full_name: 'Bob van Roberts',
|
2014-02-20 19:50:14 +01:00
|
|
|
};
|
|
|
|
people.add_in_realm(alice1);
|
|
|
|
people.add_in_realm(bob);
|
|
|
|
people.add_in_realm(alice2);
|
2017-03-30 18:47:38 +02:00
|
|
|
assert.equal(people.get_realm_count(), 3);
|
|
|
|
|
2014-02-20 19:50:14 +01:00
|
|
|
var others = people.get_rest_of_realm();
|
|
|
|
var expected = [
|
2017-01-07 07:58:08 +01:00
|
|
|
{ email: 'alice1@example.com', user_id: 202, full_name: 'Alice' },
|
|
|
|
{ email: 'alice2@example.com', user_id: 203, full_name: 'Alice' },
|
|
|
|
{ email: 'bob@example.com', user_id: 204, full_name: 'Bob van Roberts' },
|
2014-02-20 19:50:14 +01:00
|
|
|
];
|
|
|
|
assert.deepEqual(others, expected);
|
2016-10-18 19:21:38 +02:00
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2016-10-18 19:21:38 +02:00
|
|
|
|
2017-01-19 23:04:52 +01:00
|
|
|
initialize();
|
2016-12-15 22:18:59 +01:00
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('recipient_counts', () => {
|
2017-01-31 21:02:15 +01:00
|
|
|
var user_id = 99;
|
|
|
|
assert.equal(people.get_recipient_count({id: user_id}), 0);
|
|
|
|
people.incr_recipient_count(user_id);
|
|
|
|
people.incr_recipient_count(user_id);
|
|
|
|
assert.equal(people.get_recipient_count({user_id: user_id}), 2);
|
2016-11-04 14:34:58 +01:00
|
|
|
|
|
|
|
assert.equal(people.get_recipient_count({pm_recipient_count: 5}), 5);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2016-11-03 21:59:18 +01:00
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('filtered_users', () => {
|
2018-05-07 03:30:13 +02:00
|
|
|
var charles = {
|
2016-10-18 19:21:38 +02:00
|
|
|
email: 'charles@example.com',
|
2016-10-31 15:56:57 +01:00
|
|
|
user_id: 301,
|
2016-12-03 23:17:57 +01:00
|
|
|
full_name: 'Charles Dickens',
|
2016-10-18 19:21:38 +02:00
|
|
|
};
|
|
|
|
var maria = {
|
|
|
|
email: 'athens@example.com',
|
2016-10-31 15:56:57 +01:00
|
|
|
user_id: 302,
|
2016-12-03 23:17:57 +01:00
|
|
|
full_name: 'Maria Athens',
|
2016-10-18 19:21:38 +02:00
|
|
|
};
|
|
|
|
var ashton = {
|
|
|
|
email: 'ashton@example.com',
|
2016-10-31 15:56:57 +01:00
|
|
|
user_id: 303,
|
2016-12-03 23:17:57 +01:00
|
|
|
full_name: 'Ashton Smith',
|
2016-10-18 19:21:38 +02:00
|
|
|
};
|
2016-11-14 21:37:36 +01:00
|
|
|
var linus = {
|
|
|
|
email: 'ltorvalds@example.com',
|
|
|
|
user_id: 304,
|
2016-12-03 23:17:57 +01:00
|
|
|
full_name: 'Linus Torvalds',
|
2016-11-14 21:37:36 +01:00
|
|
|
};
|
2017-06-21 03:33:30 +02:00
|
|
|
var noah = {
|
|
|
|
email: 'emnoa@example.com',
|
|
|
|
user_id: 305,
|
|
|
|
full_name: 'Nöôáàh Ëmerson',
|
|
|
|
};
|
|
|
|
var plain_noah = {
|
|
|
|
email: 'otheremnoa@example.com',
|
|
|
|
user_id: 306,
|
|
|
|
full_name: 'Nooaah Emerson',
|
|
|
|
};
|
2016-10-18 19:21:38 +02:00
|
|
|
|
|
|
|
people.add_in_realm(charles);
|
|
|
|
people.add_in_realm(maria);
|
|
|
|
people.add_in_realm(ashton);
|
2016-11-14 21:37:36 +01:00
|
|
|
people.add_in_realm(linus);
|
2017-06-21 03:33:30 +02:00
|
|
|
people.add_in_realm(noah);
|
|
|
|
people.add_in_realm(plain_noah);
|
2016-11-14 21:37:36 +01:00
|
|
|
|
2016-10-18 19:21:38 +02:00
|
|
|
var search_term = 'a';
|
|
|
|
var users = people.get_rest_of_realm();
|
2016-11-14 21:26:12 +01:00
|
|
|
var filtered_people = people.filter_people_by_search_terms(users, [search_term]);
|
2017-01-26 13:00:27 +01:00
|
|
|
assert.equal(filtered_people.num_items(), 2);
|
|
|
|
assert(filtered_people.has(ashton.user_id));
|
|
|
|
assert(filtered_people.has(maria.user_id));
|
|
|
|
assert(!filtered_people.has(charles.user_id));
|
2016-10-18 19:21:38 +02:00
|
|
|
|
2016-11-14 21:26:12 +01:00
|
|
|
filtered_people = people.filter_people_by_search_terms(users, []);
|
2017-01-26 13:00:27 +01:00
|
|
|
assert.equal(filtered_people.num_items(), 0);
|
2016-10-18 19:21:38 +02:00
|
|
|
|
2016-11-14 21:37:36 +01:00
|
|
|
filtered_people = people.filter_people_by_search_terms(users, ['ltorv']);
|
2017-01-26 13:00:27 +01:00
|
|
|
assert.equal(filtered_people.num_items(), 1);
|
|
|
|
assert(filtered_people.has(linus.user_id));
|
2016-11-14 21:37:36 +01:00
|
|
|
|
2016-11-14 22:34:46 +01:00
|
|
|
filtered_people = people.filter_people_by_search_terms(users, ['ch di', 'maria']);
|
2017-01-26 13:00:27 +01:00
|
|
|
assert.equal(filtered_people.num_items(), 2);
|
|
|
|
assert(filtered_people.has(charles.user_id));
|
|
|
|
assert(filtered_people.has(maria.user_id));
|
2016-11-14 22:34:46 +01:00
|
|
|
|
2017-06-21 03:33:30 +02:00
|
|
|
// Test filtering of names with diacritics
|
|
|
|
// This should match Nöôáàh by ignoring diacritics, and also match Nooaah
|
|
|
|
filtered_people = people.filter_people_by_search_terms(users, ['noOa']);
|
|
|
|
assert.equal(filtered_people.num_items(), 2);
|
|
|
|
assert(filtered_people.has(noah.user_id));
|
|
|
|
assert(filtered_people.has(plain_noah.user_id));
|
|
|
|
|
|
|
|
// This should match ëmerson, but not emerson
|
|
|
|
filtered_people = people.filter_people_by_search_terms(users, ['ëm']);
|
|
|
|
assert.equal(filtered_people.num_items(), 1);
|
|
|
|
assert(filtered_people.has(noah.user_id));
|
|
|
|
|
2017-06-02 04:47:53 +02:00
|
|
|
// Test filtering with undefined user
|
|
|
|
var foo = {
|
|
|
|
email: 'foo@example.com',
|
|
|
|
user_id: 42,
|
|
|
|
full_name: 'Foo Bar',
|
|
|
|
};
|
|
|
|
users.push(foo);
|
|
|
|
|
|
|
|
filtered_people = people.filter_people_by_search_terms(users, ['ltorv']);
|
|
|
|
assert.equal(filtered_people.num_items(), 1);
|
|
|
|
assert(filtered_people.has(linus.user_id));
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2016-11-15 22:55:37 +01:00
|
|
|
|
2016-12-15 22:18:59 +01:00
|
|
|
people.init();
|
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('multi_user_methods', () => {
|
2016-12-15 22:18:59 +01:00
|
|
|
var emp401 = {
|
2016-11-15 22:55:37 +01:00
|
|
|
email: 'emp401@example.com',
|
|
|
|
user_id: 401,
|
2016-12-03 23:17:57 +01:00
|
|
|
full_name: 'whatever 401',
|
2016-11-15 22:55:37 +01:00
|
|
|
};
|
|
|
|
var emp402 = {
|
2016-11-19 00:33:32 +01:00
|
|
|
email: 'EMP402@example.com',
|
2016-11-15 22:55:37 +01:00
|
|
|
user_id: 402,
|
2016-12-03 23:17:57 +01:00
|
|
|
full_name: 'whatever 402',
|
2016-11-15 22:55:37 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
people.add_in_realm(emp401);
|
|
|
|
people.add_in_realm(emp402);
|
|
|
|
|
2016-11-19 00:33:32 +01:00
|
|
|
var emails_string = people.user_ids_string_to_emails_string('402,401');
|
2016-11-15 22:55:37 +01:00
|
|
|
assert.equal(emails_string, 'emp401@example.com,emp402@example.com');
|
|
|
|
|
Make nicer slugs for "pm-with" narrows.
The slugs for PM-with narrows now have user ids in them, so they
are more resilient to email changes, and they have less escaping
characters and are generally prettier.
Examples:
narrow/pm-with/3-cordelia
narrow/pm-with/3,5-group
The part of the URL that is actionable is the comma-delimited
list of one or more userids.
When we decode the slugs, we only use the part before the dash; the
stuff after the dash is just for humans. If we don't see a number
before the dash, we fall back to the old decoding (which should only
matter during a transition period where folks may have old links).
For group PMS, we always say "group" after the dash. For single PMs,
we use the person's email userid, since it's usually fairly concise
and not noisy for a URL. We may tinker with this later.
Basically, the heart of this change is these two new methods:
people.emails_to_slug
people.slug_to_emails
And then we unify the encode codepath as follows:
narrow.pm_with_uri ->
hashchange.operators_to_hash ->
hashchange.encode_operand ->
people.emails_to_slug
The decode path didn't really require much modication in this commit,
other than to have hashchange.decode_operand call people.slug_to_emails
for the pm-with case.
2017-01-06 02:00:03 +01:00
|
|
|
emails_string = people.slug_to_emails('402,401-group');
|
|
|
|
assert.equal(emails_string, 'emp401@example.com,emp402@example.com');
|
|
|
|
|
2016-11-19 00:33:32 +01:00
|
|
|
emails_string = 'emp402@example.com,EMP401@EXAMPLE.COM';
|
2016-11-15 22:55:37 +01:00
|
|
|
var user_ids_string = people.emails_strings_to_user_ids_string(emails_string);
|
|
|
|
assert.equal(user_ids_string, '401,402');
|
Make nicer slugs for "pm-with" narrows.
The slugs for PM-with narrows now have user ids in them, so they
are more resilient to email changes, and they have less escaping
characters and are generally prettier.
Examples:
narrow/pm-with/3-cordelia
narrow/pm-with/3,5-group
The part of the URL that is actionable is the comma-delimited
list of one or more userids.
When we decode the slugs, we only use the part before the dash; the
stuff after the dash is just for humans. If we don't see a number
before the dash, we fall back to the old decoding (which should only
matter during a transition period where folks may have old links).
For group PMS, we always say "group" after the dash. For single PMs,
we use the person's email userid, since it's usually fairly concise
and not noisy for a URL. We may tinker with this later.
Basically, the heart of this change is these two new methods:
people.emails_to_slug
people.slug_to_emails
And then we unify the encode codepath as follows:
narrow.pm_with_uri ->
hashchange.operators_to_hash ->
hashchange.encode_operand ->
people.emails_to_slug
The decode path didn't really require much modication in this commit,
other than to have hashchange.decode_operand call people.slug_to_emails
for the pm-with case.
2017-01-06 02:00:03 +01:00
|
|
|
|
2017-04-03 19:21:18 +02:00
|
|
|
user_ids_string = people.reply_to_to_user_ids_string(emails_string);
|
|
|
|
assert.equal(user_ids_string, '401,402');
|
|
|
|
|
Make nicer slugs for "pm-with" narrows.
The slugs for PM-with narrows now have user ids in them, so they
are more resilient to email changes, and they have less escaping
characters and are generally prettier.
Examples:
narrow/pm-with/3-cordelia
narrow/pm-with/3,5-group
The part of the URL that is actionable is the comma-delimited
list of one or more userids.
When we decode the slugs, we only use the part before the dash; the
stuff after the dash is just for humans. If we don't see a number
before the dash, we fall back to the old decoding (which should only
matter during a transition period where folks may have old links).
For group PMS, we always say "group" after the dash. For single PMs,
we use the person's email userid, since it's usually fairly concise
and not noisy for a URL. We may tinker with this later.
Basically, the heart of this change is these two new methods:
people.emails_to_slug
people.slug_to_emails
And then we unify the encode codepath as follows:
narrow.pm_with_uri ->
hashchange.operators_to_hash ->
hashchange.encode_operand ->
people.emails_to_slug
The decode path didn't really require much modication in this commit,
other than to have hashchange.decode_operand call people.slug_to_emails
for the pm-with case.
2017-01-06 02:00:03 +01:00
|
|
|
var slug = people.emails_to_slug(emails_string);
|
|
|
|
assert.equal(slug, '401,402-group');
|
2017-04-03 19:21:18 +02:00
|
|
|
|
|
|
|
assert.equal(people.reply_to_to_user_ids_string('invalid@example.com'), undefined);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
Make nicer slugs for "pm-with" narrows.
The slugs for PM-with narrows now have user ids in them, so they
are more resilient to email changes, and they have less escaping
characters and are generally prettier.
Examples:
narrow/pm-with/3-cordelia
narrow/pm-with/3,5-group
The part of the URL that is actionable is the comma-delimited
list of one or more userids.
When we decode the slugs, we only use the part before the dash; the
stuff after the dash is just for humans. If we don't see a number
before the dash, we fall back to the old decoding (which should only
matter during a transition period where folks may have old links).
For group PMS, we always say "group" after the dash. For single PMs,
we use the person's email userid, since it's usually fairly concise
and not noisy for a URL. We may tinker with this later.
Basically, the heart of this change is these two new methods:
people.emails_to_slug
people.slug_to_emails
And then we unify the encode codepath as follows:
narrow.pm_with_uri ->
hashchange.operators_to_hash ->
hashchange.encode_operand ->
people.emails_to_slug
The decode path didn't really require much modication in this commit,
other than to have hashchange.decode_operand call people.slug_to_emails
for the pm-with case.
2017-01-06 02:00:03 +01:00
|
|
|
|
2017-02-06 20:48:01 +01:00
|
|
|
initialize();
|
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('message_methods', () => {
|
2017-02-06 20:48:01 +01:00
|
|
|
var charles = {
|
|
|
|
email: 'charles@example.com',
|
|
|
|
user_id: 451,
|
|
|
|
full_name: 'Charles Dickens',
|
2017-04-03 20:02:02 +02:00
|
|
|
avatar_url: 'charles.com/foo.png',
|
2018-10-31 18:15:29 +01:00
|
|
|
is_guest: false,
|
2017-02-06 20:48:01 +01:00
|
|
|
};
|
2018-10-31 18:15:29 +01:00
|
|
|
// Maria is an intentionally incomplete user object without all attributes
|
2017-02-06 20:48:01 +01:00
|
|
|
var maria = {
|
2018-05-10 21:18:23 +02:00
|
|
|
email: 'Athens@example.com',
|
2017-02-06 20:48:01 +01:00
|
|
|
user_id: 452,
|
|
|
|
full_name: 'Maria Athens',
|
|
|
|
};
|
|
|
|
people.add(charles);
|
|
|
|
people.add(maria);
|
|
|
|
|
2018-04-05 21:36:32 +02:00
|
|
|
assert.equal(people.small_avatar_url_for_person(maria),
|
|
|
|
'https://secure.gravatar.com/avatar/md5-athens@example.com?d=identicon&s=50');
|
2017-02-06 20:48:01 +01:00
|
|
|
var message = {
|
|
|
|
type: 'private',
|
|
|
|
display_recipient: [
|
|
|
|
{id: maria.user_id},
|
|
|
|
{id: me.user_id},
|
|
|
|
{user_id: charles.user_id},
|
|
|
|
],
|
2017-04-03 20:02:02 +02:00
|
|
|
sender_id: charles.user_id,
|
2017-02-06 20:48:01 +01:00
|
|
|
};
|
|
|
|
assert.equal(people.pm_with_url(message), '#narrow/pm-with/451,452-group');
|
2018-10-18 22:05:28 +02:00
|
|
|
assert.equal(people.pm_perma_link(message), '#narrow/pm-with/30,451,452-group');
|
2017-04-03 19:47:25 +02:00
|
|
|
assert.equal(people.pm_reply_to(message),
|
2018-05-10 21:18:23 +02:00
|
|
|
'Athens@example.com,charles@example.com');
|
2017-04-03 20:02:02 +02:00
|
|
|
assert.equal(people.small_avatar_url(message),
|
2018-05-07 03:30:13 +02:00
|
|
|
'charles.com/foo.png&s=50');
|
2017-02-06 20:48:01 +01:00
|
|
|
|
|
|
|
message = {
|
|
|
|
type: 'private',
|
|
|
|
display_recipient: [
|
|
|
|
{id: maria.user_id},
|
|
|
|
{user_id: me.user_id},
|
|
|
|
],
|
2017-04-03 20:02:02 +02:00
|
|
|
avatar_url: 'legacy.png',
|
2017-02-06 20:48:01 +01:00
|
|
|
};
|
|
|
|
assert.equal(people.pm_with_url(message), '#narrow/pm-with/452-athens');
|
2018-10-18 22:05:28 +02:00
|
|
|
assert.equal(people.pm_perma_link(message), '#narrow/pm-with/30,452-pm');
|
2017-04-03 19:47:25 +02:00
|
|
|
assert.equal(people.pm_reply_to(message),
|
2018-05-10 21:18:23 +02:00
|
|
|
'Athens@example.com');
|
2017-04-03 20:02:02 +02:00
|
|
|
assert.equal(people.small_avatar_url(message),
|
2018-05-07 03:30:13 +02:00
|
|
|
'legacy.png&s=50');
|
2017-02-06 20:48:01 +01:00
|
|
|
|
2017-11-03 17:25:47 +01:00
|
|
|
message = {
|
|
|
|
avatar_url: undefined,
|
|
|
|
sender_id: maria.user_id,
|
|
|
|
};
|
|
|
|
assert.equal(people.small_avatar_url(message),
|
2018-05-07 03:30:13 +02:00
|
|
|
'https://secure.gravatar.com/avatar/md5-athens@example.com?d=identicon&s=50'
|
2017-11-03 17:25:47 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
message = {
|
|
|
|
avatar_url: undefined,
|
|
|
|
sender_email: 'foo@example.com',
|
|
|
|
sender_id: 9999999,
|
|
|
|
};
|
|
|
|
assert.equal(people.small_avatar_url(message),
|
2018-05-07 03:30:13 +02:00
|
|
|
'https://secure.gravatar.com/avatar/md5-foo@example.com?d=identicon&s=50'
|
2017-11-03 17:25:47 +01:00
|
|
|
);
|
|
|
|
|
2017-02-06 20:48:01 +01:00
|
|
|
message = {
|
|
|
|
type: 'private',
|
|
|
|
display_recipient: [
|
|
|
|
{user_id: me.user_id},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
assert.equal(people.pm_with_url(message), '#narrow/pm-with/30-me');
|
2018-10-18 22:05:28 +02:00
|
|
|
assert.equal(people.pm_perma_link(message), '#narrow/pm-with/30-pm');
|
2017-06-02 04:47:53 +02:00
|
|
|
|
|
|
|
message = { type: 'stream' };
|
|
|
|
assert.equal(people.pm_with_user_ids(message), undefined);
|
2018-10-18 22:05:28 +02:00
|
|
|
assert.equal(people.all_user_ids_in_pm(message), undefined);
|
2017-06-02 04:47:53 +02:00
|
|
|
|
|
|
|
// Test undefined user_ids
|
|
|
|
assert.equal(people.pm_reply_to(message), undefined);
|
|
|
|
assert.equal(people.pm_reply_user_string(message), undefined);
|
|
|
|
assert.equal(people.pm_with_url(message), undefined);
|
|
|
|
|
|
|
|
// Test sender_is_bot
|
|
|
|
var bot = {
|
|
|
|
email: 'bot@example.com',
|
|
|
|
user_id: 42,
|
|
|
|
full_name: 'Test Bot',
|
|
|
|
is_bot: true,
|
|
|
|
};
|
|
|
|
people.add(bot);
|
|
|
|
|
|
|
|
message = { sender_id: bot.user_id };
|
|
|
|
assert.equal(people.sender_is_bot(message), true);
|
|
|
|
|
|
|
|
message = { sender_id: maria.user_id };
|
|
|
|
assert.equal(people.sender_is_bot(message), undefined);
|
|
|
|
|
|
|
|
message = { sender_id: undefined };
|
|
|
|
assert.equal(people.sender_is_bot(message), false);
|
2018-10-31 18:15:29 +01:00
|
|
|
|
|
|
|
// Test sender_is_guest
|
|
|
|
var polonius = {
|
|
|
|
email: 'polonius@example.com',
|
|
|
|
user_id: 43,
|
|
|
|
full_name: 'Guest User',
|
|
|
|
is_bot: false,
|
|
|
|
is_guest: true,
|
|
|
|
};
|
|
|
|
people.add(polonius);
|
|
|
|
|
|
|
|
message = { sender_id: polonius.user_id };
|
|
|
|
assert.equal(people.sender_is_guest(message), true);
|
|
|
|
|
|
|
|
message = { sender_id: maria.user_id };
|
|
|
|
assert.equal(people.sender_is_guest(message), undefined);
|
|
|
|
|
|
|
|
message = { sender_id: charles.user_id };
|
|
|
|
assert.equal(people.sender_is_guest(message), false);
|
|
|
|
|
|
|
|
message = { sender_id: undefined };
|
|
|
|
assert.equal(people.sender_is_guest(message), false);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-06-02 04:47:53 +02:00
|
|
|
|
|
|
|
initialize();
|
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('extract_people_from_message', () => {
|
2017-11-06 16:47:19 +01:00
|
|
|
var unknown_user = {
|
|
|
|
email: 'unknown@example.com',
|
|
|
|
user_id: 500,
|
|
|
|
unknown_local_echo_user: true,
|
|
|
|
};
|
|
|
|
|
2017-06-02 04:47:53 +02:00
|
|
|
var maria = {
|
|
|
|
email: 'athens@example.com',
|
|
|
|
user_id: 452,
|
|
|
|
full_name: 'Maria Athens',
|
|
|
|
};
|
|
|
|
|
|
|
|
var message = {
|
|
|
|
type: 'stream',
|
|
|
|
sender_full_name: maria.full_name,
|
|
|
|
sender_id: maria.user_id,
|
|
|
|
sender_email: maria.email,
|
|
|
|
};
|
2017-11-06 15:48:44 +01:00
|
|
|
assert(!people.is_known_user_id(maria.user_id));
|
2017-11-06 17:03:01 +01:00
|
|
|
|
|
|
|
var reported;
|
|
|
|
people.report_late_add = function (user_id, email) {
|
|
|
|
assert.equal(user_id, maria.user_id);
|
|
|
|
assert.equal(email, maria.email);
|
|
|
|
reported = true;
|
|
|
|
};
|
|
|
|
|
2017-06-02 04:47:53 +02:00
|
|
|
people.extract_people_from_message(message);
|
|
|
|
assert(people.is_known_user_id(maria.user_id));
|
2017-11-06 17:03:01 +01:00
|
|
|
assert(reported);
|
2017-11-06 16:47:19 +01:00
|
|
|
|
|
|
|
// Get line coverage
|
2017-11-06 17:03:01 +01:00
|
|
|
people.report_late_add = function () {
|
|
|
|
throw Error('unexpected late add');
|
|
|
|
};
|
|
|
|
|
2017-11-06 16:47:19 +01:00
|
|
|
message = {
|
|
|
|
type: 'private',
|
|
|
|
display_recipient: [unknown_user],
|
|
|
|
};
|
|
|
|
people.extract_people_from_message(message);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-11-06 15:48:44 +01:00
|
|
|
|
|
|
|
initialize();
|
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('maybe_incr_recipient_count', () => {
|
2017-11-06 15:48:44 +01:00
|
|
|
var maria = {
|
|
|
|
email: 'athens@example.com',
|
|
|
|
user_id: 452,
|
|
|
|
full_name: 'Maria Athens',
|
|
|
|
};
|
|
|
|
people.add_in_realm(maria);
|
|
|
|
|
|
|
|
var unknown_user = {
|
|
|
|
email: 'unknown@example.com',
|
|
|
|
user_id: 500,
|
|
|
|
unknown_local_echo_user: true,
|
|
|
|
};
|
|
|
|
|
|
|
|
var message = {
|
|
|
|
type: 'private',
|
|
|
|
display_recipient: [maria],
|
|
|
|
sent_by_me: true,
|
|
|
|
};
|
|
|
|
assert.equal(people.get_recipient_count(maria), 0);
|
|
|
|
people.maybe_incr_recipient_count(message);
|
|
|
|
assert.equal(people.get_recipient_count(maria), 1);
|
2017-06-02 04:47:53 +02:00
|
|
|
|
2017-11-06 15:48:44 +01:00
|
|
|
// Test all the no-op conditions to get test
|
|
|
|
// coverage.
|
2017-06-02 04:47:53 +02:00
|
|
|
message = {
|
|
|
|
type: 'private',
|
2017-11-06 15:48:44 +01:00
|
|
|
sent_by_me: false,
|
2017-06-02 04:47:53 +02:00
|
|
|
display_recipient: [maria],
|
2017-11-06 15:48:44 +01:00
|
|
|
};
|
|
|
|
people.maybe_incr_recipient_count(message);
|
|
|
|
assert.equal(people.get_recipient_count(maria), 1);
|
|
|
|
|
|
|
|
message = {
|
|
|
|
type: 'private',
|
2017-06-02 04:47:53 +02:00
|
|
|
sent_by_me: true,
|
2017-11-06 15:48:44 +01:00
|
|
|
display_recipient: [unknown_user],
|
2017-06-02 04:47:53 +02:00
|
|
|
};
|
2017-11-06 15:48:44 +01:00
|
|
|
people.maybe_incr_recipient_count(message);
|
|
|
|
assert.equal(people.get_recipient_count(maria), 1);
|
|
|
|
|
|
|
|
message = {
|
|
|
|
type: 'stream',
|
|
|
|
};
|
|
|
|
people.maybe_incr_recipient_count(message);
|
2017-06-02 04:47:53 +02:00
|
|
|
assert.equal(people.get_recipient_count(maria), 1);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-02-06 20:48:01 +01:00
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('slugs', () => {
|
Make nicer slugs for "pm-with" narrows.
The slugs for PM-with narrows now have user ids in them, so they
are more resilient to email changes, and they have less escaping
characters and are generally prettier.
Examples:
narrow/pm-with/3-cordelia
narrow/pm-with/3,5-group
The part of the URL that is actionable is the comma-delimited
list of one or more userids.
When we decode the slugs, we only use the part before the dash; the
stuff after the dash is just for humans. If we don't see a number
before the dash, we fall back to the old decoding (which should only
matter during a transition period where folks may have old links).
For group PMS, we always say "group" after the dash. For single PMs,
we use the person's email userid, since it's usually fairly concise
and not noisy for a URL. We may tinker with this later.
Basically, the heart of this change is these two new methods:
people.emails_to_slug
people.slug_to_emails
And then we unify the encode codepath as follows:
narrow.pm_with_uri ->
hashchange.operators_to_hash ->
hashchange.encode_operand ->
people.emails_to_slug
The decode path didn't really require much modication in this commit,
other than to have hashchange.decode_operand call people.slug_to_emails
for the pm-with case.
2017-01-06 02:00:03 +01:00
|
|
|
var person = {
|
|
|
|
email: 'deBBie71@example.com',
|
|
|
|
user_id: 501,
|
|
|
|
full_name: 'Debra Henton',
|
|
|
|
};
|
|
|
|
people.add(person);
|
|
|
|
|
|
|
|
var slug = people.emails_to_slug(person.email);
|
|
|
|
assert.equal(slug, '501-debbie71');
|
|
|
|
|
|
|
|
var email = people.slug_to_emails(slug);
|
|
|
|
assert.equal(email, 'debbie71@example.com');
|
2017-06-02 04:47:53 +02:00
|
|
|
|
|
|
|
// Test undefined slug
|
2018-05-30 13:05:27 +02:00
|
|
|
assert.equal(people.emails_to_slug('does@not.exist'), undefined);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-01-31 20:44:51 +01:00
|
|
|
|
|
|
|
initialize();
|
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('updates', () => {
|
2017-01-31 20:44:51 +01:00
|
|
|
var old_email = 'FOO@example.com';
|
|
|
|
var new_email = 'bar@example.com';
|
|
|
|
var user_id = 502;
|
|
|
|
|
|
|
|
var person = {
|
|
|
|
email: old_email,
|
|
|
|
user_id: user_id,
|
|
|
|
full_name: 'Foo Barson',
|
|
|
|
};
|
|
|
|
people.add_in_realm(person);
|
|
|
|
|
|
|
|
// Do sanity checks on our data.
|
|
|
|
assert.equal(people.get_by_email(old_email).user_id, user_id);
|
2017-10-26 18:52:42 +02:00
|
|
|
assert.equal(people.get_active_user_for_email(old_email).user_id, user_id);
|
2017-01-31 20:44:51 +01:00
|
|
|
assert (!people.is_cross_realm_email(old_email));
|
|
|
|
|
|
|
|
assert.equal(people.get_by_email(new_email), undefined);
|
|
|
|
|
|
|
|
// DO THE EMAIL UPDATE HERE.
|
|
|
|
people.update_email(user_id, new_email);
|
|
|
|
|
|
|
|
// Now look up using the new email.
|
|
|
|
assert.equal(people.get_by_email(new_email).user_id, user_id);
|
2017-10-26 18:52:42 +02:00
|
|
|
assert.equal(people.get_active_user_for_email(new_email).user_id, user_id);
|
2017-01-31 20:44:51 +01:00
|
|
|
assert (!people.is_cross_realm_email(new_email));
|
|
|
|
|
|
|
|
var all_people = people.get_all_persons();
|
|
|
|
assert.equal(all_people.length, 2);
|
|
|
|
|
|
|
|
person = _.filter(all_people, function (p) {
|
2018-06-06 18:19:09 +02:00
|
|
|
return p.email === new_email;
|
2017-01-31 20:44:51 +01:00
|
|
|
})[0];
|
|
|
|
assert.equal(person.full_name, 'Foo Barson');
|
|
|
|
|
|
|
|
// Test shim where we can still retrieve user info using the
|
|
|
|
// old email.
|
2018-05-01 05:55:50 +02:00
|
|
|
blueslip.set_test_data('warn',
|
2018-05-07 03:30:13 +02:00
|
|
|
'Obsolete email passed to get_by_email: ' +
|
|
|
|
'FOO@example.com new email = bar@example.com');
|
2017-01-31 20:44:51 +01:00
|
|
|
person = people.get_by_email(old_email);
|
|
|
|
assert.equal(person.user_id, user_id);
|
2018-05-01 05:55:50 +02:00
|
|
|
assert.equal(blueslip.get_test_logs('warn').length, 1);
|
|
|
|
blueslip.clear_test_data();
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-02-10 03:18:57 +01:00
|
|
|
|
|
|
|
initialize();
|
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('update_email_in_reply_to', () => {
|
2017-02-10 03:18:57 +01:00
|
|
|
var charles = {
|
|
|
|
email: 'charles@example.com',
|
|
|
|
user_id: 601,
|
|
|
|
full_name: 'Charles Dickens',
|
|
|
|
};
|
|
|
|
var maria = {
|
|
|
|
email: 'athens@example.com',
|
|
|
|
user_id: 602,
|
|
|
|
full_name: 'Maria Athens',
|
|
|
|
};
|
|
|
|
people.add(charles);
|
|
|
|
people.add(maria);
|
|
|
|
|
|
|
|
var reply_to = ' charles@example.com, athens@example.com';
|
|
|
|
assert.equal(
|
|
|
|
people.update_email_in_reply_to(reply_to, 9999, 'whatever'),
|
|
|
|
reply_to
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
people.update_email_in_reply_to(reply_to, maria.user_id, 'maria@example.com'),
|
|
|
|
'charles@example.com,maria@example.com'
|
|
|
|
);
|
2017-06-02 04:47:53 +02:00
|
|
|
|
|
|
|
reply_to = ' charles@example.com, athens@example.com, unknown@example.com';
|
|
|
|
assert.equal(
|
|
|
|
people.update_email_in_reply_to(reply_to, 9999, 'whatever'),
|
|
|
|
reply_to
|
|
|
|
);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-02-10 03:18:57 +01:00
|
|
|
|
2018-08-08 21:56:07 +02:00
|
|
|
initialize();
|
|
|
|
|
|
|
|
run_test('track_duplicate_full_names', () => {
|
|
|
|
var stephen1 = {
|
|
|
|
email: 'stephen-the-author@example.com',
|
|
|
|
user_id: 601,
|
|
|
|
full_name: 'Stephen King',
|
|
|
|
};
|
|
|
|
var stephen2 = {
|
|
|
|
email: 'stephen-the-explorer@example.com',
|
|
|
|
user_id: 602,
|
|
|
|
full_name: 'Stephen King',
|
|
|
|
};
|
|
|
|
var maria = {
|
|
|
|
email: 'athens@example.com',
|
|
|
|
user_id: 603,
|
|
|
|
full_name: 'Maria Athens',
|
|
|
|
};
|
|
|
|
people.add(stephen1);
|
|
|
|
people.add(stephen2);
|
|
|
|
people.add(maria);
|
|
|
|
assert(people.is_duplicate_full_name('Stephen King'));
|
|
|
|
assert(!people.is_duplicate_full_name('Maria Athens'));
|
|
|
|
assert(!people.is_duplicate_full_name('Some Random Name'));
|
|
|
|
people.set_full_name(stephen2, 'Stephen King JP');
|
|
|
|
assert(!people.is_duplicate_full_name('Stephen King'));
|
|
|
|
assert(!people.is_duplicate_full_name('Stephen King JP'));
|
|
|
|
});
|
|
|
|
|
2018-10-13 02:25:38 +02:00
|
|
|
run_test('track_duplicate_full_names', () => {
|
|
|
|
var stephen1 = {
|
|
|
|
email: 'stephen-the-author@example.com',
|
|
|
|
user_id: 601,
|
|
|
|
full_name: 'Stephen King',
|
|
|
|
};
|
|
|
|
var stephen2 = {
|
|
|
|
email: 'stephen-the-explorer@example.com',
|
|
|
|
user_id: 602,
|
|
|
|
full_name: 'Stephen King',
|
|
|
|
};
|
|
|
|
var maria = {
|
|
|
|
email: 'athens@example.com',
|
|
|
|
user_id: 603,
|
|
|
|
full_name: 'Maria Athens',
|
|
|
|
};
|
|
|
|
people.add(stephen1);
|
|
|
|
people.add(stephen2);
|
|
|
|
people.add(maria);
|
|
|
|
|
|
|
|
blueslip.set_test_data('warn', 'get_mention_syntax called without user_id.');
|
|
|
|
assert.equal(people.get_mention_syntax('Stephen King'), '@**Stephen King**');
|
|
|
|
assert.equal(blueslip.get_test_logs('warn').length, 1);
|
|
|
|
blueslip.clear_test_data();
|
|
|
|
assert.equal(people.get_mention_syntax('Stephen King', 601), '@**Stephen King|601**');
|
|
|
|
assert.equal(people.get_mention_syntax('Stephen King', 602), '@**Stephen King|602**');
|
|
|
|
assert.equal(people.get_mention_syntax('Maria Athens', 603), '@**Maria Athens**');
|
|
|
|
});
|
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('initialize', () => {
|
2017-06-02 04:47:53 +02:00
|
|
|
people.init();
|
|
|
|
|
2017-11-06 14:56:06 +01:00
|
|
|
global.page_params.realm_non_active_users = [
|
|
|
|
{
|
|
|
|
email: 'retiree@example.com',
|
|
|
|
user_id: 15,
|
|
|
|
full_name: 'Retiree',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2017-06-02 04:47:53 +02:00
|
|
|
global.page_params.realm_users = [
|
|
|
|
{
|
|
|
|
email: 'alice@example.com',
|
|
|
|
user_id: 16,
|
|
|
|
full_name: 'Alice',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
global.page_params.cross_realm_bots = [
|
|
|
|
{
|
|
|
|
email: 'bot@example.com',
|
|
|
|
user_id: 17,
|
|
|
|
full_name: 'Test Bot',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
global.page_params.user_id = 42;
|
|
|
|
|
|
|
|
people.initialize();
|
|
|
|
|
2017-10-26 18:52:42 +02:00
|
|
|
assert.equal(people.get_active_user_for_email('alice@example.com').full_name, 'Alice');
|
2017-10-26 21:00:30 +02:00
|
|
|
assert.equal(people.is_active_user_for_popover(17), true);
|
2017-06-02 04:47:53 +02:00
|
|
|
assert(people.is_cross_realm_email('bot@example.com'));
|
2017-10-26 18:45:08 +02:00
|
|
|
assert(people.is_valid_email_for_compose('bot@example.com'));
|
|
|
|
assert(people.is_valid_email_for_compose('alice@example.com'));
|
2017-11-06 14:56:06 +01:00
|
|
|
assert(!people.is_valid_email_for_compose('retiree@example.com'));
|
2018-03-06 15:07:55 +01:00
|
|
|
assert(!people.is_valid_email_for_compose('totally-bogus-username@example.com'));
|
2018-05-28 14:10:33 +02:00
|
|
|
assert(people.is_valid_bulk_emails_for_compose(['bot@example.com', 'alice@example.com']));
|
|
|
|
assert(!people.is_valid_bulk_emails_for_compose(['not@valid.com', 'alice@example.com']));
|
2017-06-02 04:47:53 +02:00
|
|
|
assert(people.is_my_user_id(42));
|
|
|
|
|
2017-11-06 14:56:06 +01:00
|
|
|
var fetched_retiree = people.get_person_from_user_id(15);
|
2019-02-15 23:38:59 +01:00
|
|
|
assert.equal(fetched_retiree.full_name, 'Retiree');
|
2017-11-06 14:56:06 +01:00
|
|
|
|
2017-06-02 04:47:53 +02:00
|
|
|
assert.equal(global.page_params.realm_users, undefined);
|
|
|
|
assert.equal(global.page_params.cross_realm_bots, undefined);
|
2017-11-06 14:56:06 +01:00
|
|
|
assert.equal(global.page_params.realm_non_active_users, undefined);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|