"""Guard: broadcast receivers are scoped to active app mappings (see create_message)."""
import unittest
from pathlib import Path


class TestBroadcastScopeSource(unittest.TestCase):
    def test_create_message_broadcast_joins_mapping(self):
        root = Path(__file__).resolve().parent.parent
        path = root / "app" / "api" / "v1" / "endpoints" / "messages.py"
        text = path.read_text(encoding="utf-8")
        self.assertIn("is_broadcast", text)
        self.assertIn("join(AppUserMapping", text)
        self.assertIn("AppUserMapping.is_active", text)
        self.assertIn(".distinct()", text)


if __name__ == "__main__":
    unittest.main()
