"""Tests for write-lock command behavior."""

import json
from pathlib import Path

from accountable_record.commands.write_lock import (
    ELEMENT_LOCK_PATH,
    LOCK_ROOT,
    _write_json,
)


def test_write_json_writes_stable_json(tmp_path: Path) -> None:
    path = tmp_path / ELEMENT_LOCK_PATH
    path.parent.mkdir(parents=True)

    payload = {
        "schema": "ar-element-lock-1",
        "target_root": str(tmp_path),
        "elements": [],
    }

    _write_json(path, payload)

    assert path.is_file()
    assert path.read_text(encoding="utf-8").endswith("\n")
    assert json.loads(path.read_text(encoding="utf-8")) == payload


def test_lock_paths_are_expected() -> None:
    assert LOCK_ROOT.as_posix() == "data/locks"
    assert ELEMENT_LOCK_PATH.as_posix() == "data/locks/elements.lock.json"
