<commit_before>var _ = global._;

set_global('$', function () {
    return {trigger: function () {}};
});
set_global('document', null);

var page_params = {
    is_admin: false,
    email: '<EMAIL>'
};
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>',
        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>');
        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>');
        assert.equal('Bot 1', bot.full_name);
        bot_data.update('<EMAIL>', {full_name: 'New Bot 1'});
        bot = bot_data.get('<EMAIL>');
        assert.equal('New Bot 1', bot.full_name);
    }());

    (function test_remove() {
        var bot;

        bot_data.add(test_bot);

        bot = bot_data.get('<EMAIL>');
        assert.equal('Bot 1', bot.full_name);
        bot_data.remove('<EMAIL>');
        bot = bot_data.get('<EMAIL>');
        assert.equal(undefined, bot);
    }());

    (function test_owner_can_admin() {
        var bot;

        bot_data.add(_.extend({owner: '<EMAIL>'}, test_bot));

        bot = bot_data.get('<EMAIL>');
        assert(bot.can_admin);

        bot_data.add(_.extend({owner: '<EMAIL>'}, test_bot));

        bot = bot_data.get('<EMAIL>');
        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>');
        assert(bot.can_admin);

        page_params.is_admin = false;
    }());

    (function test_get_editable() {
        var can_admin;

        bot_data.add(_.extend({}, test_bot, {owner: '<EMAIL>'}));
        bot_data.add(_.extend({}, test_bot, {email: '<EMAIL>'}));

        can_admin = _.pluck(bot_data.get_editable(), 'email');
        assert.deepEqual(['<EMAIL>'], can_admin);
    }());


}());
<commit_msg>Test startup logic in bot_data.js<commit_after>var _ = global._;

set_global('$', function (f) {
    if (f) {
        return f();
    }
    return {trigger: function () {}};
});
set_global('document', null);

var page_params = {
    bot_list: [{email: '<EMAIL>', full_name: 'Bot 0'}],
    is_admin: false,
    email: '<EMAIL>'
};
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');

// Our startup logic should have added Bot 0 from page_params.
assert.equal(bot_data.get('bot<EMAIL>').full_name, 'Bot 0');

(function () {
    var test_bot = {
        email: '<EMAIL>',
        avatar_url: '',
        default_all_public_streams: '',
        default_events_register_stream: '',
        default_sending_stream: '',
        full_name: '<NAME>',
        extra: 'Not in data'
    };

    (function test_add() {
        bot_data.add(test_bot);

        var bot = bot_data.get('<EMAIL>');
        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>');
        assert.equal('Bot 1', bot.full_name);
        bot_data.update('<EMAIL>', {full_name: 'New Bot 1'});
        bot = bot_data.get('<EMAIL>');
        assert.equal('New Bot 1', bot.full_name);
    }());

    (function test_remove() {
        var bot;

        bot_data.add(test_bot);

        bot = bot_data.get('<EMAIL>');
        assert.equal('Bot 1', bot.full_name);
        bot_data.remove('<EMAIL>');
        bot = bot_data.get('<EMAIL>');
        assert.equal(undefined, bot);
    }());

    (function test_owner_can_admin() {
        var bot;

        bot_data.add(_.extend({owner: '<EMAIL>'}, test_bot));

        bot = bot_data.get('<EMAIL>');
        assert(bot.can_admin);

        bot_data.add(_.extend({owner: '<EMAIL>'}, test_bot));

        bot = bot_data.get('<EMAIL>');
        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>');
        assert(bot.can_admin);

        page_params.is_admin = false;
    }());

    (function test_get_editable() {
        var can_admin;

        bot_data.add(_.extend({}, test_bot, {owner: '<EMAIL>'}));
        bot_data.add(_.extend({}, test_bot, {email: '<EMAIL>'}));

        can_admin = _.pluck(bot_data.get_editable(), 'email');
        assert.deepEqual(['<EMAIL>'], can_admin);
    }());


}());

{'fraction_non_alphanumeric': 0.17908420644159875, 'fraction_numerical': 0.002716336825766395, 'mean_word_length': 2.661221590909091, 'pattern_counts': {'":': 0, '<': 40, '<?xml version=': 0, '>': 40, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6525807', 'n_tokens_mistral': 1804, 'n_tokens_neox': 1745, 'n_words': 303}