checklist_items_spec.rb 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe 'Ticket Checklist Items', 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 '#create' do
  8. let(:checklist) { create(:checklist, ticket: ticket) }
  9. let(:checklist_item_params) do
  10. {
  11. text: 'foobar',
  12. }
  13. end
  14. before do
  15. checklist
  16. post "/api/v1/tickets/#{ticket.id}/checklist/items", params: checklist_item_params
  17. end
  18. context 'when user is not authorized' do
  19. let(:agent) { create(:agent, groups: [group], group_names_access_map: { group.name => 'read' }) }
  20. it 'returns forbidden status' do
  21. expect(response).to have_http_status(:forbidden)
  22. end
  23. end
  24. context 'when user is authorized' do
  25. it 'returns ok status' do
  26. expect(response).to have_http_status(:ok)
  27. end
  28. end
  29. end
  30. describe '#update' do
  31. let(:checklist) { create(:checklist, ticket: ticket) }
  32. let(:checklist_item_params) do
  33. {
  34. checked: true,
  35. }
  36. end
  37. before do
  38. put "/api/v1/tickets/#{ticket.id}/checklist/items/#{checklist.items.last.id}", params: checklist_item_params
  39. end
  40. context 'when user is not authorized' do
  41. let(:agent) { create(:agent, groups: [group], group_names_access_map: { group.name => 'read' }) }
  42. it 'returns forbidden status' do
  43. expect(response).to have_http_status(:forbidden)
  44. end
  45. end
  46. context 'when user is authorized' do
  47. it 'returns ok status' do
  48. expect(response).to have_http_status(:ok)
  49. end
  50. end
  51. end
  52. describe '#destroy' do
  53. let(:checklist) { create(:checklist, ticket: ticket) }
  54. before do
  55. delete "/api/v1/tickets/#{ticket.id}/checklist/items/#{checklist.items.last.id}"
  56. end
  57. context 'when user is not authorized' do
  58. let(:agent) { create(:agent, groups: [group], group_names_access_map: { group.name => 'read' }) }
  59. it 'returns forbidden status' do
  60. expect(response).to have_http_status(:forbidden)
  61. end
  62. end
  63. context 'when user is authorized' do
  64. it 'returns ok status' do
  65. expect(response).to have_http_status(:ok)
  66. end
  67. end
  68. end
  69. end