delete_spec.rb 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Gql::Mutations::Ticket::Checklist::Delete, type: :graphql do
  4. let(:group) { create(:group) }
  5. let(:agent) { create(:agent, groups: [group]) }
  6. let(:ticket) { create(:ticket, group: group) }
  7. let(:checklist) { create(:checklist, ticket: ticket) }
  8. let(:query) do
  9. <<~QUERY
  10. mutation ticketChecklistDelete($checklistId: ID!) {
  11. ticketChecklistDelete(checklistId: $checklistId) {
  12. success
  13. errors {
  14. message
  15. }
  16. }
  17. }
  18. QUERY
  19. end
  20. let(:variables) { { checklistId: gql.id(checklist) } }
  21. before do
  22. gql.execute(query, variables: variables)
  23. end
  24. shared_examples 'deleting the ticket checklist' do
  25. it 'deletes the ticket checklist' do
  26. expect(gql.result.data['success']).to be(true)
  27. end
  28. end
  29. shared_examples 'raising an error' do |error_type|
  30. it 'raises an error' do
  31. expect(gql.result.error_type).to eq(error_type)
  32. end
  33. end
  34. context 'with authenticated session', authenticated_as: :agent do
  35. it_behaves_like 'deleting the ticket checklist'
  36. context 'without access to the ticket' do
  37. let(:agent) { create(:agent) }
  38. it_behaves_like 'raising an error', Pundit::NotAuthorizedError
  39. end
  40. context 'with ticket read permission' do
  41. let(:agent) { create(:agent, groups: [group], group_names_access_map: { group.name => 'read' }) }
  42. it_behaves_like 'raising an error', Pundit::NotAuthorizedError
  43. end
  44. context 'with ticket read+change permissions' do
  45. let(:agent) { create(:agent, groups: [group], group_names_access_map: { group.name => %w[read change] }) }
  46. it_behaves_like 'deleting the ticket checklist'
  47. end
  48. context 'when ticket checklist does not exist' do
  49. let(:variables) { { checklistId: 'gid://Zammad/Checklist/0' } }
  50. it_behaves_like 'raising an error', ActiveRecord::RecordNotFound
  51. end
  52. end
  53. it_behaves_like 'graphql responds with error if unauthenticated'
  54. end