]> git.openstreetmap.org Git - rails.git/blob - test/lib/nominatim_test.rb
Merge remote-tracking branch 'upstream/pull/5334'
[rails.git] / test / lib / nominatim_test.rb
1 require "test_helper"
2
3 class NominatimTest < ActiveSupport::TestCase
4   def test_describe_location
5     stub_request(:get, %r{^https://nominatim\.example\.com/reverse\?})
6       .to_return(:body => "<reversegeocode><result>Target location</result></reversegeocode>")
7
8     with_settings(:nominatim_url => "https://nominatim.example.com/") do
9       location = Nominatim.describe_location(60, 30, 10, "en")
10       assert_equal "Target location", location
11     end
12
13     assert_requested :get, "https://nominatim.example.com/reverse?lat=60&lon=30&zoom=10&accept-language=en",
14                      :headers => { "User-Agent" => Settings.server_url }
15   end
16
17   def test_describe_location_no_result
18     stub_request(:get, %r{^https://nominatim\.example\.com/reverse\?})
19       .to_return(:body => "<reversegeocode><error>Unable to geocode</error></reversegeocode>")
20
21     with_settings(:nominatim_url => "https://nominatim.example.com/") do
22       location = Nominatim.describe_location(1, 2, 14, "en")
23       assert_equal "1.000, 2.000", location
24     end
25
26     assert_requested :get, "https://nominatim.example.com/reverse?lat=1&lon=2&zoom=14&accept-language=en",
27                      :headers => { "User-Agent" => Settings.server_url }
28   end
29 end