events_spec.rb 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Gql::Queries::Calendar::IcsFile::Events, authenticated_as: :user, type: :graphql do
  4. let(:query) do
  5. <<~QUERY
  6. query calendarIcsFileEvents($fileId: ID!) {
  7. calendarIcsFileEvents(fileId: $fileId) {
  8. title
  9. location
  10. startDate
  11. endDate
  12. organizer
  13. attendees
  14. description
  15. }
  16. }
  17. QUERY
  18. end
  19. let(:ticket) { create(:ticket) }
  20. let(:calendar_file) { create(:store, :ics, object: 'Ticket', o_id: ticket.id) }
  21. let(:variables) { { fileId: gql.id(calendar_file) } }
  22. before do
  23. gql.execute(query, variables: variables)
  24. end
  25. context 'when an agent is fetching events from an ICS file' do
  26. let(:user) { create(:agent, groups: [ticket.group]) }
  27. it 'returns the events' do
  28. expect(gql.result.data).to eq(
  29. [{
  30. 'title' => 'Test Summary',
  31. 'location' => 'https://us.zoom.us/j/example?pwd=test',
  32. 'startDate' => '2021-07-27T10:30:00+02:00',
  33. 'endDate' => '2021-07-27T12:00:00+02:00',
  34. 'attendees' => ['M.bob@example.com', 'J.doe@example.com'],
  35. 'organizer' => 'f.sample@example.com',
  36. 'description' => 'Test description'
  37. }],
  38. )
  39. end
  40. context 'when the agent has no permission to access the ticket' do
  41. let(:user) { create(:agent, groups: []) }
  42. it 'returns an error' do
  43. expect(gql.result.error_type).to eq(Exceptions::Forbidden)
  44. end
  45. end
  46. end
  47. context 'when not authenticated' do
  48. let(:user) { nil }
  49. it_behaves_like 'graphql responds with error if unauthenticated'
  50. end
  51. end