"""Tests for the browser scrape executor.""" from unittest.mock import AsyncMock import pytest from cron.browser_executor import execute_browser_scrape class TestBrowserScrapeExecutor: @pytest.mark.asyncio async def test_returns_error_without_profile(self): job = { "id": "j1", "name": "FB Scan", "config": {"url": "https://facebook.com/marketplace"}, "targetRoom": "!room:test", "browserProfile": None, } send_text = AsyncMock() result = await execute_browser_scrape(job=job, send_text=send_text) assert result["status"] == "error" assert "browser profile" in result["error"].lower() send_text.assert_called_once() msg = send_text.call_args[0][1] assert "matrixhost.eu/settings/automations" in msg @pytest.mark.asyncio async def test_returns_error_with_expired_profile(self): job = { "id": "j1", "name": "FB Scan", "config": {"url": "https://facebook.com/marketplace"}, "targetRoom": "!room:test", "browserProfile": {"id": "b1", "status": "expired", "name": "facebook"}, } send_text = AsyncMock() result = await execute_browser_scrape(job=job, send_text=send_text) assert result["status"] == "error" assert "expired" in result["error"].lower() send_text.assert_called_once() msg = send_text.call_args[0][1] assert "re-record" in msg.lower() @pytest.mark.asyncio async def test_placeholder_with_active_profile(self): job = { "id": "j1", "name": "FB Scan", "config": {"url": "https://facebook.com/marketplace"}, "targetRoom": "!room:test", "browserProfile": {"id": "b1", "status": "active", "name": "facebook"}, } send_text = AsyncMock() result = await execute_browser_scrape(job=job, send_text=send_text) # Currently a placeholder, should indicate not yet implemented assert result["status"] == "error" assert "not yet implemented" in result["error"].lower()