Files
maptool/test/test_gpx.rb
T
randy cd4eef342b
CI / check (push) Successful in 1m56s
CI / deploy (push) Successful in 2m56s
Add a persisted test suite
`bundle exec rake test` (minitest, a default gem but pinned in
Gemfile for reproducibility) now covers what ad-hoc scripts kept
re-verifying by hand during development: Gpx/Fit/TrackStats parsing,
GpxStore/LiveTrackStore file/TTL logic, LiveTrackClient's payload
parsing, and app.rb's routes end to end via Rack::MockRequest.

MAPTOOL_DATA_DIR (new, app.rb) lets the suite point GPX_STORE/
LIVETRACK_STORE at a throwaway directory instead of real data/ —
without it every run would leave uploaded test files behind. Each
lib file's old `if __FILE__ == $0` self-check is now redundant with
real tests covering the same ground, so removed rather than kept as
a second copy of the same assertions. Wired into ci.yml so it isn't
just a local convenience.
2026-09-07 12:46:35 +02:00

45 lines
1.8 KiB
Ruby

require_relative "test_helper"
require "maptool/gpx"
class GpxTest < Minitest::Test
def test_kinds_detects_waypoints_and_tracks
assert_equal %w[waypoint track], Maptool::Gpx.kinds(fixture_path("sample.gpx"))
end
def test_to_geojson_produces_a_waypoint_point_feature
geojson = Maptool::Gpx.to_geojson(fixture_path("sample.gpx"))
waypoint = geojson["features"].find { |f| f["properties"]["kind"] == "waypoint" }
assert_equal "Point", waypoint["geometry"]["type"]
assert_equal [17.2, 48.1, 200.0], waypoint["geometry"]["coordinates"]
assert_equal "Start", waypoint["properties"]["name"]
assert_includes waypoint["properties"]["description"], "example.com"
end
def test_to_geojson_produces_a_track_multilinestring_with_stats
geojson = Maptool::Gpx.to_geojson(fixture_path("sample.gpx"))
track = geojson["features"].find { |f| f["properties"]["kind"] == "track" }
assert_equal "MultiLineString", track["geometry"]["type"]
assert_equal 3, track["geometry"]["coordinates"][0].size
assert_equal "Morning Loop", track["properties"]["name"]
assert_operator track["properties"]["distance_meters"], :>, 0
assert_equal 50.0, track["properties"]["elevation_gain_meters"], "200->250 is the only gain, 250->230 descent not subtracted"
assert_equal 1200, track["properties"]["duration_secs"]
end
def test_invalid_xml_raises_parse_error
path = File.join(Dir.mktmpdir, "bad.gpx")
File.write(path, "<gpx><trk unclosed>")
assert_raises(Maptool::Gpx::ParseError) { Maptool::Gpx.to_geojson(path) }
end
def test_non_gpx_root_raises_parse_error
path = File.join(Dir.mktmpdir, "notgpx.gpx")
File.write(path, "<html></html>")
assert_raises(Maptool::Gpx::ParseError) { Maptool::Gpx.to_geojson(path) }
end
end