summaryrefslogtreecommitdiff
path: root/spec/requests/api/graphql/mutations/work_items/create_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/requests/api/graphql/mutations/work_items/create_spec.rb')
-rw-r--r--spec/requests/api/graphql/mutations/work_items/create_spec.rb89
1 files changed, 89 insertions, 0 deletions
diff --git a/spec/requests/api/graphql/mutations/work_items/create_spec.rb b/spec/requests/api/graphql/mutations/work_items/create_spec.rb
index 6abdaa2c850..911568bc39f 100644
--- a/spec/requests/api/graphql/mutations/work_items/create_spec.rb
+++ b/spec/requests/api/graphql/mutations/work_items/create_spec.rb
@@ -63,6 +63,95 @@ RSpec.describe 'Create a work item' do
let(:mutation_class) { ::Mutations::WorkItems::Create }
end
+ context 'with hierarchy widget input' do
+ let(:widgets_response) { mutation_response['workItem']['widgets'] }
+ let(:fields) do
+ <<~FIELDS
+ workItem {
+ widgets {
+ type
+ ... on WorkItemWidgetHierarchy {
+ parent {
+ id
+ }
+ children {
+ edges {
+ node {
+ id
+ }
+ }
+ }
+ }
+ }
+ }
+ errors
+ FIELDS
+ end
+
+ let(:mutation) { graphql_mutation(:workItemCreate, input.merge('projectPath' => project.full_path), fields) }
+
+ context 'when setting parent' do
+ let_it_be(:parent) { create(:work_item, project: project) }
+
+ let(:input) do
+ {
+ title: 'item1',
+ workItemTypeId: WorkItems::Type.default_by_type(:task).to_global_id.to_s,
+ hierarchyWidget: { 'parentId' => parent.to_global_id.to_s }
+ }
+ end
+
+ it 'updates the work item parent' do
+ post_graphql_mutation(mutation, current_user: current_user)
+
+ expect(response).to have_gitlab_http_status(:success)
+ expect(widgets_response).to include(
+ {
+ 'children' => { 'edges' => [] },
+ 'parent' => { 'id' => parent.to_global_id.to_s },
+ 'type' => 'HIERARCHY'
+ }
+ )
+ end
+
+ context 'when parent work item type is invalid' do
+ let_it_be(:parent) { create(:work_item, :task, project: project) }
+
+ it 'returns error' do
+ post_graphql_mutation(mutation, current_user: current_user)
+
+ expect(mutation_response['errors'])
+ .to contain_exactly(/cannot be added: only Issue and Incident can be parent of Task./)
+ expect(mutation_response['workItem']).to be_nil
+ end
+ end
+
+ context 'when parent work item is not found' do
+ let_it_be(:parent) { build_stubbed(:work_item, id: non_existing_record_id)}
+
+ it 'returns a top level error' do
+ post_graphql_mutation(mutation, current_user: current_user)
+
+ expect(graphql_errors.first['message']).to include('No object found for `parentId')
+ end
+ end
+ end
+
+ context 'when unsupported widget input is sent' do
+ let(:input) do
+ {
+ 'title' => 'new title',
+ 'description' => 'new description',
+ 'workItemTypeId' => WorkItems::Type.default_by_type(:test_case).to_global_id.to_s,
+ 'hierarchyWidget' => {}
+ }
+ end
+
+ it_behaves_like 'a mutation that returns top-level errors',
+ errors: ['Following widget keys are not supported by Test Case type: [:hierarchy_widget]']
+ end
+ end
+
context 'when the work_items feature flag is disabled' do
before do
stub_feature_flags(work_items: false)