checklist_item_spec.rb 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe 'Checklist Item', 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(: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 show checklist items', :aggregate_failures do
  17. get "/api/v1/checklist_items/#{checklist_1.items.first.id}", params: {}, as: :json
  18. expect(response).to have_http_status(:ok)
  19. expect(json_response).to include('id' => checklist_1.items.first.id)
  20. end
  21. it 'does not show inaccessible checklist items' do
  22. get "/api/v1/checklist_items/#{checklist_2.items.first.id}", params: {}, as: :json
  23. expect(response).to have_http_status(:forbidden)
  24. end
  25. it 'does not show nonexistant checklist items' do
  26. get '/api/v1/checklist_items/1234', params: {}, as: :json
  27. expect(response).to have_http_status(:forbidden)
  28. end
  29. it 'does create checklist items', :aggregate_failures do
  30. post '/api/v1/checklist_items', params: { checklist_id: checklist_1.id, text: SecureRandom.uuid }, as: :json
  31. expect(response).to have_http_status(:created)
  32. expect(json_response).to include('id' => Checklist::Item.last.id)
  33. end
  34. it 'does not create checklist items' do
  35. post '/api/v1/checklist_items', params: { checklist_id: checklist_2.id, text: SecureRandom.uuid }, as: :json
  36. expect(response).to have_http_status(:forbidden)
  37. end
  38. it 'does update checklist items', :aggregate_failures do
  39. put "/api/v1/checklist_items/#{checklist_1.items.first.id}", params: { id: checklist_1.items.first.id, text: SecureRandom.uuid }, as: :json
  40. expect(response).to have_http_status(:ok)
  41. expect(json_response).to include('id' => checklist_1.items.first.id)
  42. end
  43. it 'does not update checklist items' do
  44. put "/api/v1/checklist_items/#{checklist_2.items.first.id}", params: { id: checklist_2.items.first.id, text: SecureRandom.uuid }, as: :json
  45. expect(response).to have_http_status(:forbidden)
  46. end
  47. it 'does destroy checklist items' do
  48. delete "/api/v1/checklist_items/#{checklist_1.items.first.id}", params: {}, as: :json
  49. expect(response).to have_http_status(:ok)
  50. end
  51. it 'does not destroy checklist items' do
  52. delete "/api/v1/checklist_items/#{checklist_2.items.first.id}", params: {}, as: :json
  53. expect(response).to have_http_status(:forbidden)
  54. end
  55. end