diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-02-20 13:49:51 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-02-20 13:49:51 +0000 |
commit | 71786ddc8e28fbd3cb3fcc4b3ff15e5962a1c82e (patch) | |
tree | 6a2d93ef3fb2d353bb7739e4b57e6541f51cdd71 /spec/graphql/mutations | |
parent | a7253423e3403b8c08f8a161e5937e1488f5f407 (diff) | |
download | gitlab-ce-71786ddc8e28fbd3cb3fcc4b3ff15e5962a1c82e.tar.gz |
Add latest changes from gitlab-org/gitlab@15-9-stable-eev15.9.0-rc42
Diffstat (limited to 'spec/graphql/mutations')
8 files changed, 213 insertions, 23 deletions
diff --git a/spec/graphql/mutations/achievements/create_spec.rb b/spec/graphql/mutations/achievements/create_spec.rb index 4bad6164314..12b8ff67549 100644 --- a/spec/graphql/mutations/achievements/create_spec.rb +++ b/spec/graphql/mutations/achievements/create_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Mutations::Achievements::Create, feature_category: :users do +RSpec.describe Mutations::Achievements::Create, feature_category: :user_profile do include GraphqlHelpers let_it_be(:user) { create(:user) } diff --git a/spec/graphql/mutations/ci/job_token_scope/add_project_spec.rb b/spec/graphql/mutations/ci/job_token_scope/add_project_spec.rb index 727db7e2361..44147987ebb 100644 --- a/spec/graphql/mutations/ci/job_token_scope/add_project_spec.rb +++ b/spec/graphql/mutations/ci/job_token_scope/add_project_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true require 'spec_helper' -RSpec.describe Mutations::Ci::JobTokenScope::AddProject do +RSpec.describe Mutations::Ci::JobTokenScope::AddProject, feature_category: :continuous_integration do let(:mutation) do described_class.new(object: nil, context: { current_user: current_user }, field: nil) end @@ -14,9 +14,10 @@ RSpec.describe Mutations::Ci::JobTokenScope::AddProject do let_it_be(:target_project) { create(:project) } let(:target_project_path) { target_project.full_path } + let(:mutation_args) { { project_path: project.full_path, target_project_path: target_project_path } } subject do - mutation.resolve(project_path: project.full_path, target_project_path: target_project_path) + mutation.resolve(**mutation_args) end context 'when user is not logged in' do @@ -42,18 +43,45 @@ RSpec.describe Mutations::Ci::JobTokenScope::AddProject do target_project.add_guest(current_user) end - it 'adds target project to the job token scope' do + it 'adds target project to the outbound job token scope by default' do expect do expect(subject).to include(ci_job_token_scope: be_present, errors: be_empty) - end.to change { Ci::JobToken::ProjectScopeLink.count }.by(1) + end.to change { Ci::JobToken::ProjectScopeLink.outbound.count }.by(1) + end + + context 'when mutation uses the direction argument' do + let(:mutation_args) { super().merge!(direction: direction) } + + context 'when targeting the outbound allowlist' do + let(:direction) { :outbound } + + it 'adds the target project' do + expect do + expect(subject).to include(ci_job_token_scope: be_present, errors: be_empty) + end.to change { Ci::JobToken::ProjectScopeLink.outbound.count }.by(1) + end + end + + context 'when targeting the inbound allowlist' do + let(:direction) { :inbound } + + it 'adds the target project' do + expect do + expect(subject).to include(ci_job_token_scope: be_present, errors: be_empty) + end.to change { Ci::JobToken::ProjectScopeLink.inbound.count }.by(1) + end + end end context 'when the service returns an error' do let(:service) { double(:service) } it 'returns an error response' do - expect(::Ci::JobTokenScope::AddProjectService).to receive(:new).with(project, current_user).and_return(service) - expect(service).to receive(:execute).with(target_project).and_return(ServiceResponse.error(message: 'The error message')) + expect(::Ci::JobTokenScope::AddProjectService).to receive(:new).with( + project, + current_user + ).and_return(service) + expect(service).to receive(:execute).with(target_project, direction: :outbound).and_return(ServiceResponse.error(message: 'The error message')) expect(subject.fetch(:ci_job_token_scope)).to be_nil expect(subject.fetch(:errors)).to include("The error message") diff --git a/spec/graphql/mutations/ci/job_token_scope/remove_project_spec.rb b/spec/graphql/mutations/ci/job_token_scope/remove_project_spec.rb index d399e73f394..5385b6ca1cf 100644 --- a/spec/graphql/mutations/ci/job_token_scope/remove_project_spec.rb +++ b/spec/graphql/mutations/ci/job_token_scope/remove_project_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true require 'spec_helper' -RSpec.describe Mutations::Ci::JobTokenScope::RemoveProject do +RSpec.describe Mutations::Ci::JobTokenScope::RemoveProject, feature_category: :continuous_integration do let(:mutation) do described_class.new(object: nil, context: { current_user: current_user }, field: nil) end @@ -17,6 +17,7 @@ RSpec.describe Mutations::Ci::JobTokenScope::RemoveProject do end let(:target_project_path) { target_project.full_path } + let(:links_relation) { Ci::JobToken::ProjectScopeLink.with_source(project).with_target(target_project) } subject do mutation.resolve(project_path: project.full_path, target_project_path: target_project_path) @@ -45,18 +46,40 @@ RSpec.describe Mutations::Ci::JobTokenScope::RemoveProject do target_project.add_guest(current_user) end - it 'removes target project from the job token scope' do - expect do - expect(subject).to include(ci_job_token_scope: be_present, errors: be_empty) - end.to change { Ci::JobToken::ProjectScopeLink.count }.by(-1) + let(:service) { instance_double('Ci::JobTokenScope::RemoveProjectService') } + + context 'with no direction specified' do + it 'defaults to asking the RemoveProjectService to remove the outbound link' do + expect(::Ci::JobTokenScope::RemoveProjectService) + .to receive(:new).with(project, current_user).and_return(service) + expect(service).to receive(:execute).with(target_project, :outbound) + .and_return(instance_double('ServiceResponse', "success?": true)) + + subject + end + end + + context 'with direction specified' do + subject do + mutation.resolve(project_path: project.full_path, target_project_path: target_project_path, direction: 'inbound') + end + + it 'executes project removal for the correct direction' do + expect(::Ci::JobTokenScope::RemoveProjectService) + .to receive(:new).with(project, current_user).and_return(service) + expect(service).to receive(:execute).with(target_project, 'inbound') + .and_return(instance_double('ServiceResponse', "success?": true)) + + subject + end end context 'when the service returns an error' do - let(:service) { double(:service) } + let(:service) { instance_double('Ci::JobTokenScope::RemoveProjectService') } it 'returns an error response' do expect(::Ci::JobTokenScope::RemoveProjectService).to receive(:new).with(project, current_user).and_return(service) - expect(service).to receive(:execute).with(target_project).and_return(ServiceResponse.error(message: 'The error message')) + expect(service).to receive(:execute).with(target_project, :outbound).and_return(ServiceResponse.error(message: 'The error message')) expect(subject.fetch(:ci_job_token_scope)).to be_nil expect(subject.fetch(:errors)).to include("The error message") diff --git a/spec/graphql/mutations/ci/pipeline_schedule/variable_input_type_spec.rb b/spec/graphql/mutations/ci/pipeline_schedule/variable_input_type_spec.rb new file mode 100644 index 00000000000..564bc95b352 --- /dev/null +++ b/spec/graphql/mutations/ci/pipeline_schedule/variable_input_type_spec.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Mutations::Ci::PipelineSchedule::VariableInputType, feature_category: :continuous_integration do + specify { expect(described_class.graphql_name).to eq('PipelineScheduleVariableInput') } + + it { expect(described_class.arguments.keys).to match_array(%w[key value variableType]) } +end diff --git a/spec/graphql/mutations/issues/update_spec.rb b/spec/graphql/mutations/issues/update_spec.rb index bb57ad4c404..324f225f209 100644 --- a/spec/graphql/mutations/issues/update_spec.rb +++ b/spec/graphql/mutations/issues/update_spec.rb @@ -46,10 +46,12 @@ RSpec.describe Mutations::Issues::Update do project.add_developer(user) end - it 'updates issue with correct values' do - subject + context 'when all attributes except timeEstimate are provided' do + it 'updates issue with correct values' do + subject - expect(issue.reload).to have_attributes(expected_attributes) + expect(issue.reload).to have_attributes(expected_attributes) + end end context 'when iid does not exist' do @@ -162,6 +164,39 @@ RSpec.describe Mutations::Issues::Update do expect { subject }.to change { issue.reload.issue_type }.from('issue').to('incident') end end + + context 'when timeEstimate attribute is provided' do + let_it_be_with_refind(:issue) { create(:issue, project: project, time_estimate: 3600) } + + let(:time_estimate) { '0' } + let(:expected_attributes) { { time_estimate: time_estimate } } + + context 'when timeEstimate is invalid' do + let(:time_estimate) { '1e' } + + it 'raises an argument error and changes are not applied' do + expect { mutation.ready?(time_estimate: time_estimate) } + .to raise_error(Gitlab::Graphql::Errors::ArgumentError, 'timeEstimate must be formatted correctly, for example `1h 30m`') + expect { subject }.not_to change { issue.reload.time_estimate } + end + end + + context 'when timeEstimate is 0' do + let(:time_estimate) { '0' } + + it 'resets the time estimate' do + expect { subject }.to change { issue.reload.time_estimate }.from(3600).to(0) + end + end + + context 'when timeEstimate is a valid human readable time' do + let(:time_estimate) { '1h 30m' } + + it 'updates the time estimate' do + expect { subject }.to change { issue.reload.time_estimate }.from(3600).to(5400) + end + end + end end end end diff --git a/spec/graphql/mutations/merge_requests/update_spec.rb b/spec/graphql/mutations/merge_requests/update_spec.rb index 206abaf34ce..8a10f6cadd0 100644 --- a/spec/graphql/mutations/merge_requests/update_spec.rb +++ b/spec/graphql/mutations/merge_requests/update_spec.rb @@ -26,10 +26,56 @@ RSpec.describe Mutations::MergeRequests::Update do merge_request.project.add_developer(user) end - it 'applies all attributes' do - expect(mutated_merge_request).to eq(merge_request) - expect(mutated_merge_request).to have_attributes(attributes) - expect(subject[:errors]).to be_empty + context 'when all attributes except timeEstimate are provided' do + before do + merge_request.update!(time_estimate: 3600) + end + + it 'applies all attributes' do + expect(mutated_merge_request).to eq(merge_request) + expect(mutated_merge_request).to have_attributes(attributes) + expect(mutated_merge_request.time_estimate).to eq(3600) + expect(subject[:errors]).to be_empty + end + end + + context 'when timeEstimate attribute is provided' do + let(:time_estimate) { '0' } + let(:attributes) { { time_estimate: time_estimate } } + + before do + merge_request.update!(time_estimate: 3600) + end + + context 'when timeEstimate is invalid' do + let(:time_estimate) { '1e' } + + it 'changes are not applied' do + expect { mutation.ready?(time_estimate: time_estimate) } + .to raise_error( + Gitlab::Graphql::Errors::ArgumentError, + 'timeEstimate must be formatted correctly, for example `1h 30m`') + expect(mutated_merge_request.time_estimate).to eq(3600) + end + end + + context 'when timeEstimate is 0' do + let(:time_estimate) { '0' } + + it 'resets the time estimate' do + expect(mutated_merge_request.time_estimate).to eq(0) + expect(subject[:errors]).to be_empty + end + end + + context 'when timeEstimate is a valid human readable time' do + let(:time_estimate) { '1h 30m' } + + it 'updates the time estimate' do + expect(mutated_merge_request.time_estimate).to eq(5400) + expect(subject[:errors]).to be_empty + end + end end context 'the merge request is invalid' do @@ -82,4 +128,53 @@ RSpec.describe Mutations::MergeRequests::Update do end end end + + describe '#ready?' do + let(:extra_args) { {} } + + let(:arguments) do + { + project_path: merge_request.project.full_path, + iid: merge_request.iid + }.merge(extra_args) + end + + subject(:ready) { mutation.ready?(**arguments) } + + context 'when required arguments are not provided' do + let(:arguments) { {} } + + it 'raises an argument error' do + expect { subject }.to raise_error(ArgumentError, 'Arguments must be provided: projectPath, iid') + end + end + + context 'when required arguments are provided' do + it 'returns true' do + expect(subject).to eq(true) + end + end + + context 'when timeEstimate is provided' do + let(:extra_args) { { time_estimate: time_estimate } } + + context 'when the value is invalid' do + let(:time_estimate) { '1e' } + + it 'raises an argument error' do + expect { subject }.to raise_error( + Gitlab::Graphql::Errors::ArgumentError, + 'timeEstimate must be formatted correctly, for example `1h 30m`') + end + end + + context 'when the value valid' do + let(:time_estimate) { '1d' } + + it 'returns true' do + expect(subject).to eq(true) + end + end + end + end end diff --git a/spec/graphql/mutations/saved_replies/create_spec.rb b/spec/graphql/mutations/saved_replies/create_spec.rb index 5141c537b06..9423ba2b354 100644 --- a/spec/graphql/mutations/saved_replies/create_spec.rb +++ b/spec/graphql/mutations/saved_replies/create_spec.rb @@ -33,7 +33,7 @@ RSpec.describe Mutations::SavedReplies::Create do let(:mutation_arguments) { { name: '', content: '' } } it { expect(subject[:saved_reply]).to be_nil } - it { expect(subject[:errors]).to match_array(["Content can't be blank", "Name can't be blank", "Name can contain only lowercase letters, digits, '_' and '-'. Must start with a letter, and cannot end with '-' or '_'"]) } + it { expect(subject[:errors]).to match_array(["Content can't be blank", "Name can't be blank"]) } end context 'when service successfully creates a new saved reply' do diff --git a/spec/graphql/mutations/saved_replies/update_spec.rb b/spec/graphql/mutations/saved_replies/update_spec.rb index 67c2d1348f7..9b0e90b7b41 100644 --- a/spec/graphql/mutations/saved_replies/update_spec.rb +++ b/spec/graphql/mutations/saved_replies/update_spec.rb @@ -34,7 +34,7 @@ RSpec.describe Mutations::SavedReplies::Update do let(:mutation_arguments) { { name: '', content: '' } } it { expect(subject[:saved_reply]).to be_nil } - it { expect(subject[:errors]).to match_array(["Content can't be blank", "Name can't be blank", "Name can contain only lowercase letters, digits, '_' and '-'. Must start with a letter, and cannot end with '-' or '_'"]) } + it { expect(subject[:errors]).to match_array(["Content can't be blank", "Name can't be blank"]) } end context 'when service successfully updates the saved reply' do |