diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 21:42:06 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 21:42:06 +0300 |
commit | 6e4e1050d9dba2b7b2523fdd1768823ab85feef4 (patch) | |
tree | 78be5963ec075d80116a932011d695dd33910b4e /spec/graphql/mutations/boards/issues/issue_move_list_spec.rb | |
parent | 1ce776de4ae122aba3f349c02c17cebeaa8ecf07 (diff) |
Add latest changes from gitlab-org/gitlab@13-3-stable-ee
Diffstat (limited to 'spec/graphql/mutations/boards/issues/issue_move_list_spec.rb')
-rw-r--r-- | spec/graphql/mutations/boards/issues/issue_move_list_spec.rb | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/spec/graphql/mutations/boards/issues/issue_move_list_spec.rb b/spec/graphql/mutations/boards/issues/issue_move_list_spec.rb new file mode 100644 index 00000000000..71c43ed826c --- /dev/null +++ b/spec/graphql/mutations/boards/issues/issue_move_list_spec.rb @@ -0,0 +1,90 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Mutations::Boards::Issues::IssueMoveList do + let_it_be(:group) { create(:group, :public) } + let_it_be(:project) { create(:project, group: group) } + let_it_be(:board) { create(:board, group: group) } + let_it_be(:user) { create(:user) } + let_it_be(:guest) { create(:user) } + let_it_be(:development) { create(:label, project: project, name: 'Development') } + let_it_be(:testing) { create(:label, project: project, name: 'Testing') } + let_it_be(:list1) { create(:list, board: board, label: development, position: 0) } + let_it_be(:list2) { create(:list, board: board, label: testing, position: 1) } + let_it_be(:issue1) { create(:labeled_issue, project: project, labels: [development]) } + let_it_be(:existing_issue1) { create(:labeled_issue, project: project, labels: [testing], relative_position: 10) } + let_it_be(:existing_issue2) { create(:labeled_issue, project: project, labels: [testing], relative_position: 50) } + + let(:current_user) { user } + let(:mutation) { described_class.new(object: nil, context: { current_user: current_user }, field: nil) } + let(:params) { { board: board, project_path: project.full_path, iid: issue1.iid } } + let(:move_params) do + { + from_list_id: list1.id, + to_list_id: list2.id, + move_before_id: existing_issue2.id, + move_after_id: existing_issue1.id + } + end + + before_all do + group.add_maintainer(user) + group.add_guest(guest) + end + + subject do + mutation.resolve(params.merge(move_params)) + end + + describe '#ready?' do + it 'raises an error if required arguments are missing' do + expect { mutation.ready?(params) } + .to raise_error(Gitlab::Graphql::Errors::ArgumentError, "At least one of the arguments " \ + "fromListId, toListId, afterId or beforeId is required") + end + + it 'raises an error if only one of fromListId and toListId is present' do + expect { mutation.ready?(params.merge(from_list_id: list1.id)) } + .to raise_error(Gitlab::Graphql::Errors::ArgumentError, + 'Both fromListId and toListId must be present' + ) + end + end + + describe '#resolve' do + context 'when user have access to resources' do + it 'moves and repositions issue' do + subject + + expect(issue1.reload.labels).to eq([testing]) + expect(issue1.relative_position).to be < existing_issue2.relative_position + expect(issue1.relative_position).to be > existing_issue1.relative_position + end + end + + context 'when user have no access to resources' do + shared_examples 'raises a resource not available error' do + it { expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable) } + end + + context 'when user cannot update issue' do + let(:current_user) { guest } + + it_behaves_like 'raises a resource not available error' + end + + context 'when user cannot access board' do + let(:board) { create(:board, group: create(:group, :private)) } + + it_behaves_like 'raises a resource not available error' + end + + context 'when passing board_id as nil' do + let(:board) { nil } + + it_behaves_like 'raises a resource not available error' + end + end + end +end |