Create blueslip error for undefined keys in Dict.

We create a blueslip error for undefined keys in Dict.  This led
to a straightforward change in the unit tests for Dict.  For the
unread test, to avoid the blueslip error, we had to be more specific
in setting up a user in one place, but this reduced our coverage,
leading to another small test being added.

(imported from commit 33e14795500d9283de2a7c03c4c58aec11cea4b8)
This commit is contained in:
Steve Howell 2013-09-10 17:33:46 -04:00
parent 9eefc8ae62
commit 0165dc54ad
3 changed files with 13 additions and 2 deletions

View File

@ -53,6 +53,7 @@ Dict.from_array = function Dict_from_array(xs, opts) {
Dict.prototype = {
_munge: function Dict__munge(k) {
if (k === undefined) {
blueslip.error("Tried to call a Dict method with an undefined key.");
return undefined;
}
if (this._opts.fold_case) {

View File

@ -6,6 +6,8 @@ var _ = global._;
var Dict = require('js/dict.js');
var assert = require('assert');
set_global('blueslip', {});
(function test_basic() {
var d = new Dict();
@ -60,6 +62,10 @@ var assert = require('assert');
}());
(function test_undefined_keys() {
global.blueslip.error = function (msg) {
assert.equal(msg, "Tried to call a Dict method with an undefined key.");
};
var d = new Dict();
assert.equal(d.has(undefined), false);

View File

@ -196,7 +196,8 @@ var zero_counts = {
var message = {
id: 15,
type: 'private'
type: 'private',
reply_to: 'alice@zulip.com'
};
unread.process_loaded_messages([message]);
@ -209,7 +210,10 @@ var zero_counts = {
}());
(function test_num_unread_for_person() {
var email = 'alice@zulip.com';
var email = 'unknown@zulip.com';
assert.equal(unread.num_unread_for_person(email), 0);
email = 'alice@zulip.com';
assert.equal(unread.num_unread_for_person(email), 0);
var message = {