1 # frozen_string_literal: true
5 class NominatimTest < ActiveSupport::TestCase
6 def test_describe_location
7 stub_request(:get, %r{^https://nominatim\.example\.com/reverse\?})
8 .to_return(:body => "<reversegeocode><result>Target location</result></reversegeocode>")
10 with_settings(:nominatim_url => "https://nominatim.example.com/") do
11 location = Nominatim.describe_location(60, 30, 10, "en")
12 assert_equal "Target location", location
15 assert_requested :get, "https://nominatim.example.com/reverse?lat=60&lon=30&zoom=10&accept-language=en",
16 :headers => { "User-Agent" => Settings.server_url }
19 def test_describe_location_no_result
20 stub_request(:get, %r{^https://nominatim\.example\.com/reverse\?})
21 .to_return(:body => "<reversegeocode><error>Unable to geocode</error></reversegeocode>")
23 with_settings(:nominatim_url => "https://nominatim.example.com/") do
24 location = Nominatim.describe_location(1, 2, 14, "en")
25 assert_equal "1.000, 2.000", location
28 assert_requested :get, "https://nominatim.example.com/reverse?lat=1&lon=2&zoom=14&accept-language=en",
29 :headers => { "User-Agent" => Settings.server_url }