mirror of
https://github.com/zulip/zulip.git
synced 2026-06-24 21:08:25 +08:00
We had never-enabled code to allow users to set default streams for their bots (for event registration, default sending, etc.). This commit removes the code.
126 lines
3.2 KiB
JavaScript
126 lines
3.2 KiB
JavaScript
global.stub_out_jquery();
|
|
|
|
add_dependencies({
|
|
people: 'js/people.js',
|
|
});
|
|
|
|
var _ = global._;
|
|
|
|
set_global('$', function (f) {
|
|
if (f) {
|
|
return f();
|
|
}
|
|
return {trigger: function () {}};
|
|
});
|
|
set_global('document', null);
|
|
|
|
var page_params = {
|
|
bot_list: [{email: '[email protected]', full_name: 'Bot 0'}],
|
|
is_admin: false,
|
|
};
|
|
set_global('page_params', page_params);
|
|
|
|
global.people.add({
|
|
email: '[email protected]',
|
|
full_name: 'The Human Boss',
|
|
user_id: 42,
|
|
});
|
|
|
|
global.people.initialize_current_user(42);
|
|
|
|
var patched_underscore = _.clone(_);
|
|
patched_underscore.debounce = function (f) { return f; };
|
|
global.patch_builtin('_', patched_underscore);
|
|
|
|
|
|
var bot_data = require('js/bot_data.js');
|
|
|
|
// Our startup logic should have added Bot 0 from page_params.
|
|
assert.equal(bot_data.get('[email protected]').full_name, 'Bot 0');
|
|
|
|
(function () {
|
|
var test_bot = {
|
|
email: '[email protected]',
|
|
avatar_url: '',
|
|
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(_.extend({}, test_bot, {is_active: true}));
|
|
|
|
bot = bot_data.get('[email protected]');
|
|
assert.equal('Bot 1', bot.full_name);
|
|
assert(bot.is_active);
|
|
bot_data.deactivate('[email protected]');
|
|
bot = bot_data.get('[email protected]');
|
|
assert.equal(bot.is_active, false);
|
|
}());
|
|
|
|
(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]', is_active: true}));
|
|
bot_data.add(_.extend({}, test_bot, {email: '[email protected]', owner: '[email protected]', is_active: true}));
|
|
bot_data.add(_.extend({}, test_bot, {email: '[email protected]', owner: '[email protected]', is_active: true}));
|
|
|
|
can_admin = _.pluck(bot_data.get_editable(), 'email');
|
|
assert.deepEqual(['[email protected]', '[email protected]'], can_admin);
|
|
|
|
page_params.is_admin = true;
|
|
|
|
can_admin = _.pluck(bot_data.get_editable(), 'email');
|
|
assert.deepEqual(['[email protected]', '[email protected]'], can_admin);
|
|
}());
|
|
|
|
|
|
}());
|