osm_spec.rb 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Service::GeoLocation::Osm, :integration, use_vcr: true do
  4. before do
  5. # NB: Exclude possible geocoding matches, in order to always receive same coordinates for purpose of this test.
  6. # https://nominatim.org/release-docs/develop/api/Search/#result-restriction
  7. stub_const('Service::GeoLocation::Osm::OSM_SEARCH_URL', "#{Service::GeoLocation::Osm::OSM_SEARCH_URL}&exclude_place_ids=158906443")
  8. end
  9. describe '#geocode' do
  10. subject(:geocode) { described_class.geocode(address) }
  11. context 'with a german address' do
  12. let(:address) { 'Marienstrasse 13, 10117 Berlin' }
  13. let(:result) { [52.5220514, 13.3832091] }
  14. it { is_expected.to eq(result) }
  15. context 'without a separator between street, zipcode and city' do
  16. let(:address) { 'Marienstrasse 13 10117 Berlin' }
  17. it { is_expected.to eq(result) }
  18. end
  19. end
  20. context 'with a swiss address' do
  21. let(:address) { 'Martinsbruggstrasse 35, 9016 St. Gallen' }
  22. let(:result) { [47.43664765, 9.409934047751209] }
  23. it { is_expected.to eq(result) }
  24. context 'without a separator between street, zipcode and city' do
  25. let(:address) { 'Martinsbruggstrasse 35 9016 St. Gallen' }
  26. it { is_expected.to eq(result) }
  27. end
  28. end
  29. end
  30. describe '#reverse_geocode' do
  31. subject(:reverse_geocode) { described_class.reverse_geocode(latitude, longitude) }
  32. context 'with german coordinates' do
  33. let(:latitude) { 52.5220514 }
  34. let(:longitude) { 13.3832091 }
  35. let(:result) { '13, Marienstraße, Dorotheenstadt, Mitte, Berlin, 10117, Deutschland' }
  36. it { is_expected.to eq(result) }
  37. end
  38. context 'with swiss coordinates' do
  39. let(:latitude) { 47.43664765 }
  40. let(:longitude) { 9.409934047751209 }
  41. let(:result) { '35, Martinsbruggstrasse, Neudorf, St. Gallen, Wahlkreis St. Gallen, St. Gallen, 9016, Schweiz/Suisse/Svizzera/Svizra' }
  42. it { is_expected.to eq(result) }
  43. end
  44. end
  45. end