geo_ip_spec.rb 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Service::GeoIp, integration: true, retry: 5, retry_wait: 30.seconds 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. 'country_code' => 'CH',
  27. 'continent_code' => 'EU',
  28. 'latitude' => be_a(Float),
  29. 'longitude' => be_a(Float),
  30. }
  31. end
  32. include_examples 'contains correct data for location'
  33. end
  34. context 'with German ip address (Chemnitz)' do
  35. let(:ip_address) { '134.109.140.74' }
  36. let(:expected_result) do
  37. {
  38. 'country_name' => 'Germany',
  39. 'city_name' => be_present,
  40. 'country_code' => 'DE',
  41. 'continent_code' => 'EU',
  42. 'latitude' => be_a(Float),
  43. 'longitude' => be_a(Float),
  44. }
  45. end
  46. include_examples 'contains correct data for location'
  47. end
  48. context 'with German ip address (Halle)' do
  49. let(:ip_address) { '46.253.55.170' }
  50. let(:expected_result) do
  51. {
  52. 'country_name' => 'Germany',
  53. 'city_name' => be_present,
  54. 'country_code' => 'DE',
  55. 'continent_code' => 'EU',
  56. 'latitude' => be_a(Float),
  57. 'longitude' => be_a(Float),
  58. }
  59. end
  60. include_examples 'contains correct data for location'
  61. end
  62. context 'with US ip address' do
  63. let(:ip_address) { '169.229.216.200' }
  64. let(:expected_result) do
  65. {
  66. 'country_name' => 'United States',
  67. 'city_name' => be_present,
  68. 'country_code' => 'US',
  69. 'continent_code' => 'NA',
  70. 'latitude' => be_a(Float),
  71. 'longitude' => be_a(Float),
  72. }
  73. end
  74. include_examples 'contains correct data for location'
  75. end
  76. end
  77. end
  78. end
  79. end