fix: query persisted work area geometry
GeoIntel CI / docs-smoke (push) Canceled after 0s
GeoIntel CI / contract-smoke (push) Canceled after 0s

This commit is contained in:
Codex
2026-07-14 19:38:41 +02:00
parent a879c74b12
commit 616424e2a2
9 changed files with 179 additions and 46 deletions
@@ -162,11 +162,108 @@ def test_vector_select_route_rejects_non_vector_dataset(monkeypatch) -> None:
raise AssertionError("Expected DATASET_NOT_VECTOR")
def test_vector_select_route_uses_persisted_area_geometry_when_requested(monkeypatch) -> None:
from app.api.routes import datasets as dataset_routes
project_id = uuid.uuid4()
dataset_id = uuid.uuid4()
area_id = uuid.uuid4()
dataset = Dataset(
id=dataset_id,
project_id=project_id,
dataset_type="vector",
source="fixture",
name="Regional vector",
source_metadata={"selection_aggregation": {"method": "feature_count"}},
)
area_geometry = object()
area = SimpleNamespace(id=area_id, project_id=project_id, geometry=area_geometry)
captured: dict[str, object] = {}
class _AreaSession:
@staticmethod
def get(model, selected_id): # noqa: ANN001
assert model is dataset_routes.Area
assert selected_id == area_id
return area
def select_features(db, **kwargs): # noqa: ANN001
captured["select"] = kwargs
return {
"selection_bbox": {"min_x": 4.9, "min_y": 50.9, "max_x": 5.2, "max_y": 51.2, "crs": "EPSG:4326"},
"selection_area_id": str(area_id),
"feature_count": 1,
"total_feature_count": 1,
"limit": 100,
"truncated": False,
"geojson": {"type": "FeatureCollection", "features": []},
}
def summarize_features(db, **kwargs): # noqa: ANN001
captured["summary"] = kwargs
return {
"metric_label": "Gebouwen",
"metric_value": 1,
"metric_unit": "objecten",
"aggregation_method": "feature_count",
"feature_count": 1,
"is_estimate": False,
}
monkeypatch.setattr(dataset_routes.DatasetService, "get_dataset", lambda db, selected_id: dataset)
monkeypatch.setattr(dataset_routes.VectorFeatureService, "select_features_by_bbox", select_features)
monkeypatch.setattr(dataset_routes.VectorFeatureService, "summarize_features_by_bbox", summarize_features)
response = dataset_routes.select_vector_features(
project_id=project_id,
dataset_id=dataset_id,
payload=dataset_routes.VectorSelectionRequest(
bbox=dataset_routes.VectorSelectionBBox(min_x=4.9, min_y=50.9, max_x=5.2, max_y=51.2),
area_id=area_id,
limit=100,
),
db=_AreaSession(),
)
assert str(response["data"]["selection_area_id"]) == str(area_id)
assert captured["select"]["selection_geometry"] is area_geometry
assert captured["select"]["selection_area_id"] == area_id
assert captured["summary"]["selection_geometry"] is area_geometry
def test_vector_select_route_rejects_area_from_another_project(monkeypatch) -> None:
from app.api.routes import datasets as dataset_routes
project_id = uuid.uuid4()
dataset_id = uuid.uuid4()
area_id = uuid.uuid4()
dataset = Dataset(id=dataset_id, project_id=project_id, dataset_type="vector", source="fixture", name="Vector")
other_area = SimpleNamespace(id=area_id, project_id=uuid.uuid4(), geometry=object())
monkeypatch.setattr(dataset_routes.DatasetService, "get_dataset", lambda db, selected_id: dataset)
try:
dataset_routes.select_vector_features(
project_id=project_id,
dataset_id=dataset_id,
payload=dataset_routes.VectorSelectionRequest(
bbox=dataset_routes.VectorSelectionBBox(min_x=4.9, min_y=50.9, max_x=5.2, max_y=51.2),
area_id=area_id,
),
db=SimpleNamespace(get=lambda model, selected_id: other_area),
)
except AppError as exc:
assert exc.code == "AREA_NOT_FOUND"
else: # pragma: no cover
raise AssertionError("Expected AREA_NOT_FOUND")
def test_frontend_exposes_map_bbox_selection_contracts() -> None:
api_client = (ROOT / "frontend" / "src" / "services" / "api" / "datasets.ts").read_text(encoding="utf-8")
map_workspace = (ROOT / "frontend" / "src" / "components" / "map" / "MapWorkspace.tsx").read_text(encoding="utf-8")
geomap = (ROOT / "frontend" / "src" / "components" / "GeoMap.tsx").read_text(encoding="utf-8")
app = (ROOT / "frontend" / "src" / "App.tsx").read_text(encoding="utf-8")
extract_hook = (ROOT / "frontend" / "src" / "hooks" / "useMapSelectionExtract.ts").read_text(encoding="utf-8")
theme_hook = (ROOT / "frontend" / "src" / "hooks" / "useMapThemeSelectionInsights.ts").read_text(encoding="utf-8")
assert "selectVectorFeatures" in api_client
assert "Area selection" in map_workspace
@@ -177,3 +274,6 @@ def test_frontend_exposes_map_bbox_selection_contracts() -> None:
assert "selection-bbox" in geomap
assert "selection-result" in geomap
assert "useMapSelectionExtract" in app
assert "area_id: areaId" in extract_hook
assert "area_id: areaId" in theme_hook
assert "analyzeSelection(selectedAreaBbox, selectedMapArea?.id)" in map_workspace