2022-01-01 13:38:12 +00:00
|
|
|
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
|
2021-06-01 12:20:20 +00:00
|
|
|
|
2018-09-19 13:54:49 +00:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
RSpec.describe 'Overviews', type: :request do
|
|
|
|
|
2020-06-19 09:17:18 +00:00
|
|
|
let(:admin) do
|
|
|
|
create(:admin)
|
2018-09-19 13:54:49 +00:00
|
|
|
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',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2020-06-19 09:17:18 +00:00
|
|
|
agent = create(:agent, password: 'we need a password here')
|
2018-09-19 13:54:49 +00:00
|
|
|
|
2022-03-31 11:50:42 +00:00
|
|
|
authenticated_as(agent, password: 'wrong password')
|
2018-09-19 13:54:49 +00:00
|
|
|
post '/api/v1/overviews', params: params, as: :json
|
2019-04-15 01:41:17 +00:00
|
|
|
expect(response).to have_http_status(:unauthorized)
|
2018-09-19 13:54:49 +00:00
|
|
|
expect(json_response).to be_a_kind_of(Hash)
|
2021-02-04 08:28:41 +00:00
|
|
|
expect(json_response['error']).to eq('Invalid BasicAuth credentials')
|
2018-09-19 13:54:49 +00:00
|
|
|
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',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2020-06-19 09:17:18 +00:00
|
|
|
authenticated_as(admin)
|
2018-09-19 13:54:49 +00:00
|
|
|
post '/api/v1/overviews', 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['name']).to eq('Overview2')
|
|
|
|
expect(json_response['link']).to eq('my_overview')
|
|
|
|
|
|
|
|
post '/api/v1/overviews', 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['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],
|
|
|
|
]
|
|
|
|
}
|
2020-06-19 09:17:18 +00:00
|
|
|
authenticated_as(admin)
|
2018-09-19 13:54:49 +00:00
|
|
|
post '/api/v1/overviews_prio', 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)
|
2022-03-01 08:00:40 +00:00
|
|
|
expect(json_response['success']).to be(true)
|
2018-09-19 13:54:49 +00:00
|
|
|
|
|
|
|
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',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2020-06-19 09:17:18 +00:00
|
|
|
authenticated_as(admin)
|
2018-09-19 13:54:49 +00:00
|
|
|
post '/api/v1/overviews', 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['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
|