"""Tests para list_registered_obsidian_vaults."""

import json

from list_registered_obsidian_vaults import list_registered_obsidian_vaults


def test_lista_vaults_registrados_ordenados_por_path(tmp_path):
    # Golden path: dos vaults registrados se devuelven ordenados por path.
    cfg = str(tmp_path / "obsidian.json")
    with open(cfg, "w", encoding="utf-8") as f:
        json.dump(
            {
                "extra": "preservar",
                "vaults": {
                    "aaaaaaaaaaaaaaaa": {"path": "/z/Zeta", "ts": 200, "open": True},
                    "bbbbbbbbbbbbbbbb": {"path": "/a/Alpha", "ts": 100, "open": False},
                },
            },
            f,
        )

    rows = list_registered_obsidian_vaults(config_path=cfg)
    assert len(rows) == 2
    assert [r["path"] for r in rows] == ["/a/Alpha", "/z/Zeta"]

    alpha = rows[0]
    assert alpha["id"] == "bbbbbbbbbbbbbbbb"
    assert alpha["open"] is False
    assert alpha["ts"] == 100


def test_config_inexistente_devuelve_lista_vacia(tmp_path):
    # Edge: archivo de config ausente -> lista vacia, sin excepcion.
    cfg = str(tmp_path / "no_existe.json")
    assert list_registered_obsidian_vaults(config_path=cfg) == []
