overview_spec.rb 5.7 KB

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