2016-06-08 05:54:07 +02:00
|
|
|
add_dependencies({
|
|
|
|
util: 'js/util.js'
|
|
|
|
});
|
|
|
|
|
2014-02-27 18:27:31 +01:00
|
|
|
var _ = global._;
|
|
|
|
|
2014-03-12 19:31:58 +01:00
|
|
|
set_global('$', function (f) {
|
|
|
|
if (f) {
|
|
|
|
return f();
|
|
|
|
}
|
2014-02-27 18:27:31 +01:00
|
|
|
return {trigger: function () {}};
|
|
|
|
});
|
|
|
|
set_global('document', null);
|
|
|
|
|
|
|
|
var page_params = {
|
2014-03-12 19:31:58 +01:00
|
|
|
bot_list: [{email: 'bot0@zulip.com', full_name: 'Bot 0'}],
|
2014-02-27 18:27:31 +01:00
|
|
|
is_admin: false,
|
|
|
|
email: 'owner@zulip.com'
|
|
|
|
};
|
|
|
|
set_global('page_params', page_params);
|
|
|
|
|
|
|
|
var patched_underscore = _.clone(_);
|
2016-12-01 20:02:56 +01:00
|
|
|
patched_underscore.debounce = function (f) { return f; };
|
2014-02-27 18:27:31 +01:00
|
|
|
global.patch_builtin('_', patched_underscore);
|
|
|
|
|
2014-02-27 00:01:18 +01:00
|
|
|
|
|
|
|
var bot_data = require('js/bot_data.js');
|
|
|
|
|
2014-03-12 19:31:58 +01:00
|
|
|
// Our startup logic should have added Bot 0 from page_params.
|
|
|
|
assert.equal(bot_data.get('bot0@zulip.com').full_name, 'Bot 0');
|
|
|
|
|
2014-02-27 00:01:18 +01:00
|
|
|
(function () {
|
|
|
|
var test_bot = {
|
|
|
|
email: 'bot1@zulip.com',
|
|
|
|
avatar_url: '',
|
|
|
|
default_all_public_streams: '',
|
|
|
|
default_events_register_stream: '',
|
|
|
|
default_sending_stream: '',
|
|
|
|
full_name: 'Bot 1',
|
|
|
|
extra: 'Not in data'
|
|
|
|
};
|
|
|
|
|
|
|
|
(function test_add() {
|
|
|
|
bot_data.add(test_bot);
|
|
|
|
|
|
|
|
var bot = bot_data.get('bot1@zulip.com');
|
|
|
|
assert.equal('Bot 1', bot.full_name);
|
|
|
|
assert.equal(undefined, bot.extra);
|
|
|
|
}());
|
|
|
|
|
|
|
|
(function test_update() {
|
|
|
|
var bot;
|
|
|
|
|
|
|
|
bot_data.add(test_bot);
|
|
|
|
|
|
|
|
bot = bot_data.get('bot1@zulip.com');
|
|
|
|
assert.equal('Bot 1', bot.full_name);
|
|
|
|
bot_data.update('bot1@zulip.com', {full_name: 'New Bot 1'});
|
|
|
|
bot = bot_data.get('bot1@zulip.com');
|
|
|
|
assert.equal('New Bot 1', bot.full_name);
|
|
|
|
}());
|
|
|
|
|
|
|
|
(function test_remove() {
|
|
|
|
var bot;
|
|
|
|
|
|
|
|
bot_data.add(test_bot);
|
|
|
|
|
|
|
|
bot = bot_data.get('bot1@zulip.com');
|
|
|
|
assert.equal('Bot 1', bot.full_name);
|
|
|
|
bot_data.remove('bot1@zulip.com');
|
|
|
|
bot = bot_data.get('bot1@zulip.com');
|
|
|
|
assert.equal(undefined, bot);
|
|
|
|
}());
|
|
|
|
|
2014-02-27 18:27:31 +01:00
|
|
|
(function test_owner_can_admin() {
|
|
|
|
var bot;
|
|
|
|
|
|
|
|
bot_data.add(_.extend({owner: 'owner@zulip.com'}, test_bot));
|
|
|
|
|
|
|
|
bot = bot_data.get('bot1@zulip.com');
|
|
|
|
assert(bot.can_admin);
|
|
|
|
|
|
|
|
bot_data.add(_.extend({owner: 'notowner@zulip.com'}, test_bot));
|
|
|
|
|
|
|
|
bot = bot_data.get('bot1@zulip.com');
|
|
|
|
assert.equal(false, bot.can_admin);
|
|
|
|
}());
|
|
|
|
|
|
|
|
(function test_admin_can_admin() {
|
|
|
|
var bot;
|
|
|
|
page_params.is_admin = true;
|
|
|
|
|
|
|
|
bot_data.add(test_bot);
|
|
|
|
|
|
|
|
bot = bot_data.get('bot1@zulip.com');
|
|
|
|
assert(bot.can_admin);
|
|
|
|
|
|
|
|
page_params.is_admin = false;
|
|
|
|
}());
|
|
|
|
|
|
|
|
(function test_get_editable() {
|
|
|
|
var can_admin;
|
|
|
|
|
|
|
|
bot_data.add(_.extend({}, test_bot, {owner: 'owner@zulip.com'}));
|
|
|
|
bot_data.add(_.extend({}, test_bot, {email: 'bot2@zulip.com'}));
|
|
|
|
|
|
|
|
can_admin = _.pluck(bot_data.get_editable(), 'email');
|
|
|
|
assert.deepEqual(['bot1@zulip.com'], can_admin);
|
|
|
|
}());
|
|
|
|
|
|
|
|
|
2014-02-27 00:01:18 +01:00
|
|
|
}());
|