2018-09-19 13:54:49 +00:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
RSpec.describe 'Taskbars', type: :request do
|
|
|
|
|
2020-06-19 09:17:18 +00:00
|
|
|
let(:agent) do
|
|
|
|
create(:agent)
|
2018-09-19 13:54:49 +00:00
|
|
|
end
|
2020-06-19 09:17:18 +00:00
|
|
|
let(:customer) do
|
|
|
|
create(:customer)
|
2018-09-19 13:54:49 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'request handling' do
|
|
|
|
|
|
|
|
it 'does task ownership' do
|
|
|
|
params = {
|
2020-06-19 09:17:18 +00:00
|
|
|
user_id: customer.id,
|
2018-09-19 13:54:49 +00:00
|
|
|
client_id: '123',
|
2018-12-19 17:31:51 +00:00
|
|
|
key: 'Ticket-5',
|
|
|
|
callback: 'TicketZoom',
|
|
|
|
state: {
|
|
|
|
ticket: {
|
2020-06-19 09:17:18 +00:00
|
|
|
owner_id: agent.id,
|
2018-09-19 13:54:49 +00:00
|
|
|
},
|
|
|
|
article: {},
|
|
|
|
},
|
2018-12-19 17:31:51 +00:00
|
|
|
params: {
|
2018-09-19 13:54:49 +00:00
|
|
|
ticket_id: 5,
|
2018-12-19 17:31:51 +00:00
|
|
|
shown: true,
|
2018-09-19 13:54:49 +00:00
|
|
|
},
|
2018-12-19 17:31:51 +00:00
|
|
|
prio: 3,
|
|
|
|
notify: false,
|
|
|
|
active: false,
|
2018-09-19 13:54:49 +00:00
|
|
|
}
|
|
|
|
|
2020-06-19 09:17:18 +00:00
|
|
|
authenticated_as(agent)
|
2018-09-19 13:54:49 +00:00
|
|
|
post '/api/v1/taskbar', params: params, as: :json
|
2019-04-15 01:41:17 +00:00
|
|
|
expect(response).to have_http_status(:created)
|
2018-09-19 13:54:49 +00:00
|
|
|
expect(json_response).to be_a_kind_of(Hash)
|
|
|
|
expect(json_response['client_id']).to eq('123')
|
2020-06-19 09:17:18 +00:00
|
|
|
expect(json_response['user_id']).to eq(agent.id)
|
2018-09-19 13:54:49 +00:00
|
|
|
expect(json_response['params']['ticket_id']).to eq(5)
|
|
|
|
expect(json_response['params']['shown']).to eq(true)
|
|
|
|
|
|
|
|
taskbar_id = json_response['id']
|
2020-06-19 09:17:18 +00:00
|
|
|
params[:user_id] = customer.id
|
2018-09-19 13:54:49 +00:00
|
|
|
params[:params] = {
|
|
|
|
ticket_id: 5,
|
2018-12-19 17:31:51 +00:00
|
|
|
shown: false,
|
2018-09-19 13:54:49 +00:00
|
|
|
}
|
|
|
|
put "/api/v1/taskbar/#{taskbar_id}", params: params, as: :json
|
2019-04-15 01:41:17 +00:00
|
|
|
expect(response).to have_http_status(:ok)
|
2018-09-19 13:54:49 +00:00
|
|
|
expect(json_response).to be_a_kind_of(Hash)
|
|
|
|
expect(json_response['client_id']).to eq('123')
|
2020-06-19 09:17:18 +00:00
|
|
|
expect(json_response['user_id']).to eq(agent.id)
|
2018-09-19 13:54:49 +00:00
|
|
|
expect(json_response['params']['ticket_id']).to eq(5)
|
|
|
|
expect(json_response['params']['shown']).to eq(false)
|
|
|
|
|
|
|
|
# try to access with other user
|
|
|
|
params = {
|
|
|
|
active: true,
|
|
|
|
}
|
|
|
|
|
2020-06-19 09:17:18 +00:00
|
|
|
authenticated_as(customer)
|
2018-09-19 13:54:49 +00:00
|
|
|
put "/api/v1/taskbar/#{taskbar_id}", params: params, as: :json
|
2019-04-15 01:41:17 +00:00
|
|
|
expect(response).to have_http_status(:unprocessable_entity)
|
2018-09-19 13:54:49 +00:00
|
|
|
expect(json_response).to be_a_kind_of(Hash)
|
|
|
|
expect(json_response['error']).to eq('Not allowed to access this task.')
|
|
|
|
|
|
|
|
delete "/api/v1/taskbar/#{taskbar_id}", params: {}, as: :json
|
2019-04-15 01:41:17 +00:00
|
|
|
expect(response).to have_http_status(:unprocessable_entity)
|
2018-09-19 13:54:49 +00:00
|
|
|
expect(json_response).to be_a_kind_of(Hash)
|
|
|
|
expect(json_response['error']).to eq('Not allowed to access this task.')
|
|
|
|
|
|
|
|
# delete with correct user
|
2020-06-19 09:17:18 +00:00
|
|
|
authenticated_as(agent)
|
2018-09-19 13:54:49 +00:00
|
|
|
delete "/api/v1/taskbar/#{taskbar_id}", params: {}, as: :json
|
2019-04-15 01:41:17 +00:00
|
|
|
expect(response).to have_http_status(:ok)
|
2018-09-19 13:54:49 +00:00
|
|
|
expect(json_response).to be_a_kind_of(Hash)
|
|
|
|
expect(json_response).to be_blank
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|