2018-09-19 13:54:49 +00:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
RSpec.describe 'Search', type: :request, searchindex: true do
|
|
|
|
|
2019-02-04 06:56:18 +00:00
|
|
|
let(:group) { create(:group) }
|
2020-06-19 09:17:18 +00:00
|
|
|
let!(:admin) do
|
|
|
|
create(:admin, groups: [Group.lookup(name: 'Users'), group])
|
2018-09-19 13:54:49 +00:00
|
|
|
end
|
2020-06-19 09:17:18 +00:00
|
|
|
let!(:agent) do
|
|
|
|
create(:agent, firstname: 'Search 1234', groups: [Group.lookup(name: 'Users'), group])
|
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
|
|
|
|
let!(:organization1) do
|
|
|
|
create(:organization, name: 'Rest Org')
|
|
|
|
end
|
|
|
|
let!(:organization2) do
|
|
|
|
create(:organization, name: 'Rest Org #2')
|
|
|
|
end
|
|
|
|
let!(:organization3) do
|
|
|
|
create(:organization, name: 'Rest Org #3')
|
|
|
|
end
|
|
|
|
let!(:organization4) do
|
|
|
|
create(:organization, name: 'Tes.t. Org')
|
|
|
|
end
|
|
|
|
let!(:organization5) do
|
|
|
|
create(:organization, name: 'ABC_D Org')
|
|
|
|
end
|
2020-02-18 14:49:52 +00:00
|
|
|
let!(:organization_nested) do
|
|
|
|
create(:organization, name: 'Tomato42 Ltd.', note: 'Tomato42 Ltd.')
|
|
|
|
end
|
2020-06-19 09:17:18 +00:00
|
|
|
let!(:customer_nested) do
|
|
|
|
create(:customer, organization: organization_nested)
|
2020-02-18 14:49:52 +00:00
|
|
|
end
|
2020-06-19 09:17:18 +00:00
|
|
|
let!(:customer2) do
|
|
|
|
create(:customer, organization: organization1)
|
2018-09-19 13:54:49 +00:00
|
|
|
end
|
2020-06-19 09:17:18 +00:00
|
|
|
let!(:customer3) do
|
|
|
|
create(:customer, organization: organization1)
|
2018-09-19 13:54:49 +00:00
|
|
|
end
|
|
|
|
let!(:ticket1) do
|
2020-06-19 09:17:18 +00:00
|
|
|
create(:ticket, title: 'test 1234-1', customer: customer, group: group)
|
2018-09-19 13:54:49 +00:00
|
|
|
end
|
|
|
|
let!(:ticket2) do
|
2020-06-19 09:17:18 +00:00
|
|
|
create(:ticket, title: 'test 1234-2', customer: customer2, group: group)
|
2018-09-19 13:54:49 +00:00
|
|
|
end
|
|
|
|
let!(:ticket3) do
|
2020-06-19 09:17:18 +00:00
|
|
|
create(:ticket, title: 'test 1234-2', customer: customer3, group: group)
|
2018-09-19 13:54:49 +00:00
|
|
|
end
|
2020-02-18 14:49:52 +00:00
|
|
|
let!(:ticket_nested) do
|
2020-06-19 09:17:18 +00:00
|
|
|
create(:ticket, title: 'vegetable request', customer: customer_nested, group: group)
|
2020-02-18 14:49:52 +00:00
|
|
|
end
|
2018-09-19 13:54:49 +00:00
|
|
|
let!(:article1) do
|
|
|
|
create(:ticket_article, ticket_id: ticket1.id)
|
|
|
|
end
|
|
|
|
let!(:article2) do
|
|
|
|
create(:ticket_article, ticket_id: ticket2.id)
|
|
|
|
end
|
|
|
|
let!(:article3) do
|
|
|
|
create(:ticket_article, ticket_id: ticket3.id)
|
|
|
|
end
|
2020-02-18 14:49:52 +00:00
|
|
|
let!(:article_nested) do
|
|
|
|
article = create(:ticket_article, ticket_id: ticket_nested.id)
|
|
|
|
|
|
|
|
Store.add(
|
|
|
|
object: 'Ticket::Article',
|
|
|
|
o_id: article.id,
|
2020-02-18 19:51:31 +00:00
|
|
|
data: File.binread(Rails.root.join('test/data/elasticsearch/es-normal.txt')),
|
2020-02-18 14:49:52 +00:00
|
|
|
filename: 'es-normal.txt',
|
|
|
|
preferences: {},
|
|
|
|
created_by_id: 1,
|
|
|
|
)
|
|
|
|
|
|
|
|
article
|
|
|
|
end
|
2018-09-19 13:54:49 +00:00
|
|
|
|
2019-04-15 01:41:17 +00:00
|
|
|
before do
|
2018-09-19 13:54:49 +00:00
|
|
|
configure_elasticsearch do
|
|
|
|
|
|
|
|
travel 1.minute
|
|
|
|
|
|
|
|
rebuild_searchindex
|
|
|
|
|
|
|
|
# execute background jobs
|
|
|
|
Scheduler.worker(true)
|
|
|
|
|
|
|
|
sleep 6
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'request handling' do
|
|
|
|
|
|
|
|
it 'does settings index with nobody' do
|
|
|
|
params = {
|
|
|
|
query: 'test 1234',
|
|
|
|
limit: 2,
|
|
|
|
}
|
|
|
|
|
|
|
|
post '/api/v1/search/ticket', 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)
|
2019-04-15 01:41:17 +00:00
|
|
|
expect(json_response).not_to be_blank
|
2018-09-19 13:54:49 +00:00
|
|
|
expect(json_response['error']).to eq('authentication failed')
|
|
|
|
|
|
|
|
post '/api/v1/search/user', 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)
|
2019-04-15 01:41:17 +00:00
|
|
|
expect(json_response).not_to be_blank
|
2018-09-19 13:54:49 +00:00
|
|
|
expect(json_response['error']).to eq('authentication failed')
|
|
|
|
|
|
|
|
post '/api/v1/search', 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)
|
2019-04-15 01:41:17 +00:00
|
|
|
expect(json_response).not_to be_blank
|
2018-09-19 13:54:49 +00:00
|
|
|
expect(json_response['error']).to eq('authentication failed')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does settings index with admin' do
|
|
|
|
params = {
|
|
|
|
query: '1234*',
|
|
|
|
limit: 1,
|
|
|
|
}
|
2020-06-19 09:17:18 +00:00
|
|
|
authenticated_as(admin)
|
2018-09-19 13:54:49 +00:00
|
|
|
post '/api/v1/search', 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).to be_truthy
|
|
|
|
expect(json_response['result'][0]['type']).to eq('Ticket')
|
|
|
|
expect(json_response['result'][0]['id']).to eq(ticket3.id)
|
|
|
|
expect(json_response['result'][1]['type']).to eq('User')
|
2020-06-19 09:17:18 +00:00
|
|
|
expect(json_response['result'][1]['id']).to eq(agent.id)
|
2018-09-19 13:54:49 +00:00
|
|
|
expect(json_response['result'][2]).to be_falsey
|
|
|
|
|
|
|
|
params = {
|
|
|
|
query: '1234*',
|
|
|
|
limit: 10,
|
|
|
|
}
|
|
|
|
|
|
|
|
post '/api/v1/search', 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).to be_truthy
|
|
|
|
expect(json_response['result'][0]['type']).to eq('Ticket')
|
|
|
|
expect(json_response['result'][0]['id']).to eq(ticket3.id)
|
|
|
|
expect(json_response['result'][1]['type']).to eq('Ticket')
|
|
|
|
expect(json_response['result'][1]['id']).to eq(ticket2.id)
|
|
|
|
expect(json_response['result'][2]['type']).to eq('Ticket')
|
|
|
|
expect(json_response['result'][2]['id']).to eq(ticket1.id)
|
|
|
|
expect(json_response['result'][3]['type']).to eq('User')
|
2020-06-19 09:17:18 +00:00
|
|
|
expect(json_response['result'][3]['id']).to eq(agent.id)
|
2018-09-19 13:54:49 +00:00
|
|
|
expect(json_response['result'][4]).to be_falsey
|
|
|
|
|
|
|
|
params = {
|
|
|
|
query: '1234*',
|
|
|
|
limit: 10,
|
|
|
|
}
|
|
|
|
|
|
|
|
post '/api/v1/search/ticket', 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).to be_truthy
|
|
|
|
expect(json_response['result'][0]['type']).to eq('Ticket')
|
|
|
|
expect(json_response['result'][0]['id']).to eq(ticket3.id)
|
|
|
|
expect(json_response['result'][1]['type']).to eq('Ticket')
|
|
|
|
expect(json_response['result'][1]['id']).to eq(ticket2.id)
|
|
|
|
expect(json_response['result'][2]['type']).to eq('Ticket')
|
|
|
|
expect(json_response['result'][2]['id']).to eq(ticket1.id)
|
|
|
|
expect(json_response['result'][3]).to be_falsey
|
|
|
|
|
|
|
|
params = {
|
|
|
|
query: '1234*',
|
|
|
|
limit: 10,
|
|
|
|
}
|
|
|
|
|
|
|
|
post '/api/v1/search/user', 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['result'][0]['type']).to eq('User')
|
2020-06-19 09:17:18 +00:00
|
|
|
expect(json_response['result'][0]['id']).to eq(agent.id)
|
2018-09-19 13:54:49 +00:00
|
|
|
expect(json_response['result'][1]).to be_falsey
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does settings index with agent' do
|
|
|
|
params = {
|
|
|
|
query: '1234*',
|
|
|
|
limit: 1,
|
|
|
|
}
|
|
|
|
|
2020-06-19 09:17:18 +00:00
|
|
|
authenticated_as(agent)
|
2018-09-19 13:54:49 +00:00
|
|
|
post '/api/v1/search', 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).to be_truthy
|
|
|
|
expect(json_response['result'][0]['type']).to eq('Ticket')
|
|
|
|
expect(json_response['result'][0]['id']).to eq(ticket3.id)
|
|
|
|
expect(json_response['result'][1]['type']).to eq('User')
|
2020-06-19 09:17:18 +00:00
|
|
|
expect(json_response['result'][1]['id']).to eq(agent.id)
|
2018-09-19 13:54:49 +00:00
|
|
|
expect(json_response['result'][2]).to be_falsey
|
|
|
|
|
|
|
|
params = {
|
|
|
|
query: '1234*',
|
|
|
|
limit: 10,
|
|
|
|
}
|
|
|
|
|
|
|
|
post '/api/v1/search', 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).to be_truthy
|
|
|
|
expect(json_response['result'][0]['type']).to eq('Ticket')
|
|
|
|
expect(json_response['result'][0]['id']).to eq(ticket3.id)
|
|
|
|
expect(json_response['result'][1]['type']).to eq('Ticket')
|
|
|
|
expect(json_response['result'][1]['id']).to eq(ticket2.id)
|
|
|
|
expect(json_response['result'][2]['type']).to eq('Ticket')
|
|
|
|
expect(json_response['result'][2]['id']).to eq(ticket1.id)
|
|
|
|
expect(json_response['result'][3]['type']).to eq('User')
|
2020-06-19 09:17:18 +00:00
|
|
|
expect(json_response['result'][3]['id']).to eq(agent.id)
|
2018-09-19 13:54:49 +00:00
|
|
|
expect(json_response['result'][4]).to be_falsey
|
|
|
|
|
|
|
|
params = {
|
|
|
|
query: '1234*',
|
|
|
|
limit: 10,
|
|
|
|
}
|
|
|
|
|
|
|
|
post '/api/v1/search/ticket', 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).to be_truthy
|
|
|
|
expect(json_response['result'][0]['type']).to eq('Ticket')
|
|
|
|
expect(json_response['result'][0]['id']).to eq(ticket3.id)
|
|
|
|
expect(json_response['result'][1]['type']).to eq('Ticket')
|
|
|
|
expect(json_response['result'][1]['id']).to eq(ticket2.id)
|
|
|
|
expect(json_response['result'][2]['type']).to eq('Ticket')
|
|
|
|
expect(json_response['result'][2]['id']).to eq(ticket1.id)
|
|
|
|
expect(json_response['result'][3]).to be_falsey
|
|
|
|
|
|
|
|
params = {
|
|
|
|
query: '1234*',
|
|
|
|
limit: 10,
|
|
|
|
}
|
|
|
|
|
|
|
|
post '/api/v1/search/user', 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['result'][0]['type']).to eq('User')
|
2020-06-19 09:17:18 +00:00
|
|
|
expect(json_response['result'][0]['id']).to eq(agent.id)
|
2018-09-19 13:54:49 +00:00
|
|
|
expect(json_response['result'][1]).to be_falsey
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does settings index with customer 1' do
|
|
|
|
params = {
|
|
|
|
query: '1234*',
|
|
|
|
limit: 10,
|
|
|
|
}
|
|
|
|
|
2020-06-19 09:17:18 +00:00
|
|
|
authenticated_as(customer)
|
2018-09-19 13:54:49 +00:00
|
|
|
post '/api/v1/search', 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).to be_truthy
|
|
|
|
expect(json_response['result'][0]['type']).to eq('Ticket')
|
|
|
|
expect(json_response['result'][0]['id']).to eq(ticket1.id)
|
|
|
|
expect(json_response['result'][1]).to be_falsey
|
|
|
|
|
|
|
|
params = {
|
|
|
|
query: '1234*',
|
|
|
|
limit: 10,
|
|
|
|
}
|
|
|
|
|
|
|
|
post '/api/v1/search/ticket', 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).to be_truthy
|
|
|
|
expect(json_response['result'][0]['type']).to eq('Ticket')
|
|
|
|
expect(json_response['result'][0]['id']).to eq(ticket1.id)
|
|
|
|
expect(json_response['result'][1]).to be_falsey
|
|
|
|
|
|
|
|
params = {
|
|
|
|
query: '1234*',
|
|
|
|
limit: 10,
|
|
|
|
}
|
|
|
|
|
|
|
|
post '/api/v1/search/user', 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['result'][0]).to be_falsey
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does settings index with customer 2' do
|
|
|
|
params = {
|
|
|
|
query: '1234*',
|
|
|
|
limit: 10,
|
|
|
|
}
|
|
|
|
|
2020-06-19 09:17:18 +00:00
|
|
|
authenticated_as(customer2)
|
2018-09-19 13:54:49 +00:00
|
|
|
post '/api/v1/search', 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).to be_truthy
|
|
|
|
expect(json_response['result'][0]['type']).to eq('Ticket')
|
|
|
|
expect(json_response['result'][0]['id']).to eq(ticket3.id)
|
|
|
|
expect(json_response['result'][1]['type']).to eq('Ticket')
|
|
|
|
expect(json_response['result'][1]['id']).to eq(ticket2.id)
|
|
|
|
expect(json_response['result'][2]).to be_falsey
|
|
|
|
|
|
|
|
params = {
|
|
|
|
query: '1234*',
|
|
|
|
limit: 10,
|
|
|
|
}
|
|
|
|
|
|
|
|
post '/api/v1/search/ticket', 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).to be_truthy
|
|
|
|
expect(json_response['result'][0]['type']).to eq('Ticket')
|
|
|
|
expect(json_response['result'][0]['id']).to eq(ticket3.id)
|
|
|
|
expect(json_response['result'][1]['type']).to eq('Ticket')
|
|
|
|
expect(json_response['result'][1]['id']).to eq(ticket2.id)
|
|
|
|
expect(json_response['result'][2]).to be_falsey
|
|
|
|
|
|
|
|
params = {
|
|
|
|
query: '1234*',
|
|
|
|
limit: 10,
|
|
|
|
}
|
|
|
|
|
|
|
|
post '/api/v1/search/user', 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['result'][0]).to be_falsey
|
|
|
|
end
|
|
|
|
|
|
|
|
# Verify fix for Github issue #2058 - Autocomplete hangs on dot in the new user form
|
|
|
|
it 'does searching for organization with a dot in its name' do
|
2020-06-19 09:17:18 +00:00
|
|
|
authenticated_as(agent)
|
2018-09-19 13:54:49 +00:00
|
|
|
get '/api/v1/search/organization?query=tes.', 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['result'].size).to eq(1)
|
|
|
|
expect(json_response['result'][0]['type']).to eq('Organization')
|
|
|
|
target_id = json_response['result'][0]['id']
|
|
|
|
expect(json_response['assets']['Organization'][target_id.to_s]['name']).to eq('Tes.t. Org')
|
|
|
|
end
|
|
|
|
|
|
|
|
# Search query H& should correctly match H&M
|
|
|
|
it 'does searching for organization with _ in its name' do
|
2020-06-19 09:17:18 +00:00
|
|
|
authenticated_as(agent)
|
2018-09-19 13:54:49 +00:00
|
|
|
get '/api/v1/search/organization?query=abc_', 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['result'].size).to eq(1)
|
|
|
|
expect(json_response['result'][0]['type']).to eq('Organization')
|
|
|
|
target_id = json_response['result'][0]['id']
|
|
|
|
expect(json_response['assets']['Organization'][target_id.to_s]['name']).to eq('ABC_D Org')
|
|
|
|
end
|
2020-02-18 14:49:52 +00:00
|
|
|
|
|
|
|
it 'does find the user of the nested organization and also even if the organization name changes' do
|
|
|
|
|
|
|
|
# because of the initial relation between user and organization
|
|
|
|
# both user and organization will be found as result
|
2020-06-19 09:17:18 +00:00
|
|
|
authenticated_as(agent)
|
2020-03-02 14:25:33 +00:00
|
|
|
post '/api/v1/search/User', params: { query: 'Tomato42' }, as: :json
|
|
|
|
expect(response).to have_http_status(:ok)
|
|
|
|
expect(json_response).to be_a_kind_of(Hash)
|
|
|
|
expect(json_response).to be_truthy
|
|
|
|
expect(json_response['assets']['Organization'][organization_nested.id.to_s]).to be_truthy
|
2020-06-19 09:17:18 +00:00
|
|
|
expect(json_response['assets']['User'][customer_nested.id.to_s]).to be_truthy
|
2020-03-02 14:25:33 +00:00
|
|
|
|
2021-01-27 09:58:35 +00:00
|
|
|
post '/api/v1/search/User', params: { query: 'organization.name:Tomato42' }, as: :json
|
2020-02-18 14:49:52 +00:00
|
|
|
expect(response).to have_http_status(:ok)
|
|
|
|
expect(json_response).to be_a_kind_of(Hash)
|
|
|
|
expect(json_response).to be_truthy
|
|
|
|
expect(json_response['assets']['Organization'][organization_nested.id.to_s]).to be_truthy
|
2020-06-19 09:17:18 +00:00
|
|
|
expect(json_response['assets']['User'][customer_nested.id.to_s]).to be_truthy
|
2020-02-18 14:49:52 +00:00
|
|
|
|
|
|
|
organization_nested.update(name: 'Cucumber43 Ltd.')
|
|
|
|
Scheduler.worker(true)
|
|
|
|
SearchIndexBackend.refresh
|
|
|
|
|
|
|
|
# even after a change of the organization name we should find
|
|
|
|
# the customer user because of the nested organization data
|
2020-03-02 14:25:33 +00:00
|
|
|
post '/api/v1/search/User', params: { query: 'Cucumber43' }, as: :json
|
|
|
|
expect(response).to have_http_status(:ok)
|
|
|
|
expect(json_response).to be_a_kind_of(Hash)
|
|
|
|
expect(json_response).to be_truthy
|
|
|
|
expect(json_response['assets']['Organization'][organization_nested.id.to_s]).to be_truthy
|
2020-06-19 09:17:18 +00:00
|
|
|
expect(json_response['assets']['User'][customer_nested.id.to_s]).to be_truthy
|
2020-03-02 14:25:33 +00:00
|
|
|
|
2021-01-27 09:58:35 +00:00
|
|
|
post '/api/v1/search/User', params: { query: 'organization.name:Cucumber43' }, as: :json
|
2020-02-18 14:49:52 +00:00
|
|
|
expect(response).to have_http_status(:ok)
|
|
|
|
expect(json_response).to be_a_kind_of(Hash)
|
|
|
|
expect(json_response).to be_truthy
|
|
|
|
expect(json_response['assets']['Organization'][organization_nested.id.to_s]).to be_truthy
|
2020-06-19 09:17:18 +00:00
|
|
|
expect(json_response['assets']['User'][customer_nested.id.to_s]).to be_truthy
|
2020-02-18 14:49:52 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'does find the ticket by organization name even if the organization name changes' do
|
2020-06-19 09:17:18 +00:00
|
|
|
authenticated_as(agent)
|
2020-03-02 14:25:33 +00:00
|
|
|
post '/api/v1/search/Ticket', params: { query: 'Tomato42' }, as: :json
|
|
|
|
expect(response).to have_http_status(:ok)
|
|
|
|
expect(json_response).to be_a_kind_of(Hash)
|
|
|
|
expect(json_response).to be_truthy
|
|
|
|
expect(json_response['assets']['Organization'][organization_nested.id.to_s]).to be_truthy
|
|
|
|
expect(json_response['assets']['Ticket'][ticket_nested.id.to_s]).to be_truthy
|
|
|
|
|
2021-01-27 09:58:35 +00:00
|
|
|
post '/api/v1/search/Ticket', params: { query: 'organization.name:Tomato42' }, as: :json
|
2020-02-18 14:49:52 +00:00
|
|
|
expect(response).to have_http_status(:ok)
|
|
|
|
expect(json_response).to be_a_kind_of(Hash)
|
|
|
|
expect(json_response).to be_truthy
|
|
|
|
expect(json_response['assets']['Organization'][organization_nested.id.to_s]).to be_truthy
|
|
|
|
expect(json_response['assets']['Ticket'][ticket_nested.id.to_s]).to be_truthy
|
|
|
|
|
|
|
|
organization_nested.update(name: 'Cucumber43 Ltd.')
|
|
|
|
Scheduler.worker(true)
|
|
|
|
SearchIndexBackend.refresh
|
|
|
|
|
2020-03-02 14:25:33 +00:00
|
|
|
post '/api/v1/search/Ticket', params: { query: 'Cucumber43' }, as: :json
|
|
|
|
expect(response).to have_http_status(:ok)
|
|
|
|
expect(json_response).to be_a_kind_of(Hash)
|
|
|
|
expect(json_response).to be_truthy
|
|
|
|
expect(json_response['assets']['Organization'][organization_nested.id.to_s]).to be_truthy
|
|
|
|
expect(json_response['assets']['Ticket'][ticket_nested.id.to_s]).to be_truthy
|
2020-02-18 14:49:52 +00:00
|
|
|
|
2021-01-27 09:58:35 +00:00
|
|
|
post '/api/v1/search/Ticket', params: { query: 'organization.name:Cucumber43' }, as: :json
|
2020-02-18 14:49:52 +00:00
|
|
|
expect(response).to have_http_status(:ok)
|
|
|
|
expect(json_response).to be_a_kind_of(Hash)
|
|
|
|
expect(json_response).to be_truthy
|
|
|
|
expect(json_response['assets']['Organization'][organization_nested.id.to_s]).to be_truthy
|
|
|
|
expect(json_response['assets']['Ticket'][ticket_nested.id.to_s]).to be_truthy
|
|
|
|
end
|
|
|
|
|
2021-01-27 12:55:22 +00:00
|
|
|
it 'does find the ticket by group name even if the group name changes' do
|
|
|
|
authenticated_as(agent)
|
|
|
|
post '/api/v1/search/Ticket', params: { query: "number:#{ticket1.number} && group.name:ultrasupport" }, as: :json
|
|
|
|
expect(response).to have_http_status(:ok)
|
|
|
|
expect(json_response).to be_a_kind_of(Hash)
|
|
|
|
expect(json_response).to be_truthy
|
|
|
|
expect(json_response['assets']['Ticket']).to be_falsey
|
|
|
|
expect(group).not_to eq('ultrasupport')
|
|
|
|
|
|
|
|
group.update(name: 'ultrasupport')
|
|
|
|
Scheduler.worker(true)
|
|
|
|
SearchIndexBackend.refresh
|
|
|
|
|
|
|
|
post '/api/v1/search/Ticket', params: { query: "number:#{ticket1.number} && group.name:ultrasupport" }, as: :json
|
|
|
|
expect(response).to have_http_status(:ok)
|
|
|
|
expect(json_response).to be_a_kind_of(Hash)
|
|
|
|
expect(json_response).to be_truthy
|
|
|
|
expect(json_response['assets']['Ticket'][ticket1.id.to_s]).to be_truthy
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does find the ticket by state name even if the state name changes' do
|
|
|
|
authenticated_as(agent)
|
|
|
|
post '/api/v1/search/Ticket', params: { query: "number:#{ticket1.number} && state.name:ultrastate" }, as: :json
|
|
|
|
expect(response).to have_http_status(:ok)
|
|
|
|
expect(json_response).to be_a_kind_of(Hash)
|
|
|
|
expect(json_response).to be_truthy
|
|
|
|
expect(json_response['assets']['Ticket']).to be_falsey
|
|
|
|
expect(ticket1.state.name).not_to eq('ultrastate')
|
|
|
|
|
|
|
|
ticket1.state.update(name: 'ultrastate')
|
|
|
|
Scheduler.worker(true)
|
|
|
|
SearchIndexBackend.refresh
|
|
|
|
|
|
|
|
post '/api/v1/search/Ticket', params: { query: "number:#{ticket1.number} && state.name:ultrastate" }, as: :json
|
|
|
|
expect(response).to have_http_status(:ok)
|
|
|
|
expect(json_response).to be_a_kind_of(Hash)
|
|
|
|
expect(json_response).to be_truthy
|
|
|
|
expect(json_response['assets']['Ticket'][ticket1.id.to_s]).to be_truthy
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does find the ticket by priority name even if the priority name changes' do
|
|
|
|
authenticated_as(agent)
|
|
|
|
post '/api/v1/search/Ticket', params: { query: "number:#{ticket1.number} && priority.name:ultrapriority" }, as: :json
|
|
|
|
expect(response).to have_http_status(:ok)
|
|
|
|
expect(json_response).to be_a_kind_of(Hash)
|
|
|
|
expect(json_response).to be_truthy
|
|
|
|
expect(json_response['assets']['Ticket']).to be_falsey
|
|
|
|
expect(ticket1.priority.name).not_to eq('ultrapriority')
|
|
|
|
|
|
|
|
ticket1.priority.update(name: 'ultrapriority')
|
|
|
|
Scheduler.worker(true)
|
|
|
|
SearchIndexBackend.refresh
|
|
|
|
|
|
|
|
post '/api/v1/search/Ticket', params: { query: "number:#{ticket1.number} && priority.name:ultrapriority" }, as: :json
|
|
|
|
expect(response).to have_http_status(:ok)
|
|
|
|
expect(json_response).to be_a_kind_of(Hash)
|
|
|
|
expect(json_response).to be_truthy
|
|
|
|
expect(json_response['assets']['Ticket'][ticket1.id.to_s]).to be_truthy
|
|
|
|
end
|
|
|
|
|
2020-02-18 14:49:52 +00:00
|
|
|
it 'does find the ticket by attachment even after ticket reindex' do
|
|
|
|
params = {
|
|
|
|
query: 'text66',
|
|
|
|
limit: 10,
|
|
|
|
}
|
|
|
|
|
2020-06-19 09:17:18 +00:00
|
|
|
authenticated_as(agent)
|
2020-02-18 14:49:52 +00:00
|
|
|
post '/api/v1/search/Ticket', params: params, as: :json
|
|
|
|
expect(response).to have_http_status(:ok)
|
|
|
|
expect(json_response).to be_a_kind_of(Hash)
|
|
|
|
expect(json_response).to be_truthy
|
|
|
|
expect(json_response['assets']['Ticket'][ticket_nested.id.to_s]).to be_truthy
|
|
|
|
|
|
|
|
organization_nested.update(name: 'Cucumber43 Ltd.')
|
|
|
|
Scheduler.worker(true)
|
|
|
|
SearchIndexBackend.refresh
|
|
|
|
|
|
|
|
params = {
|
|
|
|
query: 'text66',
|
|
|
|
limit: 10,
|
|
|
|
}
|
|
|
|
|
|
|
|
post '/api/v1/search/Ticket', params: params, as: :json
|
|
|
|
expect(response).to have_http_status(:ok)
|
|
|
|
expect(json_response).to be_a_kind_of(Hash)
|
|
|
|
expect(json_response).to be_truthy
|
|
|
|
expect(json_response['assets']['Ticket'][ticket_nested.id.to_s]).to be_truthy
|
|
|
|
end
|
2018-09-19 13:54:49 +00:00
|
|
|
end
|
|
|
|
end
|