node tests: Add coverage for blueslip errors in people.js.

This covers all blueslip errors and warnings
in people.js. These do not need to be tested
to rigorously and just need to be covered to
get people.js to 100% coverage.
This commit is contained in:
Joshua Pan 2017-05-31 14:22:00 -07:00 committed by showell
parent cc81b7892d
commit fd57fcbc1c
1 changed files with 84 additions and 0 deletions

View File

@ -388,3 +388,87 @@ initialize();
);
}());
(function test_blueslip() {
var unknown_email = "alicebobfred@example.com";
global.blueslip.debug = function (msg) {
assert.equal(msg, 'User email operand unknown: ' + unknown_email);
};
people.id_matches_email_operand(42, unknown_email);
global.blueslip.error = function (msg) {
assert.equal(msg, 'Unknown email for get_user_id: ' + unknown_email);
};
people.get_user_id(unknown_email);
var person = {
email: 'person@example.com',
user_id: undefined,
full_name: 'Person Person',
};
people.add(person);
global.blueslip.error = function (msg) {
assert.equal(msg, 'No userid found for person@example.com');
};
var user_id = people.get_user_id('person@example.com');
assert.equal(user_id, undefined);
global.blueslip.error = function (msg) {
assert.equal(msg, 'Unknown user ids: 1,2');
};
people.user_ids_string_to_emails_string('1,2');
global.blueslip.warn = function (msg) {
assert.equal(msg, 'Unknown emails: ' + unknown_email);
};
people.email_list_to_user_ids_string(unknown_email);
var message = {
type: 'private',
display_recipient: [],
sender_id: me.user_id,
};
global.blueslip.error = function (msg) {
assert.equal(msg, 'Empty recipient list in message');
};
people.pm_with_user_ids(message);
var charles = {
email: 'charles@example.com',
user_id: 451,
full_name: 'Charles Dickens',
avatar_url: 'charles.com/foo.png',
};
var maria = {
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},
{user_id: charles.user_id},
],
sender_id: charles.user_id,
};
global.blueslip.error = function (msg) {
assert.equal(msg, 'Unknown user id in message: 42');
};
var reply_to = people.pm_reply_to(message);
assert(reply_to.indexOf('?') > -1);
people.pm_with_user_ids = function () { return [42]; };
people.get_person_from_user_id = function () { return undefined; };
global.blueslip.error = function (msg) {
assert.equal(msg, 'Unknown people in message');
};
var uri = people.pm_with_url({});
assert.equal(uri.indexOf('unk'), uri.length - 3);
}());