Refactor transport calculation into shared domain
This commit is contained in:
@@ -2,6 +2,7 @@ import base64
|
||||
import os
|
||||
import tempfile
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
import app as rollcalc_app
|
||||
|
||||
@@ -62,6 +63,42 @@ class CalculationApiTests(unittest.TestCase):
|
||||
self.assertEqual(result["state"]["request"]["roll_length_m"], 80.0)
|
||||
self.assertEqual(result["calculation"]["effective_roll_length_m"], 80.0)
|
||||
|
||||
def test_transport_endpoint_delegates_to_shared_domain_service(self):
|
||||
payload = {
|
||||
"length_m": 10,
|
||||
"width_m": 5,
|
||||
"height_m": 5,
|
||||
"max_weight_kg": 10000,
|
||||
"roll_diameter_mm": 1000,
|
||||
"core_diameter_mm": 150,
|
||||
"roll_width_m": 1,
|
||||
"roll_weight_kg": 1000,
|
||||
}
|
||||
with patch.object(
|
||||
rollcalc_app,
|
||||
"analyze_transport",
|
||||
return_value={"status": "success", "analysis": {"final_rolls": 10}},
|
||||
) as analyze:
|
||||
response = self.client.post(
|
||||
"/api/calculations/transport",
|
||||
json=payload,
|
||||
headers=self.headers,
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertEqual(response.get_json()["analysis"]["final_rolls"], 10)
|
||||
analyze.assert_called_once_with(payload)
|
||||
|
||||
def test_transport_endpoint_returns_structured_domain_validation(self):
|
||||
response = self.client.post(
|
||||
"/api/calculations/transport",
|
||||
json={"length_m": 0},
|
||||
headers=self.headers,
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertEqual(response.get_json()["status"], "invalid_parameter")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user