From bc703ab5e9213e384cc526895c899dcd95dcb09b Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Fri, 18 Sep 2026 20:25:16 +0100 Subject: [PATCH] Test json responses to nominatim reverse searches --- .../nominatim_reverse_queries_controller_test.rb | 15 +++++++++++++++ .../searches/queries_controller_test.rb | 10 ++++++++++ 2 files changed, 25 insertions(+) diff --git a/test/controllers/searches/nominatim_reverse_queries_controller_test.rb b/test/controllers/searches/nominatim_reverse_queries_controller_test.rb index 15088e85e..cd65c0870 100644 --- a/test/controllers/searches/nominatim_reverse_queries_controller_test.rb +++ b/test/controllers/searches/nominatim_reverse_queries_controller_test.rb @@ -29,6 +29,21 @@ module Searches results_check :name => "MM Steak&Grill, ถนนศรีอยุธยา, บางขุนพรหม, กรุงเทพมหานคร, เขตดุสิต, กรุงเทพมหานคร, 10300, ประเทศไทย", :lat => 13.7708691, :lon => 100.505073233221, :type => "way", :id => 542901374, :zoom => 19 + + post search_nominatim_reverse_query_path(:lat => 51.7632, :lon => -0.0076, :zoom => 15), :headers => accept_format_header("application/json") + json_results_check :name => "Broxbourne, Hertfordshire, East of England, England, United Kingdom", + :lat => 51.7465723, :lon => -0.0190782, + :type => "node", :id => 28825933, :zoom => 15 + + post search_nominatim_reverse_query_path(:lat => 51.7632, :lon => -0.0076, :zoom => 17), :headers => accept_format_header("application/json") + json_results_check :name => "Dinant Link Road, Broxbourne, Hertfordshire, East of England, England, EN11 8HX, United Kingdom", + :lat => 51.7634883, :lon => -0.0088373, + :type => "way", :id => 3489841, :zoom => 17 + + post search_nominatim_reverse_query_path(:lat => 13.7709, :lon => 100.50507, :zoom => 19), :headers => accept_format_header("application/json") + json_results_check :name => "MM Steak&Grill, ถนนศรีอยุธยา, บางขุนพรหม, กรุงเทพมหานคร, เขตดุสิต, กรุงเทพมหานคร, 10300, ประเทศไทย", + :lat => 13.7708691, :lon => 100.505073233221, + :type => "way", :id => 542901374, :zoom => 19 end end diff --git a/test/controllers/searches/queries_controller_test.rb b/test/controllers/searches/queries_controller_test.rb index ac3d87d36..ca463bbd2 100644 --- a/test/controllers/searches/queries_controller_test.rb +++ b/test/controllers/searches/queries_controller_test.rb @@ -24,6 +24,16 @@ module Searches end end + def json_results_check(*results) + js = ActiveSupport::JSON.decode(@response.body) + assert_not_nil js + results.zip(js) do |expected, actual| + expected.each do |k, v| + assert_equal v.to_s, actual[k.to_s] + end + end + end + def results_check_error(error) assert_response :success assert_template :error -- 2.47.3