checklist_spec.rb 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe 'Checklist', 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 list checklists', :aggregate_failures do
  19. authenticated_as(agent_1)
  20. get '/api/v1/checklists', params: {}, as: :json
  21. expect(response).to have_http_status(:ok)
  22. expect(json_response).to include(hash_including('id' => checklist_1.id))
  23. expect(json_response).not_to include(hash_including('id' => checklist_2.id))
  24. end
  25. it 'does show checklist', :aggregate_failures do
  26. authenticated_as(agent_1)
  27. get "/api/v1/checklists/#{checklist_1.id}", params: {}, as: :json
  28. expect(response).to have_http_status(:ok)
  29. expect(json_response).to include('id' => checklist_1.id)
  30. end
  31. it 'does not show checklist' do
  32. authenticated_as(agent_1)
  33. get "/api/v1/checklists/#{checklist_2.id}", params: {}, as: :json
  34. expect(response).to have_http_status(:not_found)
  35. end
  36. it 'does create checklist', :aggregate_failures do
  37. authenticated_as(agent_1)
  38. post '/api/v1/checklists', params: { name: SecureRandom.uuid, ticket_id: ticket_1_empty.id }, as: :json
  39. expect(response).to have_http_status(:created)
  40. expect(json_response).to include('id' => Checklist.last.id)
  41. end
  42. it 'does not create checklist' do
  43. authenticated_as(agent_1)
  44. post '/api/v1/checklists', params: { name: SecureRandom.uuid, ticket_id: ticket_2_empty.id }, as: :json
  45. expect(response).to have_http_status(:forbidden)
  46. end
  47. it 'does update checklist', :aggregate_failures do
  48. authenticated_as(agent_1)
  49. put "/api/v1/checklists/#{checklist_1.id}", params: { name: SecureRandom.uuid }, as: :json
  50. expect(response).to have_http_status(:ok)
  51. expect(json_response).to include('id' => checklist_1.id)
  52. end
  53. it 'does not update checklist' do
  54. authenticated_as(agent_1)
  55. put "/api/v1/checklists/#{checklist_2.id}", params: { name: SecureRandom.uuid }, as: :json
  56. expect(response).to have_http_status(:forbidden)
  57. end
  58. it 'does destroy checklist' do
  59. authenticated_as(agent_1)
  60. delete "/api/v1/checklists/#{checklist_1.id}", params: {}, as: :json
  61. expect(response).to have_http_status(:ok)
  62. end
  63. it 'does not destroy checklist' do
  64. authenticated_as(agent_1)
  65. delete "/api/v1/checklists/#{checklist_2.id}", params: {}, as: :json
  66. expect(response).to have_http_status(:forbidden)
  67. end
  68. end