Added unit tests

This commit is contained in:
mmd-osm 2020-01-08 18:49:45 +01:00
parent 70702d565a
commit 91b31f03de
6 changed files with 105 additions and 0 deletions

View file

@ -13,6 +13,10 @@ module Api
{ :path => "/api/0.6/node/1", :method => :get },
{ :controller => "api/nodes", :action => "show", :id => "1" }
)
assert_routing(
{ :path => "/api/0.6/node/1.json", :method => :get },
{ :controller => "api/nodes", :action => "show", :id => "1", :format => "json" }
)
assert_routing(
{ :path => "/api/0.6/node/1", :method => :put },
{ :controller => "api/nodes", :action => "update", :id => "1" }
@ -25,6 +29,10 @@ module Api
{ :path => "/api/0.6/nodes", :method => :get },
{ :controller => "api/nodes", :action => "index" }
)
assert_routing(
{ :path => "/api/0.6/nodes.json", :method => :get },
{ :controller => "api/nodes", :action => "index", :format => "json" }
)
end
def test_create
@ -464,6 +472,19 @@ module Api
assert_select "node[id='#{node5.id}'][visible='false']", :count => 1
end
# test a working call with json format
get :index, :params => { :nodes => "#{node1.id},#{node2.id},#{node3.id},#{node4.id},#{node5.id}", :format => "json" }
js = ActiveSupport::JSON.decode(@response.body)
assert_not_nil js
assert_equal 5, js["elements"].count
assert_equal 5, (js["elements"].count { |a| a["type"] == "node" })
assert_equal 1, (js["elements"].count { |a| a["id"] == node1.id && a["visible"].nil? })
assert_equal 1, (js["elements"].count { |a| a["id"] == node2.id && a["visible"] == false })
assert_equal 1, (js["elements"].count { |a| a["id"] == node3.id && a["visible"].nil? })
assert_equal 1, (js["elements"].count { |a| a["id"] == node4.id && a["visible"].nil? })
assert_equal 1, (js["elements"].count { |a| a["id"] == node5.id && a["visible"] == false })
# check error when a non-existent node is included
get :index, :params => { :nodes => "#{node1.id},#{node2.id},#{node3.id},#{node4.id},#{node5.id},0" }
assert_response :not_found

View file

@ -17,6 +17,14 @@ module Api
{ :path => "/api/0.6/node/1/2", :method => :get },
{ :controller => "api/old_nodes", :action => "version", :id => "1", :version => "2" }
)
assert_routing(
{ :path => "/api/0.6/node/1/history.json", :method => :get },
{ :controller => "api/old_nodes", :action => "history", :id => "1", :format => "json" }
)
assert_routing(
{ :path => "/api/0.6/node/1/2.json", :method => :get },
{ :controller => "api/old_nodes", :action => "version", :id => "1", :version => "2", :format => "json" }
)
assert_routing(
{ :path => "/api/0.6/node/1/2/redact", :method => :post },
{ :controller => "api/old_nodes", :action => "redact", :id => "1", :version => "2" }

View file

@ -13,6 +13,14 @@ module Api
{ :path => "/api/0.6/relation/1/2", :method => :get },
{ :controller => "api/old_relations", :action => "version", :id => "1", :version => "2" }
)
assert_routing(
{ :path => "/api/0.6/relation/1/history.json", :method => :get },
{ :controller => "api/old_relations", :action => "history", :id => "1", :format => "json" }
)
assert_routing(
{ :path => "/api/0.6/relation/1/2.json", :method => :get },
{ :controller => "api/old_relations", :action => "version", :id => "1", :version => "2", :format => "json" }
)
assert_routing(
{ :path => "/api/0.6/relation/1/2/redact", :method => :post },
{ :controller => "api/old_relations", :action => "redact", :id => "1", :version => "2" }

View file

@ -13,6 +13,14 @@ module Api
{ :path => "/api/0.6/way/1/2", :method => :get },
{ :controller => "api/old_ways", :action => "version", :id => "1", :version => "2" }
)
assert_routing(
{ :path => "/api/0.6/way/1/history.json", :method => :get },
{ :controller => "api/old_ways", :action => "history", :id => "1", :format => "json" }
)
assert_routing(
{ :path => "/api/0.6/way/1/2.json", :method => :get },
{ :controller => "api/old_ways", :action => "version", :id => "1", :version => "2", :format => "json" }
)
assert_routing(
{ :path => "/api/0.6/way/1/2/redact", :method => :post },
{ :controller => "api/old_ways", :action => "redact", :id => "1", :version => "2" }

View file

@ -13,10 +13,18 @@ module Api
{ :path => "/api/0.6/relation/1/full", :method => :get },
{ :controller => "api/relations", :action => "full", :id => "1" }
)
assert_routing(
{ :path => "/api/0.6/relation/1/full.json", :method => :get },
{ :controller => "api/relations", :action => "full", :id => "1", :format => "json" }
)
assert_routing(
{ :path => "/api/0.6/relation/1", :method => :get },
{ :controller => "api/relations", :action => "show", :id => "1" }
)
assert_routing(
{ :path => "/api/0.6/relation/1.json", :method => :get },
{ :controller => "api/relations", :action => "show", :id => "1", :format => "json" }
)
assert_routing(
{ :path => "/api/0.6/relation/1", :method => :put },
{ :controller => "api/relations", :action => "update", :id => "1" }
@ -29,6 +37,10 @@ module Api
{ :path => "/api/0.6/relations", :method => :get },
{ :controller => "api/relations", :action => "index" }
)
assert_routing(
{ :path => "/api/0.6/relations.json", :method => :get },
{ :controller => "api/relations", :action => "index", :format => "json" }
)
assert_routing(
{ :path => "/api/0.6/node/1/relations", :method => :get },
@ -42,6 +54,18 @@ module Api
{ :path => "/api/0.6/relation/1/relations", :method => :get },
{ :controller => "api/relations", :action => "relations_for_relation", :id => "1" }
)
assert_routing(
{ :path => "/api/0.6/node/1/relations.json", :method => :get },
{ :controller => "api/relations", :action => "relations_for_node", :id => "1", :format => "json" }
)
assert_routing(
{ :path => "/api/0.6/way/1/relations.json", :method => :get },
{ :controller => "api/relations", :action => "relations_for_way", :id => "1", :format => "json" }
)
assert_routing(
{ :path => "/api/0.6/relation/1/relations.json", :method => :get },
{ :controller => "api/relations", :action => "relations_for_relation", :id => "1", :format => "json" }
)
end
# -------------------------------------
@ -187,6 +211,18 @@ module Api
assert_select "relation[id='#{relation4.id}'][visible='true']", :count => 1
end
# test a working call with json format
get :index, :params => { :relations => "#{relation1.id},#{relation2.id},#{relation3.id},#{relation4.id}", :format => "json" }
js = ActiveSupport::JSON.decode(@response.body)
assert_not_nil js
assert_equal 4, js["elements"].count
assert_equal 4, (js["elements"].count { |a| a["type"] == "relation" })
assert_equal 1, (js["elements"].count { |a| a["id"] == relation1.id && a["visible"].nil? })
assert_equal 1, (js["elements"].count { |a| a["id"] == relation2.id && a["visible"] == false })
assert_equal 1, (js["elements"].count { |a| a["id"] == relation3.id && a["visible"].nil? })
assert_equal 1, (js["elements"].count { |a| a["id"] == relation4.id && a["visible"].nil? })
# check error when a non-existent relation is included
get :index, :params => { :relations => "#{relation1.id},#{relation2.id},#{relation3.id},#{relation4.id},0" }
assert_response :not_found

View file

@ -13,10 +13,18 @@ module Api
{ :path => "/api/0.6/way/1/full", :method => :get },
{ :controller => "api/ways", :action => "full", :id => "1" }
)
assert_routing(
{ :path => "/api/0.6/way/1/full.json", :method => :get },
{ :controller => "api/ways", :action => "full", :id => "1", :format => "json" }
)
assert_routing(
{ :path => "/api/0.6/way/1", :method => :get },
{ :controller => "api/ways", :action => "show", :id => "1" }
)
assert_routing(
{ :path => "/api/0.6/way/1.json", :method => :get },
{ :controller => "api/ways", :action => "show", :id => "1", :format => "json" }
)
assert_routing(
{ :path => "/api/0.6/way/1", :method => :put },
{ :controller => "api/ways", :action => "update", :id => "1" }
@ -29,6 +37,10 @@ module Api
{ :path => "/api/0.6/ways", :method => :get },
{ :controller => "api/ways", :action => "index" }
)
assert_routing(
{ :path => "/api/0.6/ways.json", :method => :get },
{ :controller => "api/ways", :action => "index", :format => "json" }
)
end
# -------------------------------------
@ -104,6 +116,18 @@ module Api
assert_select "way[id='#{way4.id}'][visible='true']", :count => 1
end
# test a working call with json format
get :index, :params => { :ways => "#{way1.id},#{way2.id},#{way3.id},#{way4.id}", :format => "json" }
js = ActiveSupport::JSON.decode(@response.body)
assert_not_nil js
assert_equal 4, js["elements"].count
assert_equal 4, (js["elements"].count { |a| a["type"] == "way" })
assert_equal 1, (js["elements"].count { |a| a["id"] == way1.id && a["visible"].nil? })
assert_equal 1, (js["elements"].count { |a| a["id"] == way2.id && a["visible"] == false })
assert_equal 1, (js["elements"].count { |a| a["id"] == way3.id && a["visible"].nil? })
assert_equal 1, (js["elements"].count { |a| a["id"] == way4.id && a["visible"].nil? })
# check error when a non-existent way is included
get :index, :params => { :ways => "#{way1.id},#{way2.id},#{way3.id},#{way4.id},0" }
assert_response :not_found