taskbar_spec.rb 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. require 'rails_helper'
  2. RSpec.describe 'Taskbars', type: :request do
  3. let(:agent) do
  4. create(:agent)
  5. end
  6. let(:customer) do
  7. create(:customer)
  8. end
  9. describe 'request handling' do
  10. it 'does task ownership' do
  11. params = {
  12. user_id: customer.id,
  13. client_id: '123',
  14. key: 'Ticket-5',
  15. callback: 'TicketZoom',
  16. state: {
  17. ticket: {
  18. owner_id: agent.id,
  19. },
  20. article: {},
  21. },
  22. params: {
  23. ticket_id: 5,
  24. shown: true,
  25. },
  26. prio: 3,
  27. notify: false,
  28. active: false,
  29. }
  30. authenticated_as(agent)
  31. post '/api/v1/taskbar', params: params, as: :json
  32. expect(response).to have_http_status(:created)
  33. expect(json_response).to be_a_kind_of(Hash)
  34. expect(json_response['client_id']).to eq('123')
  35. expect(json_response['user_id']).to eq(agent.id)
  36. expect(json_response['params']['ticket_id']).to eq(5)
  37. expect(json_response['params']['shown']).to eq(true)
  38. taskbar_id = json_response['id']
  39. params[:user_id] = customer.id
  40. params[:params] = {
  41. ticket_id: 5,
  42. shown: false,
  43. }
  44. put "/api/v1/taskbar/#{taskbar_id}", params: params, as: :json
  45. expect(response).to have_http_status(:ok)
  46. expect(json_response).to be_a_kind_of(Hash)
  47. expect(json_response['client_id']).to eq('123')
  48. expect(json_response['user_id']).to eq(agent.id)
  49. expect(json_response['params']['ticket_id']).to eq(5)
  50. expect(json_response['params']['shown']).to eq(false)
  51. # try to access with other user
  52. params = {
  53. active: true,
  54. }
  55. authenticated_as(customer)
  56. put "/api/v1/taskbar/#{taskbar_id}", params: params, as: :json
  57. expect(response).to have_http_status(:unprocessable_entity)
  58. expect(json_response).to be_a_kind_of(Hash)
  59. expect(json_response['error']).to eq('Not allowed to access this task.')
  60. delete "/api/v1/taskbar/#{taskbar_id}", params: {}, as: :json
  61. expect(response).to have_http_status(:unprocessable_entity)
  62. expect(json_response).to be_a_kind_of(Hash)
  63. expect(json_response['error']).to eq('Not allowed to access this task.')
  64. # delete with correct user
  65. authenticated_as(agent)
  66. delete "/api/v1/taskbar/#{taskbar_id}", params: {}, as: :json
  67. expect(response).to have_http_status(:ok)
  68. expect(json_response).to be_a_kind_of(Hash)
  69. expect(json_response).to be_blank
  70. end
  71. end
  72. end