"""Permission definition tests."""
from app.permissions.definitions import ALL_PERMISSIONS, PERMISSION_PREFIXES


def test_all_permissions_use_crm_prefix():
    for perm in ALL_PERMISSIONS:
        assert perm.startswith("crm."), perm


def test_required_permission_trees_present():
    trees = [
        "crm.leads.",
        "crm.contacts.",
        "crm.organizations.",
        "crm.opportunities.",
        "crm.pipelines.",
        "crm.playbooks.",
        "crm.forecasts.",
        "crm.goals.",
        "crm.targets.",
        "crm.activities.",
        "crm.tasks.",
        "crm.meetings.",
        "crm.calls.",
        "crm.timeline.",
        "crm.comments.",
        "crm.mentions.",
        "crm.team.",
        "crm.quotes.",
        "crm.notes.",
        "crm.attachments.",
        "crm.customfields.",
    ]
    for tree in trees:
        assert any(p.startswith(tree) for p in ALL_PERMISSIONS), tree


def test_permission_prefixes_documented():
    assert "crm." in PERMISSION_PREFIXES
    assert "crm.leads." in PERMISSION_PREFIXES
    assert "crm.quotes." in PERMISSION_PREFIXES
    assert "crm.notes." in PERMISSION_PREFIXES
    assert "crm.customfields." in PERMISSION_PREFIXES
    assert "crm.pipelines." in PERMISSION_PREFIXES
    assert "crm.playbooks." in PERMISSION_PREFIXES
    assert "crm.forecasts." in PERMISSION_PREFIXES
    assert "crm.goals." in PERMISSION_PREFIXES
    assert "crm.targets." in PERMISSION_PREFIXES
    assert "crm.tasks." in PERMISSION_PREFIXES
    assert "crm.meetings." in PERMISSION_PREFIXES
    assert "crm.calls." in PERMISSION_PREFIXES
    assert "crm.timeline." in PERMISSION_PREFIXES
    assert "crm.comments." in PERMISSION_PREFIXES
    assert "crm.mentions." in PERMISSION_PREFIXES
    assert "crm.team." in PERMISSION_PREFIXES
