calendar_spec.rb 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe 'Calendars', type: :request do
  4. let(:admin) do
  5. create(:admin)
  6. end
  7. describe 'request handling' do
  8. it 'does calendar index with nobody' do
  9. get '/api/v1/calendars', as: :json
  10. expect(response).to have_http_status(:forbidden)
  11. expect(json_response).to be_a(Hash)
  12. expect(json_response['error']).to eq('Authentication required')
  13. get '/api/v1/calendars_init', as: :json
  14. expect(response).to have_http_status(:forbidden)
  15. expect(json_response).to be_a(Hash)
  16. expect(json_response['error']).to eq('Authentication required')
  17. get '/api/v1/calendars/timezones', as: :json
  18. expect(response).to have_http_status(:forbidden)
  19. expect(json_response).to be_a(Hash)
  20. expect(json_response['error']).to eq('Authentication required')
  21. end
  22. it 'does calendar index with admin' do
  23. authenticated_as(admin)
  24. get '/api/v1/calendars', as: :json
  25. expect(response).to have_http_status(:ok)
  26. expect(json_response).to be_a(Array)
  27. expect(json_response).to be_truthy
  28. expect(json_response.count).to eq(1)
  29. get '/api/v1/calendars?expand=true', as: :json
  30. expect(response).to have_http_status(:ok)
  31. expect(json_response).to be_a(Array)
  32. expect(json_response).to be_truthy
  33. expect(json_response.count).to eq(1)
  34. get '/api/v1/calendars?full=true', as: :json
  35. expect(response).to have_http_status(:ok)
  36. expect(json_response).to be_a(Hash)
  37. expect(json_response).to be_truthy
  38. expect(json_response['record_ids']).to be_truthy
  39. expect(json_response['record_ids'].count).to eq(1)
  40. expect(json_response['assets']).to be_truthy
  41. expect(json_response['assets']).to be_present
  42. # index
  43. get '/api/v1/calendars_init', as: :json
  44. expect(response).to have_http_status(:ok)
  45. expect(json_response).to be_a(Hash)
  46. expect(json_response['record_ids']).to be_truthy
  47. expect(json_response['ical_feeds']).to be_truthy
  48. expect(json_response['ical_feeds']['https://www.google.com/calendar/ical/da.danish%23holiday%40group.v.calendar.google.com/public/basic.ics']).to eq('Denmark')
  49. expect(json_response['ical_feeds']['https://www.google.com/calendar/ical/de.austrian%23holiday%40group.v.calendar.google.com/public/basic.ics']).to eq('Austria')
  50. expect(json_response['timezones']).to be_truthy
  51. expect(json_response['timezones']['Africa/Johannesburg']).to eq(2)
  52. expect(json_response['timezones']['America/Sitka']).to be_between(-9, -8)
  53. expect(json_response['timezones']['Europe/Berlin']).to be_between(1, 2)
  54. expect(json_response['assets']).to be_truthy
  55. # timezones
  56. get '/api/v1/calendars/timezones', as: :json
  57. expect(response).to have_http_status(:ok)
  58. expect(json_response).to be_a(Hash)
  59. expect(json_response['timezones']).to be_a(Hash)
  60. expect(json_response['timezones']['America/New_York']).to be_truthy
  61. end
  62. end
  63. describe 'Removing calendars via UI and API does not check for references #3845', authenticated_as: -> { user } do
  64. let(:calendar) { create(:calendar) }
  65. let(:sla) { create(:sla, calendar: calendar) }
  66. let(:user) { create(:admin) }
  67. before do
  68. sla
  69. end
  70. it 'does return reference error on delete if related objects exist' do
  71. delete "/api/v1/calendars/#{calendar.id}", params: {}, as: :json
  72. expect(json_response['error']).to eq("Can't delete, object has references.")
  73. end
  74. end
  75. end