calendar_subscriptions_spec.rb 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe 'iCal endpoints', type: :request do
  4. context 'with no existing session' do
  5. it 'gives HTTP Basic auth prompt (#3064)' do
  6. get '/ical/tickets'
  7. expect(response.body).to eq("HTTP Basic: Access denied.\n")
  8. end
  9. end
  10. describe 'time zone', authenticated_as: :user do
  11. let(:group) { create(:group) }
  12. let(:user) { create(:agent) }
  13. before do
  14. user.groups << group
  15. create(:ticket, group: group, owner: user, state_name: 'open', pending_time: 1.day.ago)
  16. end
  17. it 'returns zero offset time if no time zone set' do
  18. get '/ical/tickets'
  19. expect(response.body).to match %r{DTSTART:\d{8}T0{6}Z}
  20. end
  21. it 'returns selected time zone' do
  22. Setting.set 'timezone_default', 'Europe/Vilnius'
  23. get '/ical/tickets'
  24. expect(response.body).to match %r{DTSTART;TZID=Europe/Vilnius:\d{8}T0{6}}
  25. end
  26. end
  27. # https://github.com/zammad/zammad/issues/3962
  28. context 'with request method PROPFIND', authenticated_as: :user do
  29. let(:user) { create(:agent) }
  30. it 'contains correct request method' do
  31. get '/ical/tickets', headers: { 'REQUEST_METHOD' => 'PROPFIND' }
  32. expect(response.request.request_method).to eq('PROPFIND')
  33. end
  34. it 'returns the desired calendar file' do
  35. get '/ical/tickets', headers: { 'REQUEST_METHOD' => 'PROPFIND' }
  36. expect(response.body).to match(%r{BEGIN:VCALENDAR})
  37. end
  38. end
  39. describe 'methods', authenticated_as: :user do
  40. let(:group) { create(:group) }
  41. let(:user) { create(:agent) }
  42. let(:ticket_1) { create(:ticket, title: SecureRandom.uuid, group: group, owner: user, state_name: 'open') }
  43. let(:ticket_2) { create(:ticket, title: SecureRandom.uuid, group: group, owner: user, state_name: 'pending reminder', pending_time: 1.day.from_now) }
  44. before do
  45. user.groups << group
  46. ticket_1
  47. ticket_2
  48. end
  49. it 'returns open tickets', :aggregate_failures do
  50. get '/ical/tickets/new_open'
  51. expect(response.body).to include(ticket_1.title)
  52. expect(response.body).not_to include(ticket_2.title)
  53. end
  54. it 'returns pending tickets', :aggregate_failures do
  55. get '/ical/tickets/pending'
  56. expect(response.body).not_to include(ticket_1.title)
  57. expect(response.body).to include(ticket_2.title)
  58. end
  59. it 'raises error on unknown method', :aggregate_failures do
  60. get '/ical/tickets/xxx'
  61. expect(json_response['error']).to eq('An unknown method name was requested.')
  62. expect(response).to have_http_status(:unprocessable_entity)
  63. end
  64. end
  65. end