calendar_spec.rb 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. # Copyright (C) 2012-2021 Zammad Foundation, http://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_kind_of(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_kind_of(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_kind_of(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_kind_of(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_kind_of(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_kind_of(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_kind_of(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_kind_of(Hash)
  59. expect(json_response['timezones']).to be_a_kind_of(Hash)
  60. expect(json_response['timezones']['America/New_York']).to be_truthy
  61. end
  62. end
  63. end