delete_spec.rb 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Gql::Mutations::Ticket::Checklist::Delete, current_user_id: 1, 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. setup if defined?(setup)
  23. gql.execute(query, variables: variables)
  24. end
  25. shared_examples 'deleting the ticket checklist' do
  26. it 'deletes the ticket checklist' do
  27. expect(gql.result.data[:success]).to be(true)
  28. end
  29. end
  30. shared_examples 'raising an error' do |error_type|
  31. it 'raises an error' do
  32. expect(gql.result.error_type).to eq(error_type)
  33. end
  34. end
  35. context 'with authenticated session', authenticated_as: :agent do
  36. it_behaves_like 'deleting the ticket checklist'
  37. context 'with disabled checklist feature' do
  38. let(:setup) do
  39. Setting.set('checklist', false)
  40. end
  41. it_behaves_like 'raising an error', Exceptions::Forbidden
  42. end
  43. context 'without access to the ticket' do
  44. let(:agent) { create(:agent) }
  45. it_behaves_like 'raising an error', Exceptions::Forbidden
  46. end
  47. context 'with ticket read permission' do
  48. let(:agent) { create(:agent, groups: [group], group_names_access_map: { group.name => 'read' }) }
  49. it_behaves_like 'raising an error', Pundit::NotAuthorizedError
  50. end
  51. context 'with ticket read+change permissions' do
  52. let(:agent) { create(:agent, groups: [group], group_names_access_map: { group.name => %w[read change] }) }
  53. it_behaves_like 'deleting the ticket checklist'
  54. end
  55. context 'when ticket checklist does not exist' do
  56. let(:variables) { { checklistId: 'gid://Zammad/Checklist/0' } }
  57. it_behaves_like 'raising an error', ActiveRecord::RecordNotFound
  58. end
  59. end
  60. it_behaves_like 'graphql responds with error if unauthenticated'
  61. end