Library phase 3: change feed and folder export for Locus (GPX) and OsmAnd (favourites + tracks zip)
This commit is contained in:
1 parent
cca985d2b9
commit
59447c56f2
8 files changed
+305
-3
No files matched your search
@@ -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
|
||||
|
||||
Reference in new issue
Block a user