calendar_spec.rb 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. require 'rails_helper'
  2. RSpec.describe 'Calendars', type: :request do
  3. let(:admin) do
  4. create(:admin)
  5. end
  6. describe 'request handling' do
  7. it 'does calendar index with nobody' do
  8. get '/api/v1/calendars', as: :json
  9. expect(response).to have_http_status(:forbidden)
  10. expect(json_response).to be_a_kind_of(Hash)
  11. expect(json_response['error']).to eq('Authentication required')
  12. get '/api/v1/calendars_init', as: :json
  13. expect(response).to have_http_status(:forbidden)
  14. expect(json_response).to be_a_kind_of(Hash)
  15. expect(json_response['error']).to eq('Authentication required')
  16. get '/api/v1/calendars/timezones', as: :json
  17. expect(response).to have_http_status(:forbidden)
  18. expect(json_response).to be_a_kind_of(Hash)
  19. expect(json_response['error']).to eq('Authentication required')
  20. end
  21. it 'does calendar index with admin' do
  22. authenticated_as(admin)
  23. get '/api/v1/calendars', as: :json
  24. expect(response).to have_http_status(:ok)
  25. expect(json_response).to be_a_kind_of(Array)
  26. expect(json_response).to be_truthy
  27. expect(json_response.count).to eq(1)
  28. get '/api/v1/calendars?expand=true', as: :json
  29. expect(response).to have_http_status(:ok)
  30. expect(json_response).to be_a_kind_of(Array)
  31. expect(json_response).to be_truthy
  32. expect(json_response.count).to eq(1)
  33. get '/api/v1/calendars?full=true', as: :json
  34. expect(response).to have_http_status(:ok)
  35. expect(json_response).to be_a_kind_of(Hash)
  36. expect(json_response).to be_truthy
  37. expect(json_response['record_ids']).to be_truthy
  38. expect(json_response['record_ids'].count).to eq(1)
  39. expect(json_response['assets']).to be_truthy
  40. expect(json_response['assets']).to be_present
  41. # index
  42. get '/api/v1/calendars_init', as: :json
  43. expect(response).to have_http_status(:ok)
  44. expect(json_response).to be_a_kind_of(Hash)
  45. expect(json_response['record_ids']).to be_truthy
  46. expect(json_response['ical_feeds']).to be_truthy
  47. 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')
  48. 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')
  49. expect(json_response['timezones']).to be_truthy
  50. expect(json_response['timezones']['Africa/Johannesburg']).to eq(2)
  51. expect(json_response['timezones']['America/Sitka']).to be_between(-9, -8)
  52. expect(json_response['timezones']['Europe/Berlin']).to be_between(1, 2)
  53. expect(json_response['assets']).to be_truthy
  54. # timezones
  55. get '/api/v1/calendars/timezones', as: :json
  56. expect(response).to have_http_status(:ok)
  57. expect(json_response).to be_a_kind_of(Hash)
  58. expect(json_response['timezones']).to be_a_kind_of(Hash)
  59. expect(json_response['timezones']['America/New_York']).to be_truthy
  60. end
  61. end
  62. end