diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-05 15:09:15 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-05 15:09:15 +0300 |
commit | 20d564f1064622ef0623434372ac3ceb03173331 (patch) | |
tree | 000d95440566cd189ea774168c9756bcc8fc5fae /spec/requests | |
parent | 26384c9a61da9922b8fa4b8351d4e42d51661b37 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/requests')
-rw-r--r-- | spec/requests/api/graphql/group/milestones_spec.rb | 85 | ||||
-rw-r--r-- | spec/requests/api/projects_spec.rb | 17 | ||||
-rw-r--r-- | spec/requests/api/runner_spec.rb | 42 |
3 files changed, 140 insertions, 4 deletions
diff --git a/spec/requests/api/graphql/group/milestones_spec.rb b/spec/requests/api/graphql/group/milestones_spec.rb new file mode 100644 index 00000000000..84b14470fd1 --- /dev/null +++ b/spec/requests/api/graphql/group/milestones_spec.rb @@ -0,0 +1,85 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe 'Milestones through GroupQuery' do + include GraphqlHelpers + + let_it_be(:user) { create(:user) } + let_it_be(:now) { Time.now } + let_it_be(:group) { create(:group, :private) } + let_it_be(:milestone_1) { create(:milestone, group: group) } + let_it_be(:milestone_2) { create(:milestone, group: group, state: :closed, start_date: now, due_date: now + 1.day) } + let_it_be(:milestone_3) { create(:milestone, group: group, start_date: now, due_date: now + 2.days) } + let_it_be(:milestone_4) { create(:milestone, group: group, state: :closed, start_date: now - 2.days, due_date: now - 1.day) } + let_it_be(:milestone_from_other_group) { create(:milestone, group: create(:group)) } + + let(:milestone_data) { graphql_data['group']['milestones']['edges'] } + + describe 'Get list of milestones from a group' do + before do + group.add_developer(user) + end + + context 'when the request is correct' do + before do + fetch_milestones(user) + end + + it_behaves_like 'a working graphql query' + + it 'returns milestones successfully' do + expect(response).to have_gitlab_http_status(200) + expect(graphql_errors).to be_nil + expect_array_response(milestone_1.to_global_id.to_s, milestone_2.to_global_id.to_s, milestone_3.to_global_id.to_s, milestone_4.to_global_id.to_s) + end + end + + context 'when filtering by timeframe' do + it 'fetches milestones between start_date and due_date' do + fetch_milestones(user, { start_date: now.to_s, end_date: (now + 2.days).to_s }) + + expect_array_response(milestone_2.to_global_id.to_s, milestone_3.to_global_id.to_s) + end + end + + context 'when filtering by state' do + it 'returns milestones with given state' do + fetch_milestones(user, { state: :active }) + + expect_array_response(milestone_1.to_global_id.to_s, milestone_3.to_global_id.to_s) + end + end + + def fetch_milestones(user = nil, args = {}) + post_graphql(milestones_query(args), current_user: user) + end + + def milestones_query(args = {}) + milestone_node = <<~NODE + edges { + node { + id + title + state + } + } + NODE + + graphql_query_for("group", + { full_path: group.full_path }, + [query_graphql_field("milestones", args, milestone_node)] + ) + end + + def expect_array_response(*items) + expect(response).to have_gitlab_http_status(:success) + expect(milestone_data).to be_an Array + expect(milestone_node_array('id')).to match_array(items) + end + + def milestone_node_array(extract_attribute = nil) + node_array(milestone_data, extract_attribute) + end + end +end diff --git a/spec/requests/api/projects_spec.rb b/spec/requests/api/projects_spec.rb index e88209081d4..2b9ec4319f5 100644 --- a/spec/requests/api/projects_spec.rb +++ b/spec/requests/api/projects_spec.rb @@ -1402,6 +1402,7 @@ describe API::Projects do expect(json_response['merge_requests_access_level']).to be_present expect(json_response['wiki_access_level']).to be_present expect(json_response['builds_access_level']).to be_present + expect(json_response).to have_key('emails_disabled') expect(json_response['resolve_outdated_diff_discussions']).to eq(project.resolve_outdated_diff_discussions) expect(json_response['remove_source_branch_after_merge']).to be_truthy expect(json_response['container_registry_enabled']).to be_present @@ -1412,18 +1413,18 @@ describe API::Projects do expect(json_response['namespace']).to be_present expect(json_response['import_status']).to be_present expect(json_response).to include("import_error") - expect(json_response['avatar_url']).to be_nil + expect(json_response).to have_key('avatar_url') expect(json_response['star_count']).to be_present expect(json_response['forks_count']).to be_present expect(json_response['public_jobs']).to be_present - expect(json_response['ci_config_path']).to be_nil + expect(json_response).to have_key('ci_config_path') expect(json_response['shared_with_groups']).to be_an Array expect(json_response['shared_with_groups'].length).to eq(1) expect(json_response['shared_with_groups'][0]['group_id']).to eq(group.id) expect(json_response['shared_with_groups'][0]['group_name']).to eq(group.name) expect(json_response['shared_with_groups'][0]['group_full_path']).to eq(group.full_path) expect(json_response['shared_with_groups'][0]['group_access_level']).to eq(link.group_access) - expect(json_response['shared_with_groups'][0]['expires_at']).to be_nil + expect(json_response['shared_with_groups'][0]).to have_key('expires_at') expect(json_response['only_allow_merge_if_pipeline_succeeds']).to eq(project.only_allow_merge_if_pipeline_succeeds) expect(json_response['only_allow_merge_if_all_discussions_are_resolved']).to eq(project.only_allow_merge_if_all_discussions_are_resolved) expect(json_response['ci_default_git_depth']).to eq(project.ci_default_git_depth) @@ -2243,6 +2244,16 @@ describe API::Projects do expect(json_response['pages_access_level']).to eq('private') end + it 'updates emails_disabled' do + project_param = { emails_disabled: true } + + put api("/projects/#{project3.id}", user), params: project_param + + expect(response).to have_gitlab_http_status(200) + + expect(json_response['emails_disabled']).to eq(true) + end + it 'updates build_git_strategy' do project_param = { build_git_strategy: 'clone' } diff --git a/spec/requests/api/runner_spec.rb b/spec/requests/api/runner_spec.rb index e3ba366dfcc..23ce17b14fc 100644 --- a/spec/requests/api/runner_spec.rb +++ b/spec/requests/api/runner_spec.rb @@ -1607,7 +1607,7 @@ describe API::Runner, :clean_gitlab_redis_shared_state do it_behaves_like 'successful artifacts upload' end - context 'for file stored remotelly' do + context 'for file stored remotely' do let!(:fog_connection) do stub_artifacts_object_storage(direct_upload: true) end @@ -1894,6 +1894,46 @@ describe API::Runner, :clean_gitlab_redis_shared_state do end end + context 'when artifacts already exist for the job' do + let(:params) do + { + artifact_type: :archive, + artifact_format: :zip, + 'file.sha256' => uploaded_sha256 + } + end + + let(:existing_sha256) { '0' * 64 } + + let!(:existing_artifact) do + create(:ci_job_artifact, :archive, file_sha256: existing_sha256, job: job) + end + + context 'when sha256 is the same of the existing artifact' do + let(:uploaded_sha256) { existing_sha256 } + + it 'ignores the new artifact' do + upload_artifacts(file_upload, headers_with_token, params) + + expect(response).to have_gitlab_http_status(:created) + expect(job.reload.job_artifacts_archive).to eq(existing_artifact) + end + end + + context 'when sha256 is different than the existing artifact' do + let(:uploaded_sha256) { '1' * 64 } + + it 'logs and returns an error' do + expect(Gitlab::ErrorTracking).to receive(:track_exception) + + upload_artifacts(file_upload, headers_with_token, params) + + expect(response).to have_gitlab_http_status(:bad_request) + expect(job.reload.job_artifacts_archive).to eq(existing_artifact) + end + end + end + context 'when artifacts are being stored outside of tmp path' do let(:new_tmpdir) { Dir.mktmpdir } |