diff options
Diffstat (limited to 'spec/requests/api/search_spec.rb')
-rw-r--r-- | spec/requests/api/search_spec.rb | 48 |
1 files changed, 47 insertions, 1 deletions
diff --git a/spec/requests/api/search_spec.rb b/spec/requests/api/search_spec.rb index 3894e0bf2d1..a02d804ee9b 100644 --- a/spec/requests/api/search_spec.rb +++ b/spec/requests/api/search_spec.rb @@ -15,6 +15,14 @@ describe API::Search do it { expect(json_response.size).to eq(size) } end + shared_examples 'ping counters' do |scope:, search: ''| + it 'increases usage ping searches counter' do + expect(Gitlab::UsageDataCounters::SearchCounter).to receive(:count).with(:all_searches) + + get api(endpoint, user), params: { scope: scope, search: search } + end + end + shared_examples 'pagination' do |scope:, search: ''| it 'returns a different result for each page' do get api(endpoint, user), params: { scope: scope, search: search, page: 1, per_page: 1 } @@ -75,6 +83,8 @@ describe API::Search do it_behaves_like 'response is correct', schema: 'public_api/v4/projects' it_behaves_like 'pagination', scope: :projects + + it_behaves_like 'ping counters', scope: :projects end context 'for issues scope' do @@ -86,6 +96,8 @@ describe API::Search do it_behaves_like 'response is correct', schema: 'public_api/v4/issues' + it_behaves_like 'ping counters', scope: :issues + describe 'pagination' do before do create(:issue, project: project, title: 'another issue') @@ -104,6 +116,8 @@ describe API::Search do it_behaves_like 'response is correct', schema: 'public_api/v4/merge_requests' + it_behaves_like 'ping counters', scope: :merge_requests + describe 'pagination' do before do create(:merge_request, source_project: repo_project, title: 'another mr', target_branch: 'another_branch') @@ -125,6 +139,8 @@ describe API::Search do it_behaves_like 'response is correct', schema: 'public_api/v4/milestones' + it_behaves_like 'ping counters', scope: :milestones + describe 'pagination' do before do create(:milestone, project: project, title: 'another milestone') @@ -161,6 +177,8 @@ describe API::Search do it_behaves_like 'pagination', scope: :users + it_behaves_like 'ping counters', scope: :users + context 'when users search feature is disabled' do before do stub_feature_flags(users_search: false) @@ -183,6 +201,8 @@ describe API::Search do it_behaves_like 'response is correct', schema: 'public_api/v4/snippets' + it_behaves_like 'ping counters', scope: :snippet_titles + describe 'pagination' do before do create(:snippet, :public, title: 'another snippet', content: 'snippet content') @@ -248,6 +268,8 @@ describe API::Search do it_behaves_like 'response is correct', schema: 'public_api/v4/projects' it_behaves_like 'pagination', scope: :projects + + it_behaves_like 'ping counters', scope: :projects end context 'for issues scope' do @@ -259,6 +281,8 @@ describe API::Search do it_behaves_like 'response is correct', schema: 'public_api/v4/issues' + it_behaves_like 'ping counters', scope: :issues + describe 'pagination' do before do create(:issue, project: project, title: 'another issue') @@ -277,6 +301,8 @@ describe API::Search do it_behaves_like 'response is correct', schema: 'public_api/v4/merge_requests' + it_behaves_like 'ping counters', scope: :merge_requests + describe 'pagination' do before do create(:merge_request, source_project: repo_project, title: 'another mr', target_branch: 'another_branch') @@ -295,6 +321,8 @@ describe API::Search do it_behaves_like 'response is correct', schema: 'public_api/v4/milestones' + it_behaves_like 'ping counters', scope: :milestones + describe 'pagination' do before do create(:milestone, project: project, title: 'another milestone') @@ -326,6 +354,8 @@ describe API::Search do it_behaves_like 'response is correct', schema: 'public_api/v4/user/basics' + it_behaves_like 'ping counters', scope: :users + describe 'pagination' do before do create(:group_member, :developer, group: group) @@ -395,7 +425,7 @@ describe API::Search do end end - context 'when user does can not see the project' do + context 'when user can not see the project' do it 'returns 404 error' do project.update!(visibility_level: Gitlab::VisibilityLevel::PRIVATE) @@ -415,6 +445,8 @@ describe API::Search do it_behaves_like 'response is correct', schema: 'public_api/v4/issues' + it_behaves_like 'ping counters', scope: :issues + describe 'pagination' do before do create(:issue, project: project, title: 'another issue') @@ -435,6 +467,8 @@ describe API::Search do it_behaves_like 'response is correct', schema: 'public_api/v4/merge_requests' + it_behaves_like 'ping counters', scope: :merge_requests + describe 'pagination' do before do create(:merge_request, source_project: repo_project, title: 'another mr', target_branch: 'another_branch') @@ -456,6 +490,8 @@ describe API::Search do it_behaves_like 'response is correct', schema: 'public_api/v4/milestones' + it_behaves_like 'ping counters', scope: :milestones + describe 'pagination' do before do create(:milestone, project: project, title: 'another milestone') @@ -491,6 +527,8 @@ describe API::Search do it_behaves_like 'response is correct', schema: 'public_api/v4/user/basics' + it_behaves_like 'ping counters', scope: :users + describe 'pagination' do before do create(:project_member, :developer, project: project) @@ -521,6 +559,8 @@ describe API::Search do it_behaves_like 'response is correct', schema: 'public_api/v4/notes' + it_behaves_like 'ping counters', scope: :notes + describe 'pagination' do before do mr = create(:merge_request, source_project: project, target_branch: 'another_branch') @@ -542,6 +582,8 @@ describe API::Search do it_behaves_like 'response is correct', schema: 'public_api/v4/blobs' + it_behaves_like 'ping counters', scope: :wiki_blobs + describe 'pagination' do before do create(:wiki_page, wiki: wiki, title: 'home 2', content: 'Another page') @@ -561,6 +603,8 @@ describe API::Search do it_behaves_like 'response is correct', schema: 'public_api/v4/commits_details' it_behaves_like 'pagination', scope: :commits, search: 'merge' + + it_behaves_like 'ping counters', scope: :commits end context 'for commits scope with project path as id' do @@ -582,6 +626,8 @@ describe API::Search do it_behaves_like 'pagination', scope: :blobs, search: 'monitors' + it_behaves_like 'ping counters', scope: :blobs + context 'filters' do it 'by filename' do get api(endpoint, user), params: { scope: 'blobs', search: 'mon filename:PROCESS.md' } |