diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-09-19 04:45:44 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-09-19 04:45:44 +0300 |
commit | 85dc423f7090da0a52c73eb66faf22ddb20efff9 (patch) | |
tree | 9160f299afd8c80c038f08e1545be119f5e3f1e1 /spec/requests/api/search_spec.rb | |
parent | 15c2c8c66dbe422588e5411eee7e68f1fa440bb8 (diff) |
Add latest changes from gitlab-org/gitlab@13-4-stable-ee
Diffstat (limited to 'spec/requests/api/search_spec.rb')
-rw-r--r-- | spec/requests/api/search_spec.rb | 89 |
1 files changed, 71 insertions, 18 deletions
diff --git a/spec/requests/api/search_spec.rb b/spec/requests/api/search_spec.rb index 1a93be98a67..af6731f3015 100644 --- a/spec/requests/api/search_spec.rb +++ b/spec/requests/api/search_spec.rb @@ -47,6 +47,17 @@ RSpec.describe API::Search do end end + shared_examples 'filter by state' do |scope:, search:| + it 'respects scope filtering' do + get api(endpoint, user), params: { scope: scope, search: search, state: state } + + documents = Gitlab::Json.parse(response.body) + + expect(documents.count).to eq(1) + expect(documents.first['state']).to eq(state) + end + end + describe 'GET /search' do let(:endpoint) { '/search' } @@ -88,42 +99,84 @@ RSpec.describe API::Search do end context 'for issues scope' do - before do - create(:issue, project: project, title: 'awesome issue') + context 'without filtering by state' do + before do + create(:issue, project: project, title: 'awesome issue') - get api(endpoint, user), params: { scope: 'issues', search: 'awesome' } - end + get api(endpoint, user), params: { scope: 'issues', search: 'awesome' } + end - it_behaves_like 'response is correct', schema: 'public_api/v4/issues' + it_behaves_like 'response is correct', schema: 'public_api/v4/issues' - it_behaves_like 'ping counters', scope: :issues + it_behaves_like 'ping counters', scope: :issues - describe 'pagination' do + describe 'pagination' do + before do + create(:issue, project: project, title: 'another issue') + end + + include_examples 'pagination', scope: :issues + end + end + + context 'filter by state' do before do - create(:issue, project: project, title: 'another issue') + create(:issue, project: project, title: 'awesome opened issue') + create(:issue, :closed, project: project, title: 'awesome closed issue') end - include_examples 'pagination', scope: :issues + context 'state: opened' do + let(:state) { 'opened' } + + include_examples 'filter by state', scope: :issues, search: 'awesome' + end + + context 'state: closed' do + let(:state) { 'closed' } + + include_examples 'filter by state', scope: :issues, search: 'awesome' + end end end context 'for merge_requests scope' do - before do - create(:merge_request, source_project: repo_project, title: 'awesome mr') + context 'without filtering by state' do + before do + create(:merge_request, source_project: repo_project, title: 'awesome mr') - get api(endpoint, user), params: { scope: 'merge_requests', search: 'awesome' } - end + get api(endpoint, user), params: { scope: 'merge_requests', search: 'awesome' } + end - it_behaves_like 'response is correct', schema: 'public_api/v4/merge_requests' + it_behaves_like 'response is correct', schema: 'public_api/v4/merge_requests' - it_behaves_like 'ping counters', scope: :merge_requests + it_behaves_like 'ping counters', scope: :merge_requests - describe 'pagination' do + describe 'pagination' do + before do + create(:merge_request, source_project: repo_project, title: 'another mr', target_branch: 'another_branch') + end + + include_examples 'pagination', scope: :merge_requests + end + end + + context 'filter by state' do before do - create(:merge_request, source_project: repo_project, title: 'another mr', target_branch: 'another_branch') + create(:merge_request, source_project: project, title: 'awesome opened mr') + create(:merge_request, :closed, project: project, title: 'awesome closed mr') end - include_examples 'pagination', scope: :merge_requests + context 'state: opened' do + let(:state) { 'opened' } + + include_examples 'filter by state', scope: :merge_requests, search: 'awesome' + end + + context 'state: closed' do + let(:state) { 'closed' } + + include_examples 'filter by state', scope: :merge_requests, search: 'awesome' + end end end |