Get stream_data.js back to 100% coverage

(imported from commit 5b82a10d50b6599c0c42604fe86275b21f9a6396)
This commit is contained in:
Steve Howell 2013-09-12 10:55:56 -04:00
parent 272921800a
commit 5eaeddea12
1 changed files with 36 additions and 0 deletions

View File

@ -66,3 +66,39 @@ var stream_data = require('js/stream_data.js');
stream_data.set_stream_info(info);
assert.deepEqual(stream_data.subscribed_streams(), ['Denmark']);
}());
(function test_subscribers() {
stream_data.clear_subscriptions();
var sub = {name: 'Rome', subscribed: true};
sub.subscribers = new global.Dict(); // TODO: encapsulate this in stream_data.js
stream_data.add_sub('Rome', sub);
var email = 'brutus@zulip.com';
assert(!stream_data.user_is_subscribed('Rome', email));
// add
stream_data.add_subscriber('Rome', email);
assert(stream_data.user_is_subscribed('Rome', email));
// verify that adding an already-removed subscriber is a noop
stream_data.add_subscriber('Rome', email);
assert(stream_data.user_is_subscribed('Rome', email));
// remove
stream_data.remove_subscriber('Rome', email);
assert(!stream_data.user_is_subscribed('Rome', email));
// verify that removing an already-removed subscriber is a noop
stream_data.remove_subscriber('Rome', email);
assert(!stream_data.user_is_subscribed('Rome', email));
// Verify that we noop and don't crash when unsubsribed.
sub.subscribed = false;
stream_data.add_subscriber('Rome', email);
assert.equal(stream_data.user_is_subscribed('Rome', email), undefined);
stream_data.remove_subscriber('Rome', email);
assert.equal(stream_data.user_is_subscribed('Rome', email), undefined);
}());