show_spec.rb 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Gql::Queries::Ticket::SharedDraft::Zoom::Show, type: :graphql do
  4. let(:owner) { create(:user) }
  5. let(:ticket) { create(:ticket, owner: owner) }
  6. let(:shared_draft_zoom) { create(:ticket_shared_draft_zoom, ticket: ticket) }
  7. let(:variables) { { sharedDraftId: gql.id(shared_draft_zoom) } }
  8. let(:query) do
  9. <<~QUERY
  10. query ticketSharedDraftZoomShow($sharedDraftId: ID!) {
  11. ticketSharedDraftZoomShow(sharedDraftId: $sharedDraftId) {
  12. id
  13. ticketId
  14. newArticle
  15. ticketAttributes
  16. }
  17. }
  18. QUERY
  19. end
  20. before do
  21. gql.execute(query, variables: variables)
  22. end
  23. context 'with an agent', authenticated_as: :agent do
  24. let(:agent) { create(:agent) }
  25. context 'when agent has no permission on related ticket' do
  26. it 'raises an error' do
  27. expect(gql.result.error_type).to eq(Exceptions::Forbidden)
  28. end
  29. end
  30. context 'when agent has permission on related ticket' do
  31. let(:owner) { agent }
  32. it 'returns the shared draft zoom' do
  33. expect(gql.result.data).to include(
  34. 'id' => gql.id(shared_draft_zoom),
  35. 'ticketId' => gql.id(shared_draft_zoom.ticket),
  36. 'newArticle' => shared_draft_zoom.new_article.merge('body' => ''),
  37. 'ticketAttributes' => shared_draft_zoom.ticket_attributes
  38. )
  39. end
  40. end
  41. end
  42. it_behaves_like 'graphql responds with error if unauthenticated'
  43. end