delete_spec.rb 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Gql::Mutations::Ticket::SharedDraft::Zoom::Delete, :aggregate_failures, type: :graphql do
  4. let(:owner) { create(:user) }
  5. let(:ticket) { create(:ticket, owner: owner) }
  6. let(:shared_draft) { create(:ticket_shared_draft_zoom, ticket: ticket) }
  7. let(:shared_draft_id) { gql.id(shared_draft) }
  8. let(:query) do
  9. <<~QUERY
  10. mutation ticketSharedDraftZoomDelete($sharedDraftId: ID!) {
  11. ticketSharedDraftZoomDelete(sharedDraftId: $sharedDraftId) {
  12. success
  13. errors {
  14. message
  15. field
  16. }
  17. }
  18. }
  19. QUERY
  20. end
  21. before do
  22. gql.execute(query, variables: { sharedDraftId: shared_draft_id })
  23. end
  24. context 'with an agent', authenticated_as: :agent do
  25. let(:agent) { create(:agent) }
  26. context 'when agent has no permission on related ticket' do
  27. it 'raises an error' do
  28. expect(gql.result.error_type).to eq(Exceptions::Forbidden)
  29. end
  30. end
  31. context 'when agent has permission on related ticket' do
  32. let(:owner) { agent }
  33. it 'deletes the shared draft zoom' do
  34. expect { shared_draft.reload }.to raise_error(ActiveRecord::RecordNotFound)
  35. end
  36. it 'returns success' do
  37. expect(gql.result.data).to include(
  38. 'success' => true,
  39. 'errors' => be_nil
  40. )
  41. end
  42. end
  43. context 'when shared draft does not exist' do
  44. let(:shared_draft_id) do
  45. id = gql.id(shared_draft)
  46. shared_draft.destroy
  47. id
  48. end
  49. it 'raises an error' do
  50. expect(gql.result.error_type).to eq(ActiveRecord::RecordNotFound)
  51. end
  52. end
  53. end
  54. it_behaves_like 'graphql responds with error if unauthenticated'
  55. end