diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-10-03 12:09:43 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-10-03 12:09:43 +0300 |
commit | 10d4625ed3b73f73bc67bf7d35347dcd1912cf7b (patch) | |
tree | ee42f413ec64e2a60550d741e8428615ecafb393 /spec/requests | |
parent | f743b4205666c85465eb6c6b0487414e6ec331da (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/requests')
-rw-r--r-- | spec/requests/api/ci/resource_groups_spec.rb | 42 | ||||
-rw-r--r-- | spec/requests/api/graphql/project/issues_spec.rb | 24 | ||||
-rw-r--r-- | spec/requests/api/graphql/project/merge_requests_spec.rb | 21 | ||||
-rw-r--r-- | spec/requests/api/metadata_spec.rb | 26 | ||||
-rw-r--r-- | spec/requests/api/version_spec.rb | 93 |
5 files changed, 98 insertions, 108 deletions
diff --git a/spec/requests/api/ci/resource_groups_spec.rb b/spec/requests/api/ci/resource_groups_spec.rb index 864c363e6d3..87df71f6096 100644 --- a/spec/requests/api/ci/resource_groups_spec.rb +++ b/spec/requests/api/ci/resource_groups_spec.rb @@ -77,6 +77,48 @@ RSpec.describe API::Ci::ResourceGroups do end end + describe 'GET /projects/:id/resource_groups/:key/upcoming_jobs' do + subject { get api("/projects/#{project.id}/resource_groups/#{key}/upcoming_jobs", user) } + + let_it_be(:resource_group) { create(:ci_resource_group, project: project) } + let_it_be(:processable) { create(:ci_processable, resource_group: resource_group) } + let_it_be(:upcoming_processable) { create(:ci_processable, :waiting_for_resource, resource_group: resource_group) } + + let(:key) { resource_group.key } + + it 'returns upcoming jobs of resource group', :aggregate_failures do + subject + + expect(response).to have_gitlab_http_status(:ok) + expect(json_response.length).to eq(1) + expect(json_response[0]['id']).to eq(upcoming_processable.id) + expect(json_response[0]['name']).to eq(upcoming_processable.name) + expect(json_response[0]['ref']).to eq(upcoming_processable.ref) + expect(json_response[0]['stage']).to eq(upcoming_processable.stage) + expect(json_response[0]['status']).to eq(upcoming_processable.status) + end + + context 'when user is reporter' do + let(:user) { reporter } + + it 'returns forbidden' do + subject + + expect(response).to have_gitlab_http_status(:forbidden) + end + end + + context 'when there is no corresponding resource group' do + let(:key) { 'unknown' } + + it 'returns not found' do + subject + + expect(response).to have_gitlab_http_status(:not_found) + end + end + end + describe 'PUT /projects/:id/resource_groups/:key' do subject { put api("/projects/#{project.id}/resource_groups/#{key}", user), params: params } diff --git a/spec/requests/api/graphql/project/issues_spec.rb b/spec/requests/api/graphql/project/issues_spec.rb index fe885c3cea7..163f9d02a3b 100644 --- a/spec/requests/api/graphql/project/issues_spec.rb +++ b/spec/requests/api/graphql/project/issues_spec.rb @@ -686,6 +686,30 @@ RSpec.describe 'getting an issue list for a project' do include_examples 'N+1 query check' end + + context 'when requesting participants' do + let_it_be(:issue_c) { create(:issue, project: project) } + + let(:search_params) { { iids: [issue_a.iid.to_s, issue_c.iid.to_s] } } + let(:requested_fields) { 'participants { nodes { name } }' } + + before do + create(:award_emoji, :upvote, awardable: issue_a) + create(:award_emoji, :upvote, awardable: issue_b) + create(:award_emoji, :upvote, awardable: issue_c) + + note_with_emoji_a = create(:note_on_issue, noteable: issue_a, project: project) + note_with_emoji_b = create(:note_on_issue, noteable: issue_b, project: project) + note_with_emoji_c = create(:note_on_issue, noteable: issue_c, project: project) + + create(:award_emoji, :upvote, awardable: note_with_emoji_a) + create(:award_emoji, :upvote, awardable: note_with_emoji_b) + create(:award_emoji, :upvote, awardable: note_with_emoji_c) + end + + # Executes 3 extra queries to fetch participant_attrs + include_examples 'N+1 query check', 3 + end end def issues_ids diff --git a/spec/requests/api/graphql/project/merge_requests_spec.rb b/spec/requests/api/graphql/project/merge_requests_spec.rb index 76660d510b4..ef83f9be8ac 100644 --- a/spec/requests/api/graphql/project/merge_requests_spec.rb +++ b/spec/requests/api/graphql/project/merge_requests_spec.rb @@ -338,6 +338,27 @@ RSpec.describe 'getting merge request listings nested in a project' do include_examples 'N+1 query check' end + + context 'when requesting participants' do + let(:requested_fields) { 'participants { nodes { name } }' } + + before do + create(:award_emoji, :upvote, awardable: merge_request_a) + create(:award_emoji, :upvote, awardable: merge_request_b) + create(:award_emoji, :upvote, awardable: merge_request_c) + + note_with_emoji_a = create(:note_on_merge_request, noteable: merge_request_a, project: project) + note_with_emoji_b = create(:note_on_merge_request, noteable: merge_request_b, project: project) + note_with_emoji_c = create(:note_on_merge_request, noteable: merge_request_c, project: project) + + create(:award_emoji, :upvote, awardable: note_with_emoji_a) + create(:award_emoji, :upvote, awardable: note_with_emoji_b) + create(:award_emoji, :upvote, awardable: note_with_emoji_c) + end + + # Executes 3 extra queries to fetch participant_attrs + include_examples 'N+1 query check', 3 + end end describe 'performance' do diff --git a/spec/requests/api/metadata_spec.rb b/spec/requests/api/metadata_spec.rb index dbca06b7f3e..5b6407c689b 100644 --- a/spec/requests/api/metadata_spec.rb +++ b/spec/requests/api/metadata_spec.rb @@ -6,7 +6,7 @@ RSpec.describe API::Metadata do shared_examples_for 'GET /metadata' do context 'when unauthenticated' do it 'returns authentication error' do - get api('/metadata') + get api(endpoint) expect(response).to have_gitlab_http_status(:unauthorized) end @@ -16,7 +16,7 @@ RSpec.describe API::Metadata do let(:user) { create(:user) } it 'returns the metadata information' do - get api('/metadata', user) + get api(endpoint, user) expect_metadata end @@ -29,13 +29,13 @@ RSpec.describe API::Metadata do let(:scopes) { %i(api) } it 'returns the metadata information' do - get api('/metadata', personal_access_token: personal_access_token) + get api(endpoint, personal_access_token: personal_access_token) expect_metadata end it 'returns "200" response on head requests' do - head api('/metadata', personal_access_token: personal_access_token) + head api(endpoint, personal_access_token: personal_access_token) expect(response).to have_gitlab_http_status(:ok) end @@ -45,13 +45,13 @@ RSpec.describe API::Metadata do let(:scopes) { %i(read_user) } it 'returns the metadata information' do - get api('/metadata', personal_access_token: personal_access_token) + get api(endpoint, personal_access_token: personal_access_token) expect_metadata end it 'returns "200" response on head requests' do - head api('/metadata', personal_access_token: personal_access_token) + head api(endpoint, personal_access_token: personal_access_token) expect(response).to have_gitlab_http_status(:ok) end @@ -61,7 +61,7 @@ RSpec.describe API::Metadata do let(:scopes) { %i(read_repository) } it 'returns authorization error' do - get api('/metadata', personal_access_token: personal_access_token) + get api(endpoint, personal_access_token: personal_access_token) expect(response).to have_gitlab_http_status(:forbidden) end @@ -76,18 +76,14 @@ RSpec.describe API::Metadata do end end - context 'with graphql enabled' do - before do - stub_feature_flags(graphql: true) - end + describe 'GET /metadata' do + let(:endpoint) { '/metadata' } include_examples 'GET /metadata' end - context 'with graphql disabled' do - before do - stub_feature_flags(graphql: false) - end + describe 'GET /version' do + let(:endpoint) { '/version' } include_examples 'GET /metadata' end diff --git a/spec/requests/api/version_spec.rb b/spec/requests/api/version_spec.rb deleted file mode 100644 index 7abbaf4f9ec..00000000000 --- a/spec/requests/api/version_spec.rb +++ /dev/null @@ -1,93 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe API::Version do - shared_examples_for 'GET /version' do - context 'when unauthenticated' do - it 'returns authentication error' do - get api('/version') - - expect(response).to have_gitlab_http_status(:unauthorized) - end - end - - context 'when authenticated as user' do - let(:user) { create(:user) } - - it 'returns the version information' do - get api('/version', user) - - expect_version - end - end - - context 'when authenticated with token' do - let(:personal_access_token) { create(:personal_access_token, scopes: scopes) } - - context 'with api scope' do - let(:scopes) { %i(api) } - - it 'returns the version information' do - get api('/version', personal_access_token: personal_access_token) - - expect_version - end - - it 'returns "200" response on head requests' do - head api('/version', personal_access_token: personal_access_token) - - expect(response).to have_gitlab_http_status(:ok) - end - end - - context 'with read_user scope' do - let(:scopes) { %i(read_user) } - - it 'returns the version information' do - get api('/version', personal_access_token: personal_access_token) - - expect_version - end - - it 'returns "200" response on head requests' do - head api('/version', personal_access_token: personal_access_token) - - expect(response).to have_gitlab_http_status(:ok) - end - end - - context 'with neither api nor read_user scope' do - let(:scopes) { %i(read_repository) } - - it 'returns authorization error' do - get api('/version', personal_access_token: personal_access_token) - - expect(response).to have_gitlab_http_status(:forbidden) - end - end - end - - def expect_version - expect(response).to have_gitlab_http_status(:ok) - expect(json_response['version']).to eq(Gitlab::VERSION) - expect(json_response['revision']).to eq(Gitlab.revision) - end - end - - context 'with graphql enabled' do - before do - stub_feature_flags(graphql: true) - end - - include_examples 'GET /version' - end - - context 'with graphql disabled' do - before do - stub_feature_flags(graphql: false) - end - - include_examples 'GET /version' - end -end |