120 lines
3.7 KiB
Python
120 lines
3.7 KiB
Python
"""
|
|
Unit Tests for ClaimService
|
|
Generated test cases for service layer
|
|
"""
|
|
import pytest
|
|
from unittest.mock import Mock, patch
|
|
from src.services._service import ClaimService
|
|
from src.errors.error import NotFoundError, ValidationError
|
|
|
|
@pytest.fixture
|
|
def service():
|
|
return ClaimService()
|
|
|
|
@pytest.fixture
|
|
def mock_model():
|
|
return Mock()
|
|
|
|
class TestClaimService:
|
|
def test_create_success(self, service, mock_model):
|
|
"""Test successful creation of """
|
|
data = {
|
|
"id": True,
|
|
"claim_number": "testclaim_number",
|
|
"patient_id": True,
|
|
"audio_recording_id": True,
|
|
"transcript_id": True,
|
|
"payer_id": True,
|
|
"encounter_id": "testencounter_id",
|
|
"service_date": True,
|
|
"created_by_user_id": True,
|
|
"status": True,
|
|
"claim_type": True,
|
|
"diagnosis_codes": True,
|
|
"procedure_codes": True,
|
|
"modifiers": True,
|
|
"mdm_level": True,
|
|
"medical_necessity_justification": True,
|
|
"total_charge_amount": True,
|
|
"expected_reimbursement": True,
|
|
"actual_reimbursement": True,
|
|
"scrubbing_status": True,
|
|
"scrubbing_results": True,
|
|
"scrubbing_failures": True,
|
|
"corrective_actions": True,
|
|
"confidence_score": True,
|
|
"is_template_based": True,
|
|
"template_id": True,
|
|
"reviewed_by_user_id": True,
|
|
"reviewed_at": True,
|
|
"submitted_at": True,
|
|
"paid_at": True,
|
|
"denial_reason": True,
|
|
"denial_code": "testdenial_code",
|
|
"notes": True,
|
|
"": True,
|
|
"": True,
|
|
}
|
|
created = {**data, "id": 1}
|
|
|
|
with patch('src.services._service.ClaimModel') 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.ClaimModel') 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.ClaimModel') 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.ClaimModel') 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.ClaimModel') as mock:
|
|
mock.get.return_value = {"id": id}
|
|
mock.delete.return_value = True
|
|
service.delete(id)
|
|
|
|
mock.delete.assert_called_once_with(id)
|
|
|