2017-11-06 15:10:33 +01:00
|
|
|
zrequire('people');
|
2018-07-31 07:20:03 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const return_false = function () { return false; };
|
|
|
|
const return_true = function () { return true; };
|
2018-08-04 15:40:25 +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
|
|
|
|
2018-04-13 10:03:03 +02:00
|
|
|
set_global('blueslip', global.make_zblueslip({
|
|
|
|
debug: true, // testing for debug is disabled by default.
|
|
|
|
}));
|
2017-11-06 15:10:33 +01:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const me = {
|
2017-11-06 15:10:33 +01:00
|
|
|
email: 'me@example.com',
|
|
|
|
user_id: 30,
|
|
|
|
full_name: 'Me Myself',
|
|
|
|
timezone: 'US/Pacific',
|
|
|
|
};
|
|
|
|
|
|
|
|
people.init();
|
|
|
|
people.add(me);
|
|
|
|
people.initialize_current_user(me.user_id);
|
|
|
|
|
2018-05-15 12:40:07 +02:00
|
|
|
run_test('report_late_add', () => {
|
2018-04-13 10:03:03 +02:00
|
|
|
blueslip.set_test_data('error', 'Added user late: user_id=55 email=foo@example.com');
|
2017-11-06 17:03:01 +01:00
|
|
|
people.report_late_add(55, 'foo@example.com');
|
2018-04-13 10:03:03 +02:00
|
|
|
assert.equal(blueslip.get_test_logs('error').length, 1);
|
|
|
|
blueslip.clear_test_data();
|
2018-04-23 21:13:21 +02:00
|
|
|
|
2018-08-04 15:40:25 +02:00
|
|
|
reload_state.is_in_progress = return_true;
|
2018-04-23 21:13:21 +02:00
|
|
|
people.report_late_add(55, 'foo@example.com');
|
2018-04-24 00:29:46 +02:00
|
|
|
assert.equal(blueslip.get_test_logs('log').length, 1);
|
2018-07-10 09:28:25 +02:00
|
|
|
assert.equal(blueslip.get_test_logs('log')[0].message, 'Added user late: user_id=55 email=foo@example.com');
|
2018-04-23 21:13:21 +02:00
|
|
|
assert.equal(blueslip.get_test_logs('error').length, 0);
|
|
|
|
blueslip.clear_test_data();
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-11-06 17:03:01 +01:00
|
|
|
|
2018-05-15 12:40:07 +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
|
|
|
|
2018-04-13 10:03:03 +02:00
|
|
|
blueslip.set_test_data('debug', 'User email operand unknown: ' + unknown_email);
|
2017-11-06 15:10:33 +01:00
|
|
|
people.id_matches_email_operand(42, unknown_email);
|
2018-04-13 10:03:03 +02:00
|
|
|
assert.equal(blueslip.get_test_logs('debug').length, 1);
|
|
|
|
blueslip.clear_test_data();
|
2017-11-06 15:10:33 +01:00
|
|
|
|
2018-04-13 10:03:03 +02:00
|
|
|
blueslip.set_test_data('error', 'Unknown email for get_user_id: ' + unknown_email);
|
2017-11-06 15:10:33 +01:00
|
|
|
people.get_user_id(unknown_email);
|
2018-04-13 10:03:03 +02:00
|
|
|
assert.equal(blueslip.get_test_logs('error').length, 1);
|
|
|
|
blueslip.clear_test_data();
|
2017-11-06 15:10:33 +01:00
|
|
|
|
2018-04-13 10:03:03 +02:00
|
|
|
blueslip.set_test_data('warn', 'No user_id provided for person@example.com');
|
2019-11-02 00:06:25 +01:00
|
|
|
const person = {
|
2017-11-06 15:10:33 +01:00
|
|
|
email: 'person@example.com',
|
|
|
|
user_id: undefined,
|
|
|
|
full_name: 'Person Person',
|
|
|
|
};
|
|
|
|
people.add(person);
|
2018-04-13 10:03:03 +02:00
|
|
|
assert.equal(blueslip.get_test_logs('warn').length, 1);
|
|
|
|
blueslip.clear_test_data();
|
2017-11-06 15:10:33 +01:00
|
|
|
|
2018-04-13 10:03:03 +02:00
|
|
|
blueslip.set_test_data('error', 'No user_id found for person@example.com');
|
2019-11-02 00:06:25 +01:00
|
|
|
const user_id = people.get_user_id('person@example.com');
|
2017-11-06 15:10:33 +01:00
|
|
|
assert.equal(user_id, undefined);
|
2018-04-13 10:03:03 +02:00
|
|
|
assert.equal(blueslip.get_test_logs('error').length, 1);
|
|
|
|
blueslip.clear_test_data();
|
2017-11-06 15:10:33 +01:00
|
|
|
|
2018-10-27 15:40:36 +02:00
|
|
|
blueslip.set_test_data('warn', 'Unknown user ids: 1,2');
|
2017-11-06 15:10:33 +01:00
|
|
|
people.user_ids_string_to_emails_string('1,2');
|
2018-10-27 15:40:36 +02:00
|
|
|
assert.equal(blueslip.get_test_logs('warn').length, 1);
|
2018-04-13 10:03:03 +02:00
|
|
|
blueslip.clear_test_data();
|
2017-11-06 15:10:33 +01:00
|
|
|
|
2018-04-13 10:03:03 +02:00
|
|
|
blueslip.set_test_data('warn', 'Unknown emails: ' + unknown_email);
|
2017-11-06 15:10:33 +01:00
|
|
|
people.email_list_to_user_ids_string(unknown_email);
|
2018-04-13 10:03:03 +02:00
|
|
|
assert.equal(blueslip.get_test_logs('warn').length, 1);
|
|
|
|
blueslip.clear_test_data();
|
2017-11-06 15:10:33 +01:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let message = {
|
2017-11-06 15:10:33 +01:00
|
|
|
type: 'private',
|
|
|
|
display_recipient: [],
|
|
|
|
sender_id: me.user_id,
|
|
|
|
};
|
2018-04-13 10:03:03 +02:00
|
|
|
blueslip.set_test_data('error', 'Empty recipient list in message');
|
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);
|
|
|
|
assert.equal(blueslip.get_test_logs('error').length, 4);
|
2018-04-13 10:03:03 +02:00
|
|
|
blueslip.clear_test_data();
|
2017-11-06 15:10:33 +01:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const charles = {
|
2017-11-06 15:10:33 +01:00
|
|
|
email: 'charles@example.com',
|
|
|
|
user_id: 451,
|
|
|
|
full_name: 'Charles Dickens',
|
|
|
|
avatar_url: 'charles.com/foo.png',
|
|
|
|
};
|
2019-11-02 00:06:25 +01:00
|
|
|
const maria = {
|
2017-11-06 15:10:33 +01:00
|
|
|
email: 'athens@example.com',
|
|
|
|
user_id: 452,
|
|
|
|
full_name: 'Maria Athens',
|
|
|
|
};
|
|
|
|
people.add(charles);
|
|
|
|
people.add(maria);
|
|
|
|
|
|
|
|
message = {
|
|
|
|
type: 'private',
|
|
|
|
display_recipient: [
|
|
|
|
{id: maria.user_id},
|
|
|
|
{id: 42},
|
2020-01-01 13:02:34 +01:00
|
|
|
{id: charles.user_id},
|
2017-11-06 15:10:33 +01:00
|
|
|
],
|
|
|
|
sender_id: charles.user_id,
|
|
|
|
};
|
2018-04-13 10:03:03 +02:00
|
|
|
blueslip.set_test_data('error', 'Unknown user id in message: 42');
|
2019-11-02 00:06:25 +01:00
|
|
|
const reply_to = people.pm_reply_to(message);
|
2017-11-06 15:10:33 +01:00
|
|
|
assert(reply_to.indexOf('?') > -1);
|
2018-04-13 10:03:03 +02:00
|
|
|
assert.equal(blueslip.get_test_logs('error').length, 1);
|
|
|
|
blueslip.clear_test_data();
|
2017-11-06 15:10:33 +01:00
|
|
|
|
|
|
|
people.pm_with_user_ids = function () { return [42]; };
|
2018-03-13 13:04:16 +01:00
|
|
|
people.get_person_from_user_id = function () { return; };
|
2018-04-13 10:03:03 +02:00
|
|
|
blueslip.set_test_data('error', 'Unknown people in message');
|
2019-11-02 00:06:25 +01:00
|
|
|
const uri = people.pm_with_url({});
|
2017-11-06 15:10:33 +01:00
|
|
|
assert.equal(uri.indexOf('unk'), uri.length - 3);
|
2018-04-13 10:03:03 +02:00
|
|
|
assert.equal(blueslip.get_test_logs('error').length, 1);
|
|
|
|
blueslip.clear_test_data();
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|