From 5eaeddea12539c6e7f54a054a1ff9c094067ad44 Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Thu, 12 Sep 2013 10:55:56 -0400 Subject: [PATCH] Get stream_data.js back to 100% coverage (imported from commit 5b82a10d50b6599c0c42604fe86275b21f9a6396) --- zerver/tests/frontend/node/stream_data.js | 36 +++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/zerver/tests/frontend/node/stream_data.js b/zerver/tests/frontend/node/stream_data.js index 883dadeada..357a7c8ce8 100644 --- a/zerver/tests/frontend/node/stream_data.js +++ b/zerver/tests/frontend/node/stream_data.js @@ -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); + +}());