54 lines
2.0 KiB
Python
54 lines
2.0 KiB
Python
from datetime import datetime, timedelta, timezone
|
|
from decimal import Decimal
|
|
import unittest
|
|
|
|
from src.application.domain.entities.user import UserEntity
|
|
from src.application.services.risk_scoring import RiskScoringService
|
|
|
|
|
|
class RiskScoringServiceTests(unittest.TestCase):
|
|
def test_individual_without_kyc_is_rejected_before_payment(self):
|
|
service = RiskScoringService()
|
|
user = UserEntity(
|
|
id="user_1",
|
|
account_type="individual",
|
|
kyc_verified=False,
|
|
created_at=datetime.now(timezone.utc) - timedelta(days=10),
|
|
)
|
|
|
|
assessment = service.assess_order(user=user, total_price=Decimal("1000.00"), recent_order_count=0)
|
|
|
|
self.assertEqual(assessment.decision, "reject")
|
|
self.assertIn("kyc_not_completed", assessment.reasons)
|
|
|
|
def test_recent_new_high_value_individual_goes_to_manual_review(self):
|
|
service = RiskScoringService()
|
|
user = UserEntity(
|
|
id="user_1",
|
|
account_type="individual",
|
|
kyc_verified=True,
|
|
created_at=datetime.now(timezone.utc) - timedelta(hours=2),
|
|
)
|
|
|
|
assessment = service.assess_order(user=user, total_price=Decimal("250000.00"), recent_order_count=6)
|
|
|
|
self.assertEqual(assessment.decision, "manual_review")
|
|
self.assertGreaterEqual(assessment.score, 60)
|
|
self.assertIn("new_account", assessment.reasons)
|
|
self.assertIn("large_amount", assessment.reasons)
|
|
self.assertIn("velocity_spike", assessment.reasons)
|
|
|
|
def test_legal_entity_is_not_scored(self):
|
|
service = RiskScoringService()
|
|
user = UserEntity(id="org_1", account_type="legal_entity", kyc_verified=False)
|
|
|
|
assessment = service.assess_order(user=user, total_price=Decimal("999999.00"), recent_order_count=99)
|
|
|
|
self.assertEqual(assessment.decision, "skip")
|
|
self.assertEqual(assessment.score, 0)
|
|
self.assertEqual(assessment.reasons, [])
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|