single_spec.rb 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Gql::Queries::Ticket::SharedDraft::Start::Single, type: :graphql do
  4. let(:group) { create(:group) }
  5. let(:shared_draft) { create(:ticket_shared_draft_start, group:) }
  6. let(:variables) { { sharedDraftId: gql.id(shared_draft) } }
  7. let(:query) do
  8. <<~QUERY
  9. query ticketSharedDraftStartSingle($sharedDraftId: ID!) {
  10. ticketSharedDraftStartSingle(sharedDraftId: $sharedDraftId) {
  11. id
  12. name
  13. }
  14. }
  15. QUERY
  16. end
  17. before do
  18. gql.execute(query, variables: variables)
  19. end
  20. context 'with an agent', authenticated_as: :agent do
  21. let(:access) { :create }
  22. let(:agent) do
  23. create(:agent)
  24. .tap { |elem| elem.user_groups.create!(group:, access:) if access }
  25. end
  26. context 'when agent has access to the draft group' do
  27. it 'returns the shared draft' do
  28. expect(gql.result.data).to include('id' => gql.id(shared_draft))
  29. end
  30. end
  31. context 'when agent has insufficient access to the given group' do
  32. let(:access) { 'read' }
  33. it 'raises an error' do
  34. expect(gql.result.error_type).to eq(Exceptions::Forbidden)
  35. end
  36. end
  37. context 'when agent has no access to the given group' do
  38. let(:access) { false }
  39. it 'raises an error' do
  40. expect(gql.result.error_type).to eq(Exceptions::Forbidden)
  41. end
  42. end
  43. end
  44. it_behaves_like 'graphql responds with error if unauthenticated'
  45. end