import pytest from unittest.mock import AsyncMock, patch # Assuming an API client similar to the authentication tests class MockApiClient: def __init__(self): self.responses = [] self.call_count = 0 async def get(self, url, params=None): self.call_count += 1 if self.responses: return self.responses.pop(0) return {"success": False, "error": "No mock response set"} @pytest.fixture def mock_api_client(): return MockApiClient() @pytest.mark.asyncio async def test_check_sync_status_success(mock_api_client): # Simulate a successful sync status response mock_api_client.responses = [ {"success": True, "status": "completed", "progress": 100, "job_id": "sync123", "message": "Sync completed successfully"} ] with patch('src.api_client.client', new=mock_api_client): # Simulate CLI's call to check sync status resp = await mock_api_client.get("/api/garmin/sync/status", params={"job_id": "sync123"}) assert resp["success"] == True assert resp["status"] == "completed" assert resp["job_id"] == "sync123" assert mock_api_client.call_count == 1 @pytest.mark.asyncio async def test_check_sync_status_in_progress(mock_api_client): # Simulate a sync status response for an in-progress job mock_api_client.responses = [ {"success": True, "status": "in_progress", "progress": 50, "job_id": "sync456", "message": "Downloading activities"} ] with patch('src.api_client.client', new=mock_api_client): resp = await mock_api_client.get("/api/garmin/sync/status", params={"job_id": "sync456"}) assert resp["success"] == True assert resp["status"] == "in_progress" assert resp["progress"] == 50 assert resp["job_id"] == "sync456" assert mock_api_client.call_count == 1 @pytest.mark.asyncio async def test_check_sync_status_not_found(mock_api_client): # Simulate a sync status response for a non-existent job mock_api_client.responses = [ {"success": False, "error": "Sync job not found", "job_id": "nonexistent"} ] with patch('src.api_client.client', new=mock_api_client): resp = await mock_api_client.get("/api/garmin/sync/status", params={"job_id": "nonexistent"}) assert resp["success"] == False assert resp["error"] == "Sync job not found" assert mock_api_client.call_count == 1