taskbar_spec.rb 2.6 KB

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