""" Unit Tests for EMRIntegrationService Generated test cases for service layer """ import pytest from unittest.mock import Mock, patch from src.services._service import EMRIntegrationService from src.errors.error import NotFoundError, ValidationError @pytest.fixture def service(): return EMRIntegrationService() @pytest.fixture def mock_model(): return Mock() class TestEMRIntegrationService: def test_create_success(self, service, mock_model): """Test successful creation of """ data = { "id": True, "organization_id": True, "emr_system": "testemr_system", "emr_version": "testemr_version", "integration_type": "testintegration_type", "fhir_base_url": "testfhir_base_url", "api_endpoint": "testapi_endpoint", "auth_type": "testauth_type", "client_id": "testclient_id", "client_secret_encrypted": True, "api_key_encrypted": True, "token_url": "testtoken_url", "scopes": True, "connection_status": "testconnection_status", "approval_status": "testapproval_status", "approval_date": True, "epic_approval_months_estimate": True, "data_mappings": True, "supported_resources": True, "sync_frequency_minutes": True, "last_sync_at": True, "last_sync_status": "testlast_sync_status", "last_error_message": True, "retry_count": True, "max_retries": True, "timeout_seconds": True, "rate_limit_per_minute": True, "use_mock_data": True, "configuration_notes": True, "created_by_id": True, "": True, "": True, } created = {**data, "id": 1} with patch('src.services._service.EMRIntegrationModel') as mock: mock.create.return_value = created result = service.create(data) assert result == created mock.create.assert_called_once_with(data) def test_create_validation_error(self, service): """Test validation error on invalid data""" invalid_data = {} with pytest.raises(ValidationError): service.create(invalid_data) def test_find_by_id_success(self, service, mock_model): """Test successful retrieval by id""" id = 1 found = {"id": id, "name": "Test"} with patch('src.services._service.EMRIntegrationModel') as mock: mock.get.return_value = found result = service.find_by_id(id) assert result == found mock.get.assert_called_once_with(id) def test_find_by_id_not_found(self, service): """Test NotFoundError when not found""" id = 999 with patch('src.services._service.EMRIntegrationModel') as mock: mock.get.return_value = None with pytest.raises(NotFoundError): service.find_by_id(id) def test_update_success(self, service): """Test successful update""" id = 1 update_data = {"name": "Updated"} updated = {"id": id, **update_data} with patch('src.services._service.EMRIntegrationModel') as mock: mock.get.return_value = {"id": id} mock.update.return_value = updated result = service.update(id, update_data) assert result == updated def test_delete_success(self, service): """Test successful deletion""" id = 1 with patch('src.services._service.EMRIntegrationModel') as mock: mock.get.return_value = {"id": id} mock.delete.return_value = True service.delete(id) mock.delete.assert_called_once_with(id)