checklist_item_spec.rb 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe 'Checklist Item', 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(:checklist_1) { create(:checklist, ticket: ticket_1) }
  10. let(:checklist_2) { create(:checklist, ticket: ticket_2) }
  11. before do
  12. Setting.set('checklist', true)
  13. checklist_1
  14. checklist_2
  15. end
  16. it 'does list checklist items', :aggregate_failures do
  17. authenticated_as(agent_1)
  18. get '/api/v1/checklist_items', params: {}, as: :json
  19. expect(response).to have_http_status(:ok)
  20. expect(json_response).to include(hash_including('id' => checklist_1.items.first.id))
  21. expect(json_response).not_to include(hash_including('id' => checklist_2.items.first.id))
  22. end
  23. it 'does show checklist items', :aggregate_failures do
  24. authenticated_as(agent_1)
  25. get "/api/v1/checklist_items/#{checklist_1.items.first.id}", params: {}, as: :json
  26. expect(response).to have_http_status(:ok)
  27. expect(json_response).to include('id' => checklist_1.items.first.id)
  28. end
  29. it 'does not show checklist items' do
  30. authenticated_as(agent_1)
  31. get "/api/v1/checklist_items/#{checklist_2.items.first.id}", params: {}, as: :json
  32. expect(response).to have_http_status(:not_found)
  33. end
  34. it 'does create checklist items', :aggregate_failures do
  35. authenticated_as(agent_1)
  36. post '/api/v1/checklist_items', params: { checklist_id: checklist_1.id, text: SecureRandom.uuid }, as: :json
  37. expect(response).to have_http_status(:created)
  38. expect(json_response).to include('id' => Checklist::Item.last.id)
  39. end
  40. it 'does not create checklist items' do
  41. authenticated_as(agent_1)
  42. post '/api/v1/checklist_items', params: { checklist_id: checklist_2.id, text: SecureRandom.uuid }, as: :json
  43. expect(response).to have_http_status(:forbidden)
  44. end
  45. it 'does update checklist items', :aggregate_failures do
  46. authenticated_as(agent_1)
  47. put "/api/v1/checklist_items/#{checklist_1.items.first.id}", params: { id: checklist_1.items.first.id, text: SecureRandom.uuid }, as: :json
  48. expect(response).to have_http_status(:ok)
  49. expect(json_response).to include('id' => checklist_1.items.first.id)
  50. end
  51. it 'does not update checklist items' do
  52. authenticated_as(agent_1)
  53. put "/api/v1/checklist_items/#{checklist_2.items.first.id}", params: { id: checklist_2.items.first.id, text: SecureRandom.uuid }, as: :json
  54. expect(response).to have_http_status(:forbidden)
  55. end
  56. it 'does destroy checklist items' do
  57. authenticated_as(agent_1)
  58. delete "/api/v1/checklist_items/#{checklist_1.items.first.id}", params: {}, as: :json
  59. expect(response).to have_http_status(:ok)
  60. end
  61. it 'does not destroy checklist items' do
  62. authenticated_as(agent_1)
  63. delete "/api/v1/checklist_items/#{checklist_2.items.first.id}", params: {}, as: :json
  64. expect(response).to have_http_status(:forbidden)
  65. end
  66. end