tickets_mass_spec.rb 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe 'TicketsMass', authenticated_as: :user, type: :request do
  4. let(:user) { create(:agent, groups: [group_a, group_b]) }
  5. let(:owner) { create(:agent) }
  6. let(:group_a) { create(:group) }
  7. let(:group_b) { create(:group) }
  8. let(:group_c) { create(:group) }
  9. let(:ticket_a) { create(:ticket, group: group_a, owner: owner) }
  10. let(:ticket_b) { create(:ticket, group: group_b, owner: owner) }
  11. let(:ticket_c) { create(:ticket, group: group_c, owner: owner) }
  12. let(:core_workflow) do
  13. create(:core_workflow, :active_and_screen, :condition_group, :perform_action, group: group_b)
  14. end
  15. describe 'POST /tickets/mass_macro' do
  16. let(:macro_perform) do
  17. {
  18. 'ticket.priority_id': { pre_condition: 'specific', value: 3.to_s }
  19. }
  20. end
  21. let(:macro) { create(:macro, perform: macro_perform) }
  22. let(:macro_groups) { create(:macro, groups: [group_a], perform: macro_perform) }
  23. it 'applies macro' do
  24. post '/api/v1/tickets/mass_macro', params: { macro_id: macro.id, ticket_ids: [ticket_a.id] }
  25. expect(ticket_a.reload.priority_id).to eq 3
  26. end
  27. it 'does not apply changes if one of ticket updates fail' do
  28. core_workflow
  29. post '/api/v1/tickets/mass_macro', params: { macro_id: macro.id, ticket_ids: [ticket_a.id, ticket_b.id] }, as: :json
  30. expect(ticket_a.reload.articles).not_to eq 3
  31. end
  32. it 'returns error if macro not applicable to at least one ticket' do
  33. post '/api/v1/tickets/mass_macro', params: { macro_id: macro_groups.id, ticket_ids: [ticket_a.id, ticket_b.id] }
  34. expect(response).to have_http_status(:unprocessable_entity)
  35. end
  36. it 'checks if user has write access to tickets' do
  37. post '/api/v1/tickets/mass_macro', params: { macro_id: macro_groups.id, ticket_ids: [ticket_a.id, ticket_c.id] }
  38. expect(response).to have_http_status(:unprocessable_entity)
  39. end
  40. end
  41. describe 'POST /tickets/mass_update' do
  42. it 'applies changes' do
  43. post '/api/v1/tickets/mass_update', params: { attributes: { priority_id: 3 }, ticket_ids: [ticket_a.id] }
  44. expect(ticket_a.reload.priority_id).to eq 3
  45. end
  46. it 'does not apply changes' do
  47. post '/api/v1/tickets/mass_update', params: { attributes: { priority_id: 3 }, ticket_ids: [ticket_c.id] }
  48. expect(ticket_c.reload.priority_id).not_to eq 3
  49. end
  50. it 'adds note' do
  51. post '/api/v1/tickets/mass_update', params: { attributes: {}, article: { body: 'test mass update body' }, ticket_ids: [ticket_a.id] }
  52. expect(ticket_a.reload.articles.last).to have_attributes(body: 'test mass update body')
  53. end
  54. it 'does not apply changes if one of ticket updates fail' do
  55. core_workflow
  56. post '/api/v1/tickets/mass_update', params: { attributes: { priority_id: 3 }, ticket_ids: [ticket_a.id, ticket_b.id] }
  57. expect(ticket_a.reload.priority_id).not_to eq 3
  58. end
  59. it 'checks if user has write access to tickets' do
  60. post '/api/v1/tickets/mass_update', params: { attributes: { priority_id: 3 }, ticket_ids: [ticket_a.id, ticket_c.id] }
  61. expect(response).to have_http_status(:unprocessable_entity)
  62. end
  63. end
  64. end