"""Unit tests for profile_overrides persistence."""

import pytest

from navi.profiles._overrides import ensure_table, load_overrides, save_override


class TestProfileOverrides:
    async def test_ensure_table_creates_table(self, fake_pool):
        await ensure_table(fake_pool)
        assert any("profile_overrides" in c[1] for c in fake_pool._conn.calls)

    async def test_save_and_load_override(self, fake_pool):
        await ensure_table(fake_pool)
        fake_pool._conn.enqueue("INSERT 0 1")
        await save_override(fake_pool, "secretary", True)

        fake_pool._conn.enqueue([{"profile_id": "secretary", "is_admin_only": True}])
        overrides = await load_overrides(fake_pool)
        assert overrides == {"secretary": True}

    async def test_load_overrides_empty(self, fake_pool):
        await ensure_table(fake_pool)
        fake_pool._conn.enqueue([])
        overrides = await load_overrides(fake_pool)
        assert overrides == {}
