zulip/zerver/tests/frontend/node/bot_data.js
Jason Michalski fa37e91e5c Add admin status to bot_data
(imported from commit 47b84b3ef1e97e355dee84f0595e94a4612bf4df)
2014-03-05 14:16:20 -05:00

102 lines
2.5 KiB
JavaScript

var _ = global._;
set_global('$', function () {
return {trigger: function () {}};
});
set_global('document', null);
var page_params = {
is_admin: false,
email: '[email protected]'
};
set_global('page_params', page_params);
var patched_underscore = _.clone(_);
patched_underscore.debounce = function (f) { return(f); };
global.patch_builtin('_', patched_underscore);
var bot_data = require('js/bot_data.js');
(function () {
var test_bot = {
email: '[email protected]',
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('[email protected]');
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('[email protected]');
assert.equal('Bot 1', bot.full_name);
bot_data.update('[email protected]', {full_name: 'New Bot 1'});
bot = bot_data.get('[email protected]');
assert.equal('New Bot 1', bot.full_name);
}());
(function test_remove() {
var bot;
bot_data.add(test_bot);
bot = bot_data.get('[email protected]');
assert.equal('Bot 1', bot.full_name);
bot_data.remove('[email protected]');
bot = bot_data.get('[email protected]');
assert.equal(undefined, bot);
}());
(function test_owner_can_admin() {
var bot;
bot_data.add(_.extend({owner: '[email protected]'}, test_bot));
bot = bot_data.get('[email protected]');
assert(bot.can_admin);
bot_data.add(_.extend({owner: '[email protected]'}, test_bot));
bot = bot_data.get('[email protected]');
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('[email protected]');
assert(bot.can_admin);
page_params.is_admin = false;
}());
(function test_get_editable() {
var can_admin;
bot_data.add(_.extend({}, test_bot, {owner: '[email protected]'}));
bot_data.add(_.extend({}, test_bot, {email: '[email protected]'}));
can_admin = _.pluck(bot_data.get_editable(), 'email');
assert.deepEqual(['[email protected]'], can_admin);
}());
}());