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 post(self, url, json): 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_trigger_sync_operations(mock_api_client): # Simulate a successful sync trigger response mock_api_client.responses = [ {"success": True, "sync_job_id": "sync123", "status": "initiated"} ] with patch('src.api_client.client', new=mock_api_client): # Simulate CLI's call to trigger a sync operation sync_payload = { "sync_type": "activities", "date_range_start": "2023-01-01", "date_range_end": "2023-01-31", "full_sync": False } resp = await mock_api_client.post("/api/garmin/sync/trigger", json=sync_payload) assert resp["success"] == True assert resp["sync_job_id"] == "sync123" assert resp["status"] == "initiated" assert mock_api_client.call_count == 1 @pytest.mark.asyncio async def test_trigger_sync_operations_failure(mock_api_client): # Simulate a failed sync trigger response mock_api_client.responses = [ {"success": False, "error": "Authentication required"} ] with patch('src.api_client.client', new=mock_api_client): sync_payload = { "sync_type": "activities", "full_sync": True } resp = await mock_api_client.post("/api/garmin/sync/trigger", json=sync_payload) assert resp["success"] == False assert resp["error"] == "Authentication required" assert mock_api_client.call_count == 1