geo_calendar_spec.rb 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Service::GeoCalendar, integration: true, retry: 0, 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. shared_examples 'contains correct data for location' do
  8. it { is_expected.to include(expected_result) }
  9. end
  10. context 'with default/fallback values' do
  11. let(:expected_result) do
  12. {
  13. 'name' => 'My Calendar',
  14. 'timezone' => 'America/Los_Angeles',
  15. 'ical_url' => '',
  16. }
  17. end
  18. context 'with invalid ip address' do
  19. let(:ip_address) { '127.0.0.0.1' }
  20. include_examples 'contains correct data for location'
  21. end
  22. context 'with ip address of localhost' do
  23. let(:ip_address) { '127.0.0.1' }
  24. include_examples 'contains correct data for location'
  25. end
  26. end
  27. context 'with correct results for Swiss ip addresses' do
  28. let(:expected_result) do
  29. {
  30. 'name' => 'Switzerland',
  31. 'timezone' => 'Europe/Zurich',
  32. 'ical_url' => 'https://www.google.com/calendar/ical/de.ch%23holiday%40group.v.calendar.google.com/public/basic.ics',
  33. }
  34. end
  35. context 'with Swiss ip #1' do
  36. let(:ip_address) { '195.65.29.254' }
  37. include_examples 'contains correct data for location'
  38. end
  39. context 'with Swiss ip #2' do
  40. let(:ip_address) { '195.191.132.18' }
  41. include_examples 'contains correct data for location'
  42. end
  43. end
  44. context 'with correct results for German ip addresses' do
  45. let(:expected_result) do
  46. {
  47. 'name' => 'Germany',
  48. 'timezone' => 'Europe/Berlin',
  49. 'ical_url' => 'https://www.google.com/calendar/ical/de.german%23holiday%40group.v.calendar.google.com/public/basic.ics',
  50. }
  51. end
  52. context 'with German ip #1' do
  53. let(:ip_address) { '134.109.140.74' }
  54. include_examples 'contains correct data for location'
  55. end
  56. context 'with German ip #2' do
  57. let(:ip_address) { '46.253.55.170' }
  58. include_examples 'contains correct data for location'
  59. end
  60. end
  61. context 'with correct results for US ip addresses' do
  62. let(:expected_result) do
  63. {
  64. 'name' => name,
  65. 'timezone' => timezone,
  66. 'ical_url' => 'https://www.google.com/calendar/ical/en.usa%23holiday%40group.v.calendar.google.com/public/basic.ics',
  67. }
  68. end
  69. context 'with US ip #1' do
  70. let(:ip_address) { '169.229.216.200' }
  71. let(:name) { 'United States/California' }
  72. let(:timezone) { 'America/Los_Angeles' }
  73. include_examples 'contains correct data for location'
  74. end
  75. context 'with US ip #2' do
  76. let(:ip_address) { '17.171.2.25' }
  77. let(:name) { 'United States' }
  78. let(:timezone) { 'America/Chicago' }
  79. include_examples 'contains correct data for location'
  80. context 'with US ip #3' do
  81. let(:ip_address) { '184.168.47.225' }
  82. include_examples 'contains correct data for location'
  83. end
  84. end
  85. end
  86. context 'with correct result for Canadian ip address' do
  87. let(:expected_result) do
  88. {
  89. 'name' => 'Canada',
  90. 'timezone' => 'America/Toronto',
  91. 'ical_url' => 'https://www.google.com/calendar/ical/en.canadian%23holiday%40group.v.calendar.google.com/public/basic.ics',
  92. }
  93. end
  94. let(:ip_address) { '69.172.201.245' }
  95. include_examples 'contains correct data for location'
  96. end
  97. context 'with correct result for Mexican ip address' do
  98. let(:expected_result) do
  99. {
  100. 'name' => 'Mexico/Mexico City',
  101. 'timezone' => 'America/Mexico_City',
  102. 'ical_url' => 'https://www.google.com/calendar/ical/en.mexican%23holiday%40group.v.calendar.google.com/public/basic.ics',
  103. }
  104. end
  105. let(:ip_address) { '132.247.70.37' }
  106. include_examples 'contains correct data for location'
  107. end
  108. end
  109. end
  110. end