diff options
Diffstat (limited to 'spec/controllers/search_controller_spec.rb')
-rw-r--r-- | spec/controllers/search_controller_spec.rb | 39 |
1 files changed, 24 insertions, 15 deletions
diff --git a/spec/controllers/search_controller_spec.rb b/spec/controllers/search_controller_spec.rb index 4abcd414e51..b4d4e01e972 100644 --- a/spec/controllers/search_controller_spec.rb +++ b/spec/controllers/search_controller_spec.rb @@ -67,7 +67,7 @@ RSpec.describe SearchController do end end - describe 'GET #show' do + describe 'GET #show', :snowplow do it_behaves_like 'when the user cannot read cross project', :show, { search: 'hello' } do it 'still allows accessing the search page' do get :show @@ -257,6 +257,16 @@ RSpec.describe SearchController do end end + it_behaves_like 'Snowplow event tracking' do + subject { get :show, params: { group_id: namespace.id, scope: 'blobs', search: 'term' } } + + let(:project) { nil } + let(:category) { described_class.to_s } + let(:action) { 'i_search_total' } + let(:namespace) { create(:group) } + let(:feature_flag_name) { :route_hll_to_snowplow_phase2 } + end + context 'on restricted projects' do context 'when signed out' do before do @@ -398,10 +408,11 @@ RSpec.describe SearchController do expect(payload[:metadata]['meta.search.filters.confidential']).to eq('true') expect(payload[:metadata]['meta.search.filters.state']).to eq('true') expect(payload[:metadata]['meta.search.project_ids']).to eq(%w(456 789)) - expect(payload[:metadata]['meta.search.search_level']).to eq('multi-project') + expect(payload[:metadata]['meta.search.type']).to eq('basic') + expect(payload[:metadata]['meta.search.level']).to eq('global') end - get :show, params: { scope: 'issues', search: 'hello world', group_id: '123', project_id: '456', project_ids: %w(456 789), search_level: 'multi-project', confidential: true, state: true, force_search_results: true } + get :show, params: { scope: 'issues', search: 'hello world', group_id: '123', project_id: '456', project_ids: %w(456 789), confidential: true, state: true, force_search_results: true } end it 'appends the default scope in meta.search.scope' do @@ -413,6 +424,16 @@ RSpec.describe SearchController do get :show, params: { search: 'hello world', group_id: '123', project_id: '456' } end + + it 'appends the search time based on the search' do + expect(controller).to receive(:append_info_to_payload).and_wrap_original do |method, payload| + method.call(payload) + + expect(payload[:metadata][:global_search_duration_s]).to be_a_kind_of(Numeric) + end + + get :show, params: { search: 'hello world', group_id: '123', project_id: '456' } + end end context 'abusive searches', :aggregate_failures do @@ -430,18 +451,6 @@ RSpec.describe SearchController do make_abusive_request expect(response).to have_gitlab_http_status(:ok) end - - context 'when the feature flag is disabled' do - before do - stub_feature_flags(prevent_abusive_searches: false) - end - - it 'returns a regular search result' do - expect(Gitlab::EmptySearchResults).not_to receive(:new) - make_abusive_request - expect(response).to have_gitlab_http_status(:ok) - end - end end end |