diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-06-20 11:10:13 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-06-20 11:10:13 +0000 |
commit | 0ea3fcec397b69815975647f5e2aa5fe944a8486 (patch) | |
tree | 7979381b89d26011bcf9bdc989a40fcc2f1ed4ff /spec/graphql/mutations/work_items | |
parent | 72123183a20411a36d607d70b12d57c484394c8e (diff) | |
download | gitlab-ce-0ea3fcec397b69815975647f5e2aa5fe944a8486.tar.gz |
Add latest changes from gitlab-org/gitlab@15-1-stable-eev15.1.0-rc42
Diffstat (limited to 'spec/graphql/mutations/work_items')
-rw-r--r-- | spec/graphql/mutations/work_items/update_task_spec.rb | 40 | ||||
-rw-r--r-- | spec/graphql/mutations/work_items/update_widgets_spec.rb | 58 |
2 files changed, 98 insertions, 0 deletions
diff --git a/spec/graphql/mutations/work_items/update_task_spec.rb b/spec/graphql/mutations/work_items/update_task_spec.rb new file mode 100644 index 00000000000..cb93e97504a --- /dev/null +++ b/spec/graphql/mutations/work_items/update_task_spec.rb @@ -0,0 +1,40 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Mutations::WorkItems::UpdateTask do + let_it_be(:project) { create(:project) } + let_it_be(:developer) { create(:user).tap { |user| project.add_developer(user) } } + let_it_be(:referenced_work_item, refind: true) { create(:work_item, project: project, title: 'REFERENCED') } + let_it_be(:parent_work_item) do + create(:work_item, project: project, description: "- [ ] #{referenced_work_item.to_reference}+") + end + + let(:task_params) { { title: 'UPDATED' } } + let(:task_input) { { id: referenced_work_item.to_global_id }.merge(task_params) } + let(:input) { { id: parent_work_item.to_global_id, task_data: task_input } } + let(:mutation) { described_class.new(object: nil, context: { current_user: current_user }, field: nil) } + + describe '#resolve' do + subject(:resolve) do + mutation.resolve(**input) + end + + before do + stub_spam_services + end + + context 'when user has sufficient permissions' do + let(:current_user) { developer } + + it 'expires etag cache for parent work item' do + allow(WorkItem).to receive(:find).and_call_original + allow(WorkItem).to receive(:find).with(parent_work_item.id.to_s).and_return(parent_work_item) + + expect(parent_work_item).to receive(:expire_etag_cache) + + resolve + end + end + end +end diff --git a/spec/graphql/mutations/work_items/update_widgets_spec.rb b/spec/graphql/mutations/work_items/update_widgets_spec.rb new file mode 100644 index 00000000000..2e54b81b5c7 --- /dev/null +++ b/spec/graphql/mutations/work_items/update_widgets_spec.rb @@ -0,0 +1,58 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Mutations::WorkItems::UpdateWidgets do + include GraphqlHelpers + + let_it_be(:project) { create(:project) } + let_it_be(:developer) { create(:user).tap { |user| project.add_developer(user) } } + + let(:mutation) { described_class.new(object: nil, context: { current_user: current_user }, field: nil) } + + describe '#resolve' do + before do + stub_spam_services + end + + context 'when no work item matches the given id' do + let(:current_user) { developer } + let(:gid) { global_id_of(id: non_existing_record_id, model_name: WorkItem.name) } + + it 'raises an error' do + expect { mutation.resolve(id: gid, resolve: true) }.to raise_error( + Gitlab::Graphql::Errors::ResourceNotAvailable, + Gitlab::Graphql::Authorize::AuthorizeResource::RESOURCE_ACCESS_ERROR + ) + end + end + + context 'when user can access the requested work item', :aggregate_failures do + let(:current_user) { developer } + let(:args) { {} } + + let_it_be(:work_item) { create(:work_item, project: project) } + + subject { mutation.resolve(id: work_item.to_global_id, **args) } + + context 'when `:work_items` is disabled for a project' do + let_it_be(:project2) { create(:project) } + + it 'returns an error' do + stub_feature_flags(work_items: project2) # only enable `work_item` for project2 + + expect(subject[:errors]).to contain_exactly('`work_items` feature flag disabled for this project') + end + end + + context 'when resolved with an input for description widget' do + let(:args) { { description_widget: { description: "updated description" } } } + + it 'returns the updated work item' do + expect(subject[:work_item].description).to eq("updated description") + expect(subject[:errors]).to be_empty + end + end + end + end +end |