checklist_spec.rb 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe 'Checklist', authenticated_as: :agent_1, current_user_id: 1, type: :request do
  4. let(:group_1) { create(:group) }
  5. let(:group_2) { create(:group) }
  6. let(:agent_1) { create(:agent, groups: [group_1]) }
  7. let(:ticket_1) { create(:ticket, group: group_1) }
  8. let(:ticket_2) { create(:ticket, group: group_2) }
  9. let(:ticket_1_empty) { create(:ticket, group: group_1) }
  10. let(:ticket_2_empty) { create(:ticket, group: group_2) }
  11. let(:checklist_1) { create(:checklist, ticket: ticket_1) }
  12. let(:checklist_2) { create(:checklist, ticket: ticket_2) }
  13. before do
  14. Setting.set('checklist', true)
  15. checklist_1
  16. checklist_2
  17. end
  18. it 'does show checklist', :aggregate_failures do
  19. get "/api/v1/checklists/#{checklist_1.id}", params: {}, as: :json
  20. expect(response).to have_http_status(:ok)
  21. expect(json_response).to include('id' => checklist_1.id)
  22. end
  23. it 'does not show inaccessible checklist' do
  24. get "/api/v1/checklists/#{checklist_2.id}", params: {}, as: :json
  25. expect(response).to have_http_status(:forbidden)
  26. end
  27. it 'does not show nonexistant checklist' do
  28. get '/api/v1/checklists/1234', params: {}, as: :json
  29. expect(response).to have_http_status(:forbidden)
  30. end
  31. it 'does create checklist', :aggregate_failures do
  32. post '/api/v1/checklists', params: { name: SecureRandom.uuid, ticket_id: ticket_1_empty.id }, as: :json
  33. expect(response).to have_http_status(:created)
  34. expect(json_response).to include('id' => Checklist.last.id)
  35. end
  36. it 'does not create checklist' do
  37. post '/api/v1/checklists', params: { name: SecureRandom.uuid, ticket_id: ticket_2_empty.id }, as: :json
  38. expect(response).to have_http_status(:forbidden)
  39. end
  40. it 'does update checklist', :aggregate_failures do
  41. put "/api/v1/checklists/#{checklist_1.id}", params: { name: SecureRandom.uuid }, as: :json
  42. expect(response).to have_http_status(:ok)
  43. expect(json_response).to include('id' => checklist_1.id)
  44. end
  45. it 'does not update checklist' do
  46. put "/api/v1/checklists/#{checklist_2.id}", params: { name: SecureRandom.uuid }, as: :json
  47. expect(response).to have_http_status(:forbidden)
  48. end
  49. it 'does destroy checklist' do
  50. delete "/api/v1/checklists/#{checklist_1.id}", params: {}, as: :json
  51. expect(response).to have_http_status(:ok)
  52. end
  53. it 'does not destroy checklist' do
  54. delete "/api/v1/checklists/#{checklist_2.id}", params: {}, as: :json
  55. expect(response).to have_http_status(:forbidden)
  56. end
  57. end