2018-09-19 13:54:49 +00:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
RSpec.describe 'Overviews', type: :request do
|
|
|
|
|
|
|
|
let(:admin_user) do
|
|
|
|
create(:admin_user)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'request handling' do
|
|
|
|
|
|
|
|
it 'does return no permissions' do
|
|
|
|
params = {
|
2018-12-19 17:31:51 +00:00
|
|
|
name: 'Overview2',
|
|
|
|
link: 'my_overview',
|
|
|
|
roles: Role.where(name: 'Agent').pluck(:name),
|
2018-09-19 13:54:49 +00:00
|
|
|
condition: {
|
|
|
|
'ticket.state_id' => {
|
|
|
|
operator: 'is',
|
2018-12-19 17:31:51 +00:00
|
|
|
value: [1, 2, 3],
|
2018-09-19 13:54:49 +00:00
|
|
|
},
|
|
|
|
},
|
2018-12-19 17:31:51 +00:00
|
|
|
order: {
|
|
|
|
by: 'created_at',
|
2018-09-19 13:54:49 +00:00
|
|
|
direction: 'DESC',
|
|
|
|
},
|
2018-12-19 17:31:51 +00:00
|
|
|
view: {
|
|
|
|
d: %w[title customer state created_at],
|
|
|
|
s: %w[number title customer state created_at],
|
|
|
|
m: %w[number title customer state created_at],
|
2018-09-19 13:54:49 +00:00
|
|
|
view_mode_default: 's',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
agent_user = create(:agent_user, password: 'we need a password here')
|
|
|
|
|
|
|
|
authenticated_as(agent_user)
|
|
|
|
post '/api/v1/overviews', params: params, as: :json
|
|
|
|
expect(response).to have_http_status(401)
|
|
|
|
expect(json_response).to be_a_kind_of(Hash)
|
|
|
|
expect(json_response['error']).to eq('authentication failed')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does create overviews' do
|
|
|
|
params = {
|
2018-12-19 17:31:51 +00:00
|
|
|
name: 'Overview2',
|
|
|
|
link: 'my_overview',
|
|
|
|
roles: Role.where(name: 'Agent').pluck(:name),
|
2018-09-19 13:54:49 +00:00
|
|
|
condition: {
|
|
|
|
'ticket.state_id' => {
|
|
|
|
operator: 'is',
|
2018-12-19 17:31:51 +00:00
|
|
|
value: [1, 2, 3],
|
2018-09-19 13:54:49 +00:00
|
|
|
},
|
|
|
|
},
|
2018-12-19 17:31:51 +00:00
|
|
|
order: {
|
|
|
|
by: 'created_at',
|
2018-09-19 13:54:49 +00:00
|
|
|
direction: 'DESC',
|
|
|
|
},
|
2018-12-19 17:31:51 +00:00
|
|
|
view: {
|
|
|
|
d: %w[title customer state created_at],
|
|
|
|
s: %w[number title customer state created_at],
|
|
|
|
m: %w[number title customer state created_at],
|
2018-09-19 13:54:49 +00:00
|
|
|
view_mode_default: 's',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
authenticated_as(admin_user)
|
|
|
|
post '/api/v1/overviews', params: params, as: :json
|
|
|
|
expect(response).to have_http_status(201)
|
|
|
|
expect(json_response).to be_a_kind_of(Hash)
|
|
|
|
expect(json_response['name']).to eq('Overview2')
|
|
|
|
expect(json_response['link']).to eq('my_overview')
|
|
|
|
|
|
|
|
post '/api/v1/overviews', params: params, as: :json
|
|
|
|
expect(response).to have_http_status(201)
|
|
|
|
expect(json_response).to be_a_kind_of(Hash)
|
|
|
|
expect(json_response['name']).to eq('Overview2')
|
|
|
|
expect(json_response['link']).to eq('my_overview_1')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does set mass prio' do
|
|
|
|
roles = Role.where(name: 'Agent')
|
|
|
|
overview1 = Overview.create!(
|
2018-12-19 17:31:51 +00:00
|
|
|
name: 'Overview1',
|
|
|
|
link: 'my_overview',
|
|
|
|
roles: roles,
|
|
|
|
condition: {
|
2018-09-19 13:54:49 +00:00
|
|
|
'ticket.state_id' => {
|
|
|
|
operator: 'is',
|
2018-12-19 17:31:51 +00:00
|
|
|
value: [1, 2, 3],
|
2018-09-19 13:54:49 +00:00
|
|
|
},
|
|
|
|
},
|
2018-12-19 17:31:51 +00:00
|
|
|
order: {
|
|
|
|
by: 'created_at',
|
2018-09-19 13:54:49 +00:00
|
|
|
direction: 'DESC',
|
|
|
|
},
|
2018-12-19 17:31:51 +00:00
|
|
|
view: {
|
|
|
|
d: %w[title customer state created_at],
|
|
|
|
s: %w[number title customer state created_at],
|
|
|
|
m: %w[number title customer state created_at],
|
2018-09-19 13:54:49 +00:00
|
|
|
view_mode_default: 's',
|
|
|
|
},
|
2018-12-19 17:31:51 +00:00
|
|
|
prio: 1,
|
2018-09-19 13:54:49 +00:00
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1,
|
|
|
|
)
|
|
|
|
overview2 = Overview.create!(
|
2018-12-19 17:31:51 +00:00
|
|
|
name: 'Overview2',
|
|
|
|
link: 'my_overview',
|
|
|
|
roles: roles,
|
|
|
|
condition: {
|
2018-09-19 13:54:49 +00:00
|
|
|
'ticket.state_id' => {
|
|
|
|
operator: 'is',
|
2018-12-19 17:31:51 +00:00
|
|
|
value: [1, 2, 3],
|
2018-09-19 13:54:49 +00:00
|
|
|
},
|
|
|
|
},
|
2018-12-19 17:31:51 +00:00
|
|
|
order: {
|
|
|
|
by: 'created_at',
|
2018-09-19 13:54:49 +00:00
|
|
|
direction: 'DESC',
|
|
|
|
},
|
2018-12-19 17:31:51 +00:00
|
|
|
view: {
|
|
|
|
d: %w[title customer state created_at],
|
|
|
|
s: %w[number title customer state created_at],
|
|
|
|
m: %w[number title customer state created_at],
|
2018-09-19 13:54:49 +00:00
|
|
|
view_mode_default: 's',
|
|
|
|
},
|
2018-12-19 17:31:51 +00:00
|
|
|
prio: 2,
|
2018-09-19 13:54:49 +00:00
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1,
|
|
|
|
)
|
|
|
|
|
|
|
|
params = {
|
|
|
|
prios: [
|
|
|
|
[overview2.id, 1],
|
|
|
|
[overview1.id, 2],
|
|
|
|
]
|
|
|
|
}
|
|
|
|
authenticated_as(admin_user)
|
|
|
|
post '/api/v1/overviews_prio', params: params, as: :json
|
|
|
|
expect(response).to have_http_status(200)
|
|
|
|
expect(json_response).to be_a_kind_of(Hash)
|
|
|
|
expect(json_response['success']).to eq(true)
|
|
|
|
|
|
|
|
overview1.reload
|
|
|
|
overview2.reload
|
|
|
|
|
|
|
|
expect(overview1.prio).to eq(2)
|
|
|
|
expect(overview2.prio).to eq(1)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does create an overview with group_by direction' do
|
|
|
|
|
|
|
|
params = {
|
2018-12-19 17:31:51 +00:00
|
|
|
name: 'Overview2',
|
|
|
|
link: 'my_overview',
|
|
|
|
roles: Role.where(name: 'Agent').pluck(:name),
|
|
|
|
condition: {
|
2018-09-19 13:54:49 +00:00
|
|
|
'ticket.state_id' => {
|
|
|
|
operator: 'is',
|
2018-12-19 17:31:51 +00:00
|
|
|
value: [1, 2, 3],
|
2018-09-19 13:54:49 +00:00
|
|
|
},
|
|
|
|
},
|
2018-12-19 17:31:51 +00:00
|
|
|
order: {
|
|
|
|
by: 'created_at',
|
2018-09-19 13:54:49 +00:00
|
|
|
direction: 'DESC',
|
|
|
|
},
|
2018-12-19 17:31:51 +00:00
|
|
|
group_by: 'priority',
|
2018-09-19 13:54:49 +00:00
|
|
|
group_direction: 'ASC',
|
2018-12-19 17:31:51 +00:00
|
|
|
view: {
|
|
|
|
d: %w[title customer state created_at],
|
|
|
|
s: %w[number title customer state created_at],
|
|
|
|
m: %w[number title customer state created_at],
|
2018-09-19 13:54:49 +00:00
|
|
|
view_mode_default: 's',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
authenticated_as(admin_user)
|
|
|
|
post '/api/v1/overviews', params: params, as: :json
|
|
|
|
expect(response).to have_http_status(201)
|
|
|
|
expect(json_response).to be_a_kind_of(Hash)
|
|
|
|
expect(json_response['name']).to eq('Overview2')
|
|
|
|
expect(json_response['link']).to eq('my_overview')
|
|
|
|
expect(json_response['group_by']).to eq('priority')
|
|
|
|
expect(json_response['group_direction']).to eq('ASC')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|