overview_spec.rb 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. # Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe 'Overviews', type: :request do
  4. let(:admin) do
  5. create(:admin)
  6. end
  7. describe 'request handling' do
  8. it 'does return no permissions' do
  9. params = {
  10. name: 'Overview2',
  11. link: 'my_overview',
  12. roles: Role.where(name: 'Agent').pluck(:name),
  13. condition: {
  14. 'ticket.state_id' => {
  15. operator: 'is',
  16. value: [1, 2, 3],
  17. },
  18. },
  19. order: {
  20. by: 'created_at',
  21. direction: 'DESC',
  22. },
  23. view: {
  24. d: %w[title customer state created_at],
  25. s: %w[number title customer state created_at],
  26. m: %w[number title customer state created_at],
  27. view_mode_default: 's',
  28. },
  29. }
  30. agent = create(:agent, password: 'we need a password here')
  31. authenticated_as(agent, password: 'wrong password')
  32. post '/api/v1/overviews', params: params, as: :json
  33. expect(response).to have_http_status(:unauthorized)
  34. expect(json_response).to be_a(Hash)
  35. expect(json_response['error']).to eq('Invalid BasicAuth credentials')
  36. end
  37. it 'does create overviews' do
  38. params = {
  39. name: 'Overview2',
  40. link: 'my_overview',
  41. roles: Role.where(name: 'Agent').pluck(:name),
  42. condition: {
  43. 'ticket.state_id' => {
  44. operator: 'is',
  45. value: [1, 2, 3],
  46. },
  47. },
  48. order: {
  49. by: 'created_at',
  50. direction: 'DESC',
  51. },
  52. view: {
  53. d: %w[title customer state created_at],
  54. s: %w[number title customer state created_at],
  55. m: %w[number title customer state created_at],
  56. view_mode_default: 's',
  57. },
  58. }
  59. authenticated_as(admin)
  60. post '/api/v1/overviews', params: params, as: :json
  61. expect(response).to have_http_status(:created)
  62. expect(json_response).to be_a(Hash)
  63. expect(json_response['name']).to eq('Overview2')
  64. expect(json_response['link']).to eq('my_overview')
  65. post '/api/v1/overviews', params: params, as: :json
  66. expect(response).to have_http_status(:created)
  67. expect(json_response).to be_a(Hash)
  68. expect(json_response['name']).to eq('Overview2')
  69. expect(json_response['link']).to eq('my_overview_1')
  70. end
  71. it 'does set mass prio' do
  72. roles = Role.where(name: 'Agent')
  73. overview1 = Overview.create!(
  74. name: 'Overview1',
  75. link: 'my_overview',
  76. roles: roles,
  77. condition: {
  78. 'ticket.state_id' => {
  79. operator: 'is',
  80. value: [1, 2, 3],
  81. },
  82. },
  83. order: {
  84. by: 'created_at',
  85. direction: 'DESC',
  86. },
  87. view: {
  88. d: %w[title customer state created_at],
  89. s: %w[number title customer state created_at],
  90. m: %w[number title customer state created_at],
  91. view_mode_default: 's',
  92. },
  93. prio: 1,
  94. updated_by_id: 1,
  95. created_by_id: 1,
  96. )
  97. overview2 = Overview.create!(
  98. name: 'Overview2',
  99. link: 'my_overview',
  100. roles: roles,
  101. condition: {
  102. 'ticket.state_id' => {
  103. operator: 'is',
  104. value: [1, 2, 3],
  105. },
  106. },
  107. order: {
  108. by: 'created_at',
  109. direction: 'DESC',
  110. },
  111. view: {
  112. d: %w[title customer state created_at],
  113. s: %w[number title customer state created_at],
  114. m: %w[number title customer state created_at],
  115. view_mode_default: 's',
  116. },
  117. prio: 2,
  118. updated_by_id: 1,
  119. created_by_id: 1,
  120. )
  121. params = {
  122. prios: [
  123. [overview2.id, 1],
  124. [overview1.id, 2],
  125. ]
  126. }
  127. authenticated_as(admin)
  128. post '/api/v1/overviews_prio', params: params, as: :json
  129. expect(response).to have_http_status(:ok)
  130. expect(json_response).to be_a(Hash)
  131. expect(json_response['success']).to be(true)
  132. overview1.reload
  133. overview2.reload
  134. expect(overview1.prio).to eq(2)
  135. expect(overview2.prio).to eq(1)
  136. end
  137. it 'does create an overview with group_by direction' do
  138. params = {
  139. name: 'Overview2',
  140. link: 'my_overview',
  141. roles: Role.where(name: 'Agent').pluck(:name),
  142. condition: {
  143. 'ticket.state_id' => {
  144. operator: 'is',
  145. value: [1, 2, 3],
  146. },
  147. },
  148. order: {
  149. by: 'created_at',
  150. direction: 'DESC',
  151. },
  152. group_by: 'priority',
  153. group_direction: 'ASC',
  154. view: {
  155. d: %w[title customer state created_at],
  156. s: %w[number title customer state created_at],
  157. m: %w[number title customer state created_at],
  158. view_mode_default: 's',
  159. },
  160. }
  161. authenticated_as(admin)
  162. post '/api/v1/overviews', params: params, as: :json
  163. expect(response).to have_http_status(:created)
  164. expect(json_response).to be_a(Hash)
  165. expect(json_response['name']).to eq('Overview2')
  166. expect(json_response['link']).to eq('my_overview')
  167. expect(json_response['group_by']).to eq('priority')
  168. expect(json_response['group_direction']).to eq('ASC')
  169. end
  170. end
  171. end