diff options
author | Bob Van Landuyt <bob@vanlanduyt.co> | 2018-07-10 16:19:45 +0200 |
---|---|---|
committer | Bob Van Landuyt <bob@vanlanduyt.co> | 2018-07-25 18:37:12 +0200 |
commit | 3bcb04f100f5e982379fbeae37a30a191581d1ef (patch) | |
tree | e01065b8a6728bcc75af16166baafcbddd1a6cf5 /spec/graphql/mutations | |
parent | 9fe58f5a23f2960f666c4d641b463c744138d29c (diff) | |
download | gitlab-ce-3bcb04f100f5e982379fbeae37a30a191581d1ef.tar.gz |
Add mutation toggling WIP state of merge requests
This is mainly the setup of mutations for GraphQL. Including
authorization and basic return type-structure.
Diffstat (limited to 'spec/graphql/mutations')
-rw-r--r-- | spec/graphql/mutations/concerns/mutations/resolves_project_spec.rb | 19 | ||||
-rw-r--r-- | spec/graphql/mutations/merge_requests/set_wip_spec.rb | 51 |
2 files changed, 70 insertions, 0 deletions
diff --git a/spec/graphql/mutations/concerns/mutations/resolves_project_spec.rb b/spec/graphql/mutations/concerns/mutations/resolves_project_spec.rb new file mode 100644 index 00000000000..19f5a8907a2 --- /dev/null +++ b/spec/graphql/mutations/concerns/mutations/resolves_project_spec.rb @@ -0,0 +1,19 @@ +require 'spec_helper' + +describe Mutations::ResolvesProject do + let(:mutation_class) do + Class.new(Mutations::BaseMutation) do + include Mutations::ResolvesProject + end + end + + let(:context) { double } + subject(:mutation) { mutation_class.new(object: nil, context: context) } + + it 'uses the ProjectsResolver to resolve projects by path' do + project = create(:project) + + expect(Resolvers::ProjectResolver).to receive(:new).with(object: nil, context: context).and_call_original + expect(mutation.resolve_project(full_path: project.full_path)).to eq(project) + end +end diff --git a/spec/graphql/mutations/merge_requests/set_wip_spec.rb b/spec/graphql/mutations/merge_requests/set_wip_spec.rb new file mode 100644 index 00000000000..e600abf3941 --- /dev/null +++ b/spec/graphql/mutations/merge_requests/set_wip_spec.rb @@ -0,0 +1,51 @@ +require 'spec_helper' + +describe Mutations::MergeRequests::SetWip do + let(:merge_request) { create(:merge_request) } + let(:user) { create(:user) } + subject(:mutation) { described_class.new(object: nil, context: { current_user: user }) } + + describe '#resolve' do + let(:wip) { true } + let(:mutated_merge_request) { subject[:merge_request] } + subject { mutation.resolve(project_path: merge_request.project.full_path, iid: merge_request.iid, wip: wip) } + + it 'raises an error if the resource is not accessible to the user' do + expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable) + end + + context 'when the user can update the merge request' do + before do + merge_request.project.add_developer(user) + end + + it 'returns the merge request as a wip' do + expect(mutated_merge_request).to eq(merge_request) + expect(mutated_merge_request).to be_work_in_progress + expect(subject[:errors]).to be_empty + end + + it 'returns errors merge request could not be updated' do + # Make the merge request invalid + merge_request.allow_broken = true + merge_request.update!(source_project: nil) + + expect(subject[:errors]).not_to be_empty + end + + context 'when passing wip as false' do + let(:wip) { false } + + it 'removes `wip` from the title' do + merge_request.update(title: "WIP: working on it") + + expect(mutated_merge_request).not_to be_work_in_progress + end + + it 'does not do anything if the title did not start with wip' do + expect(mutated_merge_request).not_to be_work_in_progress + end + end + end + end +end |