2021-06-01 12:20:20 +00:00
|
|
|
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
|
|
|
|
2015-05-07 11:12:40 +00:00
|
|
|
require 'integration_test_helper'
|
2017-09-29 16:03:09 +00:00
|
|
|
require 'webmock/minitest'
|
2015-05-07 11:12:40 +00:00
|
|
|
|
|
|
|
class GeoLocationTest < ActiveSupport::TestCase
|
|
|
|
|
2021-07-09 13:05:05 +00:00
|
|
|
setup do
|
2017-09-29 16:03:09 +00:00
|
|
|
@mock = true
|
2021-07-16 13:44:10 +00:00
|
|
|
# WebMock.allow_net_connect!
|
2017-09-29 16:03:09 +00:00
|
|
|
end
|
|
|
|
|
2015-05-07 11:12:40 +00:00
|
|
|
# check
|
|
|
|
test 'check simple results' do
|
|
|
|
|
2017-09-29 16:03:09 +00:00
|
|
|
if @mock
|
|
|
|
stub_request(:get, 'http://maps.googleapis.com/maps/api/geocode/json?address=Marienstrasse%2013,%2010117%20Berlin&sensor=true')
|
|
|
|
.to_return(status: 200, body: '{"results":[{"geometry":{"location":{"lat": 52.5219143, "lng": 13.3832647}}}]}', headers: {})
|
|
|
|
end
|
|
|
|
|
2016-03-31 13:41:34 +00:00
|
|
|
result = Service::GeoLocation.geocode('Marienstrasse 13, 10117 Berlin')
|
2015-05-07 11:12:40 +00:00
|
|
|
assert(result)
|
2016-08-17 22:29:09 +00:00
|
|
|
assert_equal(52.5219143, result[0])
|
2016-08-17 22:45:16 +00:00
|
|
|
assert_equal(13.3832647, result[1])
|
2015-05-07 11:12:40 +00:00
|
|
|
|
2017-09-29 16:03:09 +00:00
|
|
|
if @mock
|
|
|
|
stub_request(:get, 'http://maps.googleapis.com/maps/api/geocode/json?address=Marienstrasse%2013%2010117%20Berlin&sensor=true')
|
|
|
|
.to_return(status: 200, body: '{"results":[{"geometry":{"location":{"lat": 52.5219143, "lng": 13.3832647}}}]}', headers: {})
|
|
|
|
end
|
|
|
|
|
2016-03-31 13:41:34 +00:00
|
|
|
result = Service::GeoLocation.geocode('Marienstrasse 13 10117 Berlin')
|
2015-05-07 11:12:40 +00:00
|
|
|
assert(result)
|
2016-08-17 22:45:16 +00:00
|
|
|
assert_equal(52.5219143, result[0])
|
|
|
|
assert_equal(13.3832647, result[1])
|
2015-05-07 11:12:40 +00:00
|
|
|
|
2017-09-29 16:03:09 +00:00
|
|
|
if @mock
|
|
|
|
stub_request(:get, 'http://maps.googleapis.com/maps/api/geocode/json?address=Martinsbruggstrasse%2035,%209016%20St.%20Gallen&sensor=true')
|
|
|
|
.to_return(status: 200, body: '{"results":[{"geometry":{"location":{"lat": 47.4366557, "lng": 9.4098904}}}]}', headers: {})
|
|
|
|
end
|
|
|
|
|
2016-03-31 13:41:34 +00:00
|
|
|
result = Service::GeoLocation.geocode('Martinsbruggstrasse 35, 9016 St. Gallen')
|
2015-05-07 11:12:40 +00:00
|
|
|
assert(result)
|
2017-05-10 08:26:45 +00:00
|
|
|
assert_equal(47.4366557, result[0])
|
|
|
|
assert_equal(9.4098904, result[1])
|
2015-05-07 11:12:40 +00:00
|
|
|
|
2017-09-29 16:03:09 +00:00
|
|
|
if @mock
|
|
|
|
stub_request(:get, 'http://maps.googleapis.com/maps/api/geocode/json?address=Martinsbruggstrasse%2035%209016%20St.%20Gallen&sensor=true')
|
|
|
|
.to_return(status: 200, body: '{"results":[{"geometry":{"location":{"lat": 47.4366557, "lng": 9.4098904}}}]}', headers: {})
|
|
|
|
end
|
|
|
|
|
2016-03-31 13:41:34 +00:00
|
|
|
result = Service::GeoLocation.geocode('Martinsbruggstrasse 35 9016 St. Gallen')
|
2015-05-07 11:12:40 +00:00
|
|
|
assert(result)
|
2017-05-10 08:26:45 +00:00
|
|
|
assert_equal(47.4366557, result[0])
|
|
|
|
assert_equal(9.4098904, result[1])
|
2015-05-07 11:12:40 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'check user results' do
|
|
|
|
|
2017-09-29 16:03:09 +00:00
|
|
|
if @mock
|
|
|
|
stub_request(:get, 'http://maps.googleapis.com/maps/api/geocode/json?address=Marienstrasse%2013%2010117%20Berlin&sensor=true')
|
|
|
|
.to_return(status: 200, body: '{"results":[{"geometry":{"location":{"lat": 52.5219143, "lng": 13.3832647}}}]}', headers: {})
|
|
|
|
end
|
|
|
|
|
2015-05-07 11:12:40 +00:00
|
|
|
user1 = User.create(
|
2018-12-19 17:31:51 +00:00
|
|
|
login: 'some_geo_login1',
|
|
|
|
firstname: 'First',
|
|
|
|
lastname: 'Last',
|
|
|
|
email: 'some_geo_login1@example.com',
|
|
|
|
password: 'test',
|
|
|
|
address: 'Marienstrasse 13 10117 Berlin',
|
|
|
|
active: false,
|
2015-05-07 11:12:40 +00:00
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1
|
|
|
|
)
|
|
|
|
assert(user1.preferences)
|
|
|
|
assert(user1.preferences['lat'])
|
|
|
|
assert(user1.preferences['lng'])
|
2016-08-17 22:29:09 +00:00
|
|
|
assert_equal(52.5219143, user1.preferences['lat'])
|
2016-08-17 22:45:16 +00:00
|
|
|
assert_equal(13.3832647, user1.preferences['lng'])
|
2015-05-07 11:12:40 +00:00
|
|
|
|
2017-09-29 16:03:09 +00:00
|
|
|
if @mock
|
|
|
|
stub_request(:get, 'http://maps.googleapis.com/maps/api/geocode/json?address=Marienstrasse%2013,%2010117,%20Berlin&sensor=true')
|
|
|
|
.to_return(status: 200, body: '{"results":[{"geometry":{"location":{"lat": 52.5219143, "lng": 13.3832647}}}]}', headers: {})
|
|
|
|
end
|
|
|
|
|
2015-05-07 11:12:40 +00:00
|
|
|
user2 = User.create(
|
2018-12-19 17:31:51 +00:00
|
|
|
login: 'some_geo_login2',
|
|
|
|
firstname: 'First',
|
|
|
|
lastname: 'Last',
|
|
|
|
email: 'some_geo_login2@example.com',
|
|
|
|
password: 'test',
|
|
|
|
street: 'Marienstrasse 13',
|
|
|
|
city: 'Berlin',
|
|
|
|
zip: '10117',
|
|
|
|
active: false,
|
2015-05-07 11:12:40 +00:00
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1
|
|
|
|
)
|
|
|
|
assert(user2.preferences)
|
|
|
|
assert(user2.preferences['lat'])
|
|
|
|
assert(user2.preferences['lng'])
|
2016-08-17 22:45:16 +00:00
|
|
|
assert_equal(52.5219143, user2.preferences['lat'])
|
|
|
|
assert_equal(13.3832647, user2.preferences['lng'])
|
2015-05-07 11:12:40 +00:00
|
|
|
|
2017-09-29 16:03:09 +00:00
|
|
|
if @mock
|
|
|
|
stub_request(:get, 'http://maps.googleapis.com/maps/api/geocode/json?address=Martinsbruggstrasse%2035,%209016%20St.%20Gallen&sensor=true')
|
|
|
|
.to_return(status: 200, body: '{"results":[{"geometry":{"location":{"lat": 47.4366557, "lng": 9.4098904}}}]}', headers: {})
|
|
|
|
end
|
|
|
|
|
2015-05-07 11:12:40 +00:00
|
|
|
user3 = User.create(
|
2018-12-19 17:31:51 +00:00
|
|
|
login: 'some_geo_login3',
|
|
|
|
firstname: 'First',
|
|
|
|
lastname: 'Last',
|
|
|
|
email: 'some_geo_login3@example.com',
|
|
|
|
password: 'test',
|
|
|
|
address: 'Martinsbruggstrasse 35, 9016 St. Gallen',
|
|
|
|
active: false,
|
2015-05-07 11:12:40 +00:00
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1
|
|
|
|
)
|
|
|
|
assert(user3.preferences)
|
|
|
|
assert(user3.preferences['lat'])
|
|
|
|
assert(user3.preferences['lng'])
|
2017-05-10 08:26:45 +00:00
|
|
|
assert_equal(47.4366557, user3.preferences['lat'])
|
|
|
|
assert_equal(9.4098904, user3.preferences['lng'])
|
2015-05-07 11:12:40 +00:00
|
|
|
|
2017-09-29 16:03:09 +00:00
|
|
|
if @mock
|
|
|
|
stub_request(:get, 'http://maps.googleapis.com/maps/api/geocode/json?address=Martinsbruggstrasse%2035,%209016,%20St.%20Gallen&sensor=true')
|
|
|
|
.to_return(status: 200, body: '{"results":[{"geometry":{"location":{"lat": 47.4366557, "lng": 9.4098904}}}]}', headers: {})
|
|
|
|
end
|
|
|
|
|
2015-05-07 11:12:40 +00:00
|
|
|
user4 = User.create(
|
2018-12-19 17:31:51 +00:00
|
|
|
login: 'some_geo_login4',
|
|
|
|
firstname: 'First',
|
|
|
|
lastname: 'Last',
|
|
|
|
email: 'some_geo_login4@example.com',
|
|
|
|
password: 'test',
|
|
|
|
street: 'Martinsbruggstrasse 35',
|
|
|
|
city: 'St. Gallen',
|
|
|
|
zip: '9016',
|
|
|
|
active: false,
|
2015-05-07 11:12:40 +00:00
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1
|
|
|
|
)
|
|
|
|
assert(user4.preferences)
|
|
|
|
assert(user4.preferences['lat'])
|
|
|
|
assert(user4.preferences['lng'])
|
2017-05-10 08:26:45 +00:00
|
|
|
assert_equal(47.4366557, user4.preferences['lat'])
|
|
|
|
assert_equal(9.4098904, user4.preferences['lng'])
|
2015-05-07 11:12:40 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
end
|