From 382e773793a93825619c2a32fb825e3b67b5e44f Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Wed, 10 Jul 2024 17:08:40 +0300 Subject: [PATCH] Test Nominatim.describe_location --- test/lib/nominatim_test.rb | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 test/lib/nominatim_test.rb diff --git a/test/lib/nominatim_test.rb b/test/lib/nominatim_test.rb new file mode 100644 index 000000000..e7cb6fb59 --- /dev/null +++ b/test/lib/nominatim_test.rb @@ -0,0 +1,31 @@ +require "test_helper" + +class NominatimTest < ActiveSupport::TestCase + def test_describe_location + stub_request(:get, %r{^https://nominatim\.example\.com/reverse\?}) + .to_return(:body => "Target location") + + with_settings(:nominatim_url => "https://nominatim.example.com/", + :server_url => "osm-website.example.com") do + location = Nominatim.describe_location(60, 30, 10, "en") + assert_equal "Target location", location + end + + assert_requested :get, "https://nominatim.example.com/reverse?lat=60&lon=30&zoom=10&accept-language=en", + :headers => { "User-Agent" => "osm-website.example.com" } + end + + def test_describe_location_no_result + stub_request(:get, %r{^https://nominatim\.example\.com/reverse\?}) + .to_return(:body => "Unable to geocode") + + with_settings(:nominatim_url => "https://nominatim.example.com/", + :server_url => "osm-website.example.com") do + location = Nominatim.describe_location(1, 2, 14, "en") + assert_equal "1.000, 2.000", location + end + + assert_requested :get, "https://nominatim.example.com/reverse?lat=1&lon=2&zoom=14&accept-language=en", + :headers => { "User-Agent" => "osm-website.example.com" } + end +end -- 2.39.5