2013-08-21 20:27:14 +02:00
|
|
|
add_dependencies({
|
2013-08-23 05:32:38 +02:00
|
|
|
stream_color: 'js/stream_color.js'
|
2013-08-21 20:27:14 +02:00
|
|
|
});
|
|
|
|
|
2013-09-16 16:56:46 +02:00
|
|
|
set_global('blueslip', {});
|
|
|
|
|
2013-08-19 18:46:21 +02:00
|
|
|
var stream_data = require('js/stream_data.js');
|
|
|
|
|
|
|
|
(function test_basics() {
|
|
|
|
var denmark = {
|
|
|
|
subscribed: false,
|
|
|
|
color: 'blue',
|
|
|
|
name: 'Denmark',
|
2014-02-05 20:35:16 +01:00
|
|
|
stream_id: 1,
|
2013-08-19 18:46:21 +02:00
|
|
|
in_home_view: false
|
|
|
|
};
|
|
|
|
var social = {
|
|
|
|
subscribed: true,
|
|
|
|
color: 'red',
|
|
|
|
name: 'social',
|
2014-02-05 20:35:16 +01:00
|
|
|
stream_id: 2,
|
2013-08-19 18:46:21 +02:00
|
|
|
in_home_view: true,
|
|
|
|
invite_only: true
|
|
|
|
};
|
|
|
|
stream_data.add_sub('Denmark', denmark);
|
|
|
|
stream_data.add_sub('social', social);
|
|
|
|
|
|
|
|
assert.equal(stream_data.get_sub('denmark'), denmark);
|
|
|
|
assert.equal(stream_data.get_sub('Social'), social);
|
|
|
|
|
|
|
|
assert.deepEqual(stream_data.subscribed_streams(), ['social']);
|
|
|
|
assert.deepEqual(stream_data.get_colors(), ['red']);
|
|
|
|
|
|
|
|
assert(stream_data.all_subscribed_streams_are_in_home_view());
|
|
|
|
|
|
|
|
assert(stream_data.is_subscribed('social'));
|
|
|
|
assert(stream_data.is_subscribed('Social'));
|
|
|
|
assert(!stream_data.is_subscribed('Denmark'));
|
|
|
|
assert(!stream_data.is_subscribed('Rome'));
|
|
|
|
|
|
|
|
assert(stream_data.get_invite_only('social'));
|
2013-08-23 05:34:59 +02:00
|
|
|
assert(!stream_data.get_invite_only('unknown'));
|
2013-08-19 18:46:21 +02:00
|
|
|
assert.equal(stream_data.get_color('social'), 'red');
|
2013-08-23 05:32:38 +02:00
|
|
|
assert.equal(stream_data.get_color('unknown'), global.stream_color.default_color);
|
2013-08-19 19:25:44 +02:00
|
|
|
|
|
|
|
assert.equal(stream_data.get_name('denMARK'), 'Denmark');
|
|
|
|
assert.equal(stream_data.get_name('unknown Stream'), 'unknown Stream');
|
2013-08-23 05:36:49 +02:00
|
|
|
|
|
|
|
assert(stream_data.in_home_view('social'));
|
|
|
|
assert(!stream_data.in_home_view('denmark'));
|
2013-08-28 16:22:15 +02:00
|
|
|
|
|
|
|
// Deleting a subscription makes you unsubscribed from the perspective of
|
|
|
|
// the client.
|
|
|
|
// Deleting a subscription is case-insensitive.
|
|
|
|
stream_data.delete_sub('SOCIAL');
|
|
|
|
assert(!stream_data.is_subscribed('social'));
|
2013-08-19 18:46:21 +02:00
|
|
|
}());
|
2013-08-23 05:29:41 +02:00
|
|
|
|
2014-02-05 20:35:16 +01:00
|
|
|
(function test_get_by_id() {
|
|
|
|
stream_data.clear_subscriptions();
|
|
|
|
var id = 42;
|
|
|
|
var sub = {
|
|
|
|
name: 'Denmark',
|
|
|
|
subscribed: true,
|
|
|
|
color: 'red',
|
|
|
|
stream_id: id
|
|
|
|
};
|
|
|
|
stream_data.add_sub('Denmark', sub);
|
|
|
|
sub = stream_data.get_sub('Denmark');
|
|
|
|
assert.equal(sub.color, 'red');
|
|
|
|
sub = stream_data.get_sub_by_id(id);
|
|
|
|
assert.equal(sub.color, 'red');
|
|
|
|
}());
|
|
|
|
|
2013-09-12 16:55:56 +02:00
|
|
|
(function test_subscribers() {
|
|
|
|
stream_data.clear_subscriptions();
|
2014-02-05 20:35:16 +01:00
|
|
|
var sub = {name: 'Rome', subscribed: true, stream_id: 1};
|
2013-09-12 16:55:56 +02:00
|
|
|
|
|
|
|
stream_data.add_sub('Rome', sub);
|
2013-09-16 22:26:53 +02:00
|
|
|
|
|
|
|
stream_data.set_subscribers(sub, ['fred@zulip.com', 'george@zulip.com']);
|
2013-09-16 23:40:57 +02:00
|
|
|
assert(stream_data.user_is_subscribed('Rome', 'FRED@zulip.com'));
|
2013-09-16 22:26:53 +02:00
|
|
|
assert(stream_data.user_is_subscribed('Rome', 'fred@zulip.com'));
|
|
|
|
assert(stream_data.user_is_subscribed('Rome', 'george@zulip.com'));
|
|
|
|
assert(!stream_data.user_is_subscribed('Rome', 'not_fred@zulip.com'));
|
|
|
|
|
|
|
|
stream_data.set_subscribers(sub, []);
|
|
|
|
|
2013-09-12 16:55:56 +02:00
|
|
|
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));
|
|
|
|
|
2013-10-15 19:08:35 +02:00
|
|
|
// Verify defensive code in set_subscribers, where the second parameter
|
|
|
|
// can be undefined.
|
|
|
|
stream_data.set_subscribers(sub);
|
|
|
|
stream_data.add_sub('Rome', sub);
|
|
|
|
stream_data.add_subscriber('Rome', email);
|
|
|
|
sub.subscribed = true;
|
|
|
|
assert(stream_data.user_is_subscribed('Rome', email));
|
|
|
|
|
2013-09-12 16:55:56 +02:00
|
|
|
// Verify that we noop and don't crash when unsubsribed.
|
|
|
|
sub.subscribed = false;
|
2013-09-24 00:13:02 +02:00
|
|
|
global.blueslip.warn = function () {};
|
2013-09-12 16:55:56 +02:00
|
|
|
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);
|
|
|
|
|
|
|
|
}());
|