geo_ip_spec.rb 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. # Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Service::GeoIp, integration: true do
  4. describe '#location' do
  5. describe 'testing some locations' do
  6. subject(:lookup_result) { described_class.location(ip_address) }
  7. context 'with no results for locations' do
  8. context 'with invalid ip address' do
  9. let(:ip_address) { '127.0.0.0.1' }
  10. it { is_expected.to be_blank }
  11. end
  12. context 'with ip address of localhost' do
  13. let(:ip_address) { '127.0.0.1' }
  14. it { is_expected.to be_blank }
  15. end
  16. end
  17. shared_examples 'contains correct data for location' do
  18. it { is_expected.to include(expected_result) }
  19. end
  20. context 'with correct results for locations' do
  21. context 'with Swiss ip address' do
  22. let(:ip_address) { '195.65.29.254' }
  23. let(:expected_result) do
  24. {
  25. 'country_name' => 'Switzerland',
  26. 'city_name' => 'Amriswil',
  27. 'country_code' => 'CH',
  28. 'continent_code' => 'EU',
  29. 'latitude' => 47.5465,
  30. 'longitude' => 9.2901,
  31. }
  32. end
  33. include_examples 'contains correct data for location'
  34. end
  35. context 'with German ip address (Chemnitz)' do
  36. let(:ip_address) { '134.109.140.74' }
  37. let(:expected_result) do
  38. {
  39. 'country_name' => 'Germany',
  40. 'city_name' => 'Chemnitz',
  41. 'country_code' => 'DE',
  42. 'continent_code' => 'EU',
  43. 'latitude' => 50.8191,
  44. 'longitude' => 12.9419,
  45. }
  46. end
  47. include_examples 'contains correct data for location'
  48. end
  49. context 'with German ip address (Halle)' do
  50. let(:ip_address) { '46.253.55.170' }
  51. let(:expected_result) do
  52. {
  53. 'country_name' => 'Germany',
  54. 'city_name' => 'Halle',
  55. 'country_code' => 'DE',
  56. 'continent_code' => 'EU',
  57. 'latitude' => 51.5036,
  58. 'longitude' => 11.9594,
  59. }
  60. end
  61. include_examples 'contains correct data for location'
  62. end
  63. context 'with US ip address' do
  64. let(:ip_address) { '169.229.216.200' }
  65. let(:expected_result) do
  66. {
  67. 'country_name' => 'United States',
  68. 'city_name' => 'Richmond',
  69. 'country_code' => 'US',
  70. 'continent_code' => 'NA',
  71. 'latitude' => 37.9387,
  72. 'longitude' => -122.3661,
  73. }
  74. end
  75. include_examples 'contains correct data for location'
  76. end
  77. end
  78. end
  79. end
  80. end