def test_api_instances_on_window(default_log_settings):
    shortcut_input = "window.navigator"
    expected_output = {
        "object": "window.navigator",
        "instrumentedName": "window.navigator",
        "logSettings": default_log_settings,
    }
    actual_output = jsi._build_full_settings_object(shortcut_input)
    assert actual_output == expected_output
def test_api_whole_module(default_log_settings):
    shortcut_input = "XMLHttpRequest"
    expected_output = {
        "object": "window['XMLHttpRequest'].prototype",
        "instrumentedName": "XMLHttpRequest",
        "logSettings": default_log_settings,
    }
    actual_output = jsi._build_full_settings_object(shortcut_input)
    assert actual_output == expected_output
def test_api_module_specific_properties(default_log_settings):
    log_settings = default_log_settings.copy()
    log_settings["propertiesToInstrument"] = ["send"]
    shortcut_input = {"XMLHttpRequest": ["send"]}
    expected_output = {
        "object": "window['XMLHttpRequest'].prototype",
        "instrumentedName": "XMLHttpRequest",
        "logSettings": log_settings,
    }
    actual_output = jsi._build_full_settings_object(shortcut_input)
    assert actual_output == expected_output
def test_api_instances_on_window_with_properties(default_log_settings):
    log_settings = default_log_settings.copy()
    log_settings["propertiesToInstrument"] = ["name", "localStorage"]
    shortcut_input = {"window": ["name", "localStorage"]}
    expected_output = {
        "object": "window",
        "instrumentedName": "window",
        "logSettings": log_settings,
    }
    actual_output = jsi._build_full_settings_object(shortcut_input)
    assert actual_output == expected_output
def test_api_passing_partial_log_settings(default_log_settings):
    log_settings = default_log_settings.copy()
    log_settings["excludedProperties"] = ["send"]
    log_settings["recursive"] = True
    log_settings["depth"] = 2
    shortcut_input = {
        "XMLHttpRequest": {
            "excludedProperties": ["send"],
            "recursive": True,
            "depth": 2,
        }
    }
    expected_output = {
        "object": "window['XMLHttpRequest'].prototype",
        "instrumentedName": "XMLHttpRequest",
        "logSettings": log_settings,
    }
    actual_output = jsi._build_full_settings_object(shortcut_input)
    assert actual_output == expected_output
def test_api_two_keys_in_shortcut():
    shortcut_input = {"k1": [], "k2": []}
    with pytest.raises(ValueError):
        jsi._build_full_settings_object(shortcut_input)