Files
FitTrack_GarminSync/cli/tests/integration/test_integration_sync_operations.py
sstent 2f0b5e6bad feat: Implement MFA authentication flow with garth for CLI
This commit implements the multi-factor authentication (MFA) flow for the CLI
using the garth library, as specified in task 007.

Changes include:
- Created  to handle API communication with robust error handling.
- Refactored  to correctly implement the logout logic
  and ensure proper handling of API client headers.
- Updated  with Black, Flake8, Mypy, and Isort configurations.
- Implemented and refined integration tests for authentication, sync operations,
  and sync status checking, including mocking for the API client.
- Renamed integration test files for clarity and consistency.
- Updated  to reflect task completion.
2025-12-20 14:46:50 -08:00

59 lines
1.9 KiB
Python

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