Library phase 3: change feed and folder export for Locus (GPX) and OsmAnd (favourites + tracks zip)
CI / check (push) Successful in 20s
CI / deploy (push) Successful in 13s

This commit is contained in:
randy committed 2026-11-13 23:00:07 +01:00
1 parent cca985d2b9
commit 59447c56f2
8 files changed
+305 -3

No files matched your search

+17
View File
@@ -247,6 +247,23 @@ class AppTest < Minitest::Test
FileUtils.rm_f(File.join(Maptool::App::DATA_DIR, "vehicle.json"))
end
def test_changes_and_exports_need_login
upload("ride.gpx", File.read(fixture_path("sample.gpx")), folder: "trips")
assert_equal 401, request.get("/api/library/changes").status
assert_equal 401, request.get("/api/library/export?folder=trips&flavor=locus").status
changes = json_body(request.get("/api/library/changes?since=0", **logged_in_env))
assert_equal ["Morning Loop", "Start"], changes["items"].map { |i| i["name"] }.sort
locus = request.get("/api/library/export?folder=trips&flavor=locus", **logged_in_env)
assert_includes locus.body, "<name>Morning Loop</name>"
osmand = request.get("/api/library/export?folder=trips&flavor=osmand", **logged_in_env)
entries = nil
Zip::File.open_buffer(StringIO.new(osmand.body)) { |zip| entries = zip.map(&:name) }
assert_equal ["tracks/trips/Morning Loop.gpx"], entries
assert_equal 400, request.get("/api/library/export?folder=trips&flavor=x", **logged_in_env).status
end
def test_invalid_folder_path_is_rejected
assert_equal 400, request.post("/api/library/folder?path=..%2F..%2Fescape", **logged_in_env).status
end
+36
View File
@@ -145,8 +145,44 @@ class LibraryTest < Minitest::Test
assert_equal [["Lake, scenic", 3]], features.map { |f| [f["properties"]["name"], f["properties"]["via"].size] }
end
def test_changes_lists_everything_after_a_rev_tombstones_included
library = open_library
start = library.rev
key = library.add_note(note("Gate"), "Van")
id = JSON.parse(library.geojson(key))["features"].first["properties"]["id"]
library.delete_feature(key, id)
changes = library.changes(start)
assert_equal library.rev, changes["rev"]
assert_equal ["Van"], changes["folders"].map { |f| f["name"] }
assert_equal [[id, true, "Point"]], changes["items"].map { |i| [i["id"], i["deleted"], i["geometry"]["type"]] }
assert_empty library.changes(library.rev)["items"]
assert_raises(Maptool::Library::InvalidValue) { library.changes("x") }
end
def test_export_for_locus_and_osmand
library = open_library
library.import(folder: "Van/CZ", filename: "ride.gpx", io: File.open(fixture_path("sample.gpx")))
library.add_note(note("Gate"), "Van/CZ")
library.add_note(note("Gate", nil).tap { |f| f["geometry"]["coordinates"] = [17.3, 48.3] }, "Van/CZ")
locus = Maptool::Gpx.to_geojson(write_tmp(library.export_gpx("Van/CZ")))["features"]
assert_equal 2, locus.count { |f| f["properties"]["name"] == "Gate" }
assert(locus.any? { |f| f["properties"]["kind"] == "track" })
files = library.export_osmand("Van/CZ")
assert_equal ["favourites.gpx", "tracks/Van/CZ/Morning Loop.gpx"], files.keys.sort
favourites = Maptool::Gpx.to_geojson(write_tmp(files["favourites.gpx"]))["features"]
assert_equal [["Gate", "Van / CZ"], ["Gate (2)", "Van / CZ"]], favourites.map { |f| f["properties"].values_at("name", "category") }.sort
assert_raises(Maptool::Library::NotFound) { library.export_gpx("nope") }
end
private
def write_tmp(content)
File.join(@dir, "export-#{SecureRandom.hex(4)}.gpx").tap { |path| File.write(path, content) }
end
def open_library
Maptool::Library.new(File.join(@dir, "library.sqlite"), gpx_store: @store, sources_dir: File.join(@dir, "sources"))
end