diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-20 15:26:25 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-20 15:26:25 +0300 |
commit | a09983ae35713f5a2bbb100981116d31ce99826e (patch) | |
tree | 2ee2af7bd104d57086db360a7e6d8c9d5d43667a /spec/requests/api/projects_spec.rb | |
parent | 18c5ab32b738c0b6ecb4d0df3994000482f34bd8 (diff) |
Add latest changes from gitlab-org/gitlab@13-2-stable-ee
Diffstat (limited to 'spec/requests/api/projects_spec.rb')
-rw-r--r-- | spec/requests/api/projects_spec.rb | 117 |
1 files changed, 113 insertions, 4 deletions
diff --git a/spec/requests/api/projects_spec.rb b/spec/requests/api/projects_spec.rb index c3f29ec47a9..76b0c04e32d 100644 --- a/spec/requests/api/projects_spec.rb +++ b/spec/requests/api/projects_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -shared_examples 'languages and percentages JSON response' do +RSpec.shared_examples 'languages and percentages JSON response' do let(:expected_languages) { project.repository.languages.map { |language| language.values_at(:label, :value)}.to_h } before do @@ -46,7 +46,7 @@ shared_examples 'languages and percentages JSON response' do end end -describe API::Projects do +RSpec.describe API::Projects do include ProjectForksHelper let(:user) { create(:user) } @@ -254,7 +254,10 @@ describe API::Projects do expect(response).to have_gitlab_http_status(:ok) expect(response).to include_pagination_headers expect(json_response).to be_an Array - expect(json_response.first).to include 'statistics' + + statistics = json_response.first['statistics'] + expect(statistics).to be_present + expect(statistics).to include('commit_count', 'storage_size', 'repository_size', 'wiki_size', 'lfs_objects_size', 'job_artifacts_size', 'snippets_size') end it "does not include license by default" do @@ -584,6 +587,85 @@ describe API::Projects do end end + context 'sorting by project statistics' do + %w(repository_size storage_size wiki_size).each do |order_by| + context "sorting by #{order_by}" do + before do + ProjectStatistics.update_all(order_by => 100) + project4.statistics.update_columns(order_by => 10) + project.statistics.update_columns(order_by => 200) + end + + context 'admin user' do + let(:current_user) { admin } + + context "when sorting by #{order_by} ascendingly" do + it 'returns a properly sorted list of projects' do + get api('/projects', current_user), params: { order_by: order_by, sort: :asc } + + expect(response).to have_gitlab_http_status(:ok) + expect(response).to include_pagination_headers + expect(json_response).to be_an Array + expect(json_response.first['id']).to eq(project4.id) + end + end + + context "when sorting by #{order_by} descendingly" do + it 'returns a properly sorted list of projects' do + get api('/projects', current_user), params: { order_by: order_by, sort: :desc } + + expect(response).to have_gitlab_http_status(:ok) + expect(response).to include_pagination_headers + expect(json_response).to be_an Array + expect(json_response.first['id']).to eq(project.id) + end + end + end + + context 'non-admin user' do + let(:current_user) { user } + let(:projects) { [public_project, project, project2, project3] } + + it 'returns projects ordered normally' do + get api('/projects', current_user), params: { order_by: order_by } + + expect(response).to have_gitlab_http_status(:ok) + expect(response).to include_pagination_headers + expect(json_response).to be_an Array + expect(json_response.map { |project| project['id'] }).to eq(projects.map(&:id).reverse) + end + end + end + end + end + + context 'filtering by repository_storage' do + before do + [project, project3].each { |proj| proj.update_columns(repository_storage: 'nfs-11') } + # Since we don't actually have Gitaly configured with an nfs-11 storage, an error would be raised + # when we present the projects in a response, as we ask Gitaly for stuff like default branch and Gitaly + # is not configured for a nfs-11 storage. So we trick Rails into thinking the storage for these projects + # is still default (in reality, it is). + allow_any_instance_of(Project).to receive(:repository_storage).and_return('default') + end + + context 'admin user' do + it_behaves_like 'projects response' do + let(:filter) { { repository_storage: 'nfs-11' } } + let(:current_user) { admin } + let(:projects) { [project, project3] } + end + end + + context 'non-admin user' do + it_behaves_like 'projects response' do + let(:filter) { { repository_storage: 'nfs-11' } } + let(:current_user) { user } + let(:projects) { [public_project, project, project2, project3] } + end + end + end + context 'with keyset pagination' do let(:current_user) { user } let(:projects) { [public_project, project, project2, project3] } @@ -1846,6 +1928,13 @@ describe API::Projects do end end end + + it 'exposes service desk attributes' do + get api("/projects/#{project.id}", user) + + expect(json_response).to have_key 'service_desk_enabled' + expect(json_response).to have_key 'service_desk_address' + end end describe 'GET /projects/:id/users' do @@ -2133,7 +2222,7 @@ describe API::Projects do expect(json_response['expires_at']).to eq(expires_at.to_s) end - it 'updates project authorization' do + it 'updates project authorization', :sidekiq_inline do expect do post api("/projects/#{project.id}/share", user), params: { group_id: group.id, group_access: Gitlab::Access::DEVELOPER } end.to( @@ -2590,6 +2679,26 @@ describe API::Projects do end end end + + context 'when updating service desk' do + subject { put(api("/projects/#{project.id}", user), params: { service_desk_enabled: true }) } + + before do + project.update!(service_desk_enabled: false) + + allow(::Gitlab::IncomingEmail).to receive(:enabled?).and_return(true) + end + + it 'returns 200' do + subject + + expect(response).to have_gitlab_http_status(:ok) + end + + it 'enables the service_desk' do + expect { subject }.to change { project.reload.service_desk_enabled }.to(true) + end + end end describe 'POST /projects/:id/archive' do |