Files
maptool/test/test_overpass_pois.rb
T
randy f53c74e06f
CI / check (push) Successful in 40s
CI / deploy (push) Successful in 12s
Add rake overpass:pois to fetch camper POIs from Overpass
lib/maptool/overpass_pois.rb: queries Overpass for drinking water,
dump stations, LPG refill, toilets, laundromats, supermarkets/
convenience stores, and springs within a bbox, writes GeoJSON. A
dev-time tool (like the offline.pmtiles/terrain.pmtiles generation
steps already documented) — not called by the running app, drop the
output into data/gpx/ or upload it through the Tracks panel like any
other .geojson layer.

Verified against the real Overpass API (88 POIs for central
Bratislava) in addition to the new unit tests (pure to_geojson/
build_query logic, no network in the suite itself). Full suite: 103
runs, 0 failures.
2026-09-09 10:21:41 +02:00

69 lines
2.9 KiB
Ruby

require_relative "test_helper"
require "maptool/overpass_pois"
# No real network calls — to_geojson is pure (canned Overpass response ->
# GeoJSON), and that's the part worth protecting from regressions. fetch()
# itself is a thin Net::HTTP.post_form + JSON.parse wrapper, same as
# LiveTrackClient's own fetch_html, not independently tested for the same
# reason that one isn't.
class OverpassPoisTest < Minitest::Test
def test_to_geojson_converts_matching_node_elements
response = {
"elements" => [
{ "type" => "node", "lat" => 48.1, "lon" => 17.2, "tags" => { "amenity" => "drinking_water" } },
{ "type" => "node", "lat" => 48.3, "lon" => 17.4, "tags" => { "amenity" => "toilets", "name" => "Rest area" } },
],
}
geojson = Maptool::OverpassPois.to_geojson(response)
assert_equal "FeatureCollection", geojson["type"]
assert_equal 2, geojson["features"].size
water = geojson["features"].find { |f| f["properties"]["category"] == "Drinking water" }
assert_equal [17.2, 48.1], water["geometry"]["coordinates"]
assert_equal "Drinking water", water["properties"]["name"], "falls back to the category when the node has no name tag"
end
def test_to_geojson_uses_the_node_name_when_present
response = { "elements" => [{ "type" => "node", "lat" => 48.3, "lon" => 17.4, "tags" => { "amenity" => "toilets", "name" => "Rest area" } }] }
feature = Maptool::OverpassPois.to_geojson(response)["features"].first
assert_equal "Rest area", feature["properties"]["name"]
end
def test_to_geojson_skips_ways_and_relations
response = { "elements" => [{ "type" => "way", "tags" => { "amenity" => "drinking_water" } }] }
assert_empty Maptool::OverpassPois.to_geojson(response)["features"]
end
def test_to_geojson_skips_nodes_matching_no_known_category
response = { "elements" => [{ "type" => "node", "lat" => 48.1, "lon" => 17.2, "tags" => { "amenity" => "restaurant" } }] }
assert_empty Maptool::OverpassPois.to_geojson(response)["features"]
end
def test_lpg_matches_either_fuel_stations_with_the_lpg_tag_or_gas_bottle_shops
response = {
"elements" => [
{ "type" => "node", "lat" => 1, "lon" => 1, "tags" => { "amenity" => "fuel", "fuel:lpg" => "yes" } },
{ "type" => "node", "lat" => 2, "lon" => 2, "tags" => { "shop" => "gas" } },
{ "type" => "node", "lat" => 3, "lon" => 3, "tags" => { "amenity" => "fuel" } }, # no lpg tag - not a match
],
}
categories = Maptool::OverpassPois.to_geojson(response)["features"].map { |f| f["properties"]["category"] }
assert_equal ["LPG refill", "LPG refill"], categories
end
def test_build_query_includes_the_bbox_and_every_category_filter
query = Maptool::OverpassPois.build_query([48.0, 17.0, 49.0, 18.0])
assert_includes query, "48.0,17.0,49.0,18.0"
assert_includes query, %(["amenity"="drinking_water"])
assert_includes query, %(["natural"="spring"])
end
end