<commit_before>"use strict";

const {strict: assert} = require("assert");

const {mock_esm, set_global, zrequire} = require("../zjsunit/namespace");
const {run_test} = require("../zjsunit/test");
const $ = require("../zjsunit/zjquery");

const page_params = set_global("page_params", {
    realm_uri: "https://chat.example.com",
    realm_embedded_bots: [
        {name: "converter", config: {}},
        {name: "giphy", config: {key: "12345678"}},
        {name: "foobot", config: {bar: "baz", qux: "quux"}},
    ],
});

const bot_data_params = {
    realm_bots: [
        {
            api_key: "QadL788EkiottHmukyhHgePUFHREiu8b",
            email: "<EMAIL>",
            full_name: "<NAME>",
            user_id: 1,
            services: [],
        },
    ],
};

const avatar = mock_esm("../../static/js/avatar");
function ClipboardJS(sel) {
    assert.equal(sel, "#copy_zuliprc");
}

const bot_data = zrequire("bot_data");
const settings_bots = zrequire("settings_bots");
settings_bots.__Rewire__("ClipboardJS", ClipboardJS);

bot_data.initialize(bot_data_params);

run_test("generate_zuliprc_uri", () => {
    const uri = settings_bots.generate_zuliprc_uri(1);
    const expected =
        "data:application/octet-stream;charset=utf-8," +
        encodeURIComponent(
            "[api]\nemail=<EMAIL>\n" +
                "key=QadL788EkiottHmukyhHgePUFHREiu8b\n" +
                "site=https://chat.example.com\n",
        );

    assert.equal(uri, expected);
});

run_test("generate_zuliprc_content", () => {
    const bot_user = bot_data.get(1);
    const content = settings_bots.generate_zuliprc_content(bot_user);
    const expected =<commit_msg>node_tests: Mock clipboard to avoid __Rewire__.<commit_after>"use strict";

const {strict: assert} = require("assert");

const {mock_cjs, mock_esm, set_global, zrequire} = require("../zjsunit/namespace");
const {run_test} = require("../zjsunit/test");
const $ = require("../zjsunit/zjquery");

const page_params = set_global("page_params", {
    realm_uri: "https://chat.example.com",
    realm_embedded_bots: [
        {name: "converter", config: {}},
        {name: "giphy", config: {key: "12345678"}},
        {name: "foobot", config: {bar: "baz", qux: "quux"}},
    ],
});

const bot_data_params = {
    realm_bots: [
        {
            api_key: "QadL788EkiottHmukyhHgePUFHREiu8b",
            email: "<EMAIL>",
            full_name: "Error bot",
            user_id: 1,
            services: [],
        },
    ],
};

const avatar = mock_esm("../../static/js/avatar");

function ClipboardJS(sel) {
    assert.equal(sel, "#copy_zuliprc");
}
mock_cjs("clipboard", ClipboardJS);

const bot_data = zrequire("bot_data");
const settings_bots = zrequire("settings_bots");

bot_data.initialize(bot_data_params);

run_test("generate_zuliprc_uri", () => {
    const uri = settings_bots.generate_zuliprc_uri(1);
    const expected =
        "data:application/octet-stream;charset=utf-8," +
        encodeURIComponent(
            "[api]\nemail=<EMAIL>\n" +
                "key=QadL788EkiottHmukyhHgePUFHREiu8b\n" +
                "site=https://chat.example.com\n",
        );

    assert.equal(uri, expected);
});

run_test("generate_zuliprc_content", () => {
    const bot_user = bot_data.get(1);
    const content = settings_bots.generate_zuliprc_content(bot_user);
    const expected =
{'fraction_non_alphanumeric': 0.16557083084279736, 'fraction_numerical': 0.011954572624028692, 'mean_word_length': 3.1994981179422837, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 12, 'https://': 4, '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': '4543378', 'n_tokens_mistral': 1223, 'n_tokens_neox': 1194, 'n_words': 181}