checklist_spec.rb 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe 'Ticket Checklist', authenticated_as: :agent, type: :request do
  4. let(:group) { create(:group) }
  5. let(:agent) { create(:agent, groups: [group], group_names_access_map: { group.name => %w[read change] }) }
  6. let(:ticket) { create(:ticket, group: group) }
  7. describe '#show' do
  8. let(:checklist) { create(:checklist, ticket: ticket) }
  9. before do
  10. checklist
  11. get "/api/v1/tickets/#{ticket.id}/checklist"
  12. end
  13. context 'when user is not authorized' do
  14. let(:agent) { create(:agent) }
  15. it 'returns forbidden status' do
  16. expect(response).to have_http_status(:forbidden)
  17. end
  18. end
  19. context 'when user is authorized' do
  20. it 'returns ok status' do
  21. expect(response).to have_http_status(:ok)
  22. end
  23. end
  24. end
  25. describe '#create' do
  26. before do
  27. post "/api/v1/tickets/#{ticket.id}/checklist"
  28. end
  29. context 'when user is not authorized' do
  30. let(:agent) { create(:agent, groups: [group], group_names_access_map: { group.name => 'read' }) }
  31. it 'returns forbidden status' do
  32. expect(response).to have_http_status(:forbidden)
  33. end
  34. end
  35. context 'when user is authorized' do
  36. it 'returns ok status' do
  37. expect(response).to have_http_status(:ok)
  38. end
  39. end
  40. end
  41. describe '#update' do
  42. let(:checklist) { create(:checklist, ticket: ticket) }
  43. let(:checklist_params) do
  44. {
  45. name: 'foobar',
  46. }
  47. end
  48. before do
  49. checklist
  50. put "/api/v1/tickets/#{ticket.id}/checklist", params: checklist_params
  51. end
  52. context 'when user is not authorized' do
  53. let(:agent) { create(:agent, groups: [group], group_names_access_map: { group.name => 'read' }) }
  54. it 'returns forbidden status' do
  55. expect(response).to have_http_status(:forbidden)
  56. end
  57. end
  58. context 'when user is authorized' do
  59. it 'returns ok status' do
  60. expect(response).to have_http_status(:ok)
  61. end
  62. end
  63. end
  64. describe '#destroy' do
  65. let(:checklist) { create(:checklist, ticket: ticket) }
  66. before do
  67. checklist
  68. delete "/api/v1/tickets/#{ticket.id}/checklist"
  69. end
  70. context 'when user is not authorized' do
  71. let(:agent) { create(:agent, groups: [group], group_names_access_map: { group.name => 'read' }) }
  72. it 'returns forbidden status' do
  73. expect(response).to have_http_status(:forbidden)
  74. end
  75. end
  76. context 'when user is authorized' do
  77. it 'returns ok status' do
  78. expect(response).to have_http_status(:ok)
  79. end
  80. end
  81. end
  82. end