summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Derichs <pderichs@gitlab.com>2019-06-15 06:56:28 +0200
committerPatrick Derichs <pderichs@gitlab.com>2019-06-15 06:56:28 +0200
commit453a9b298cd801d560addba722b1e6b4028f8618 (patch)
tree7d25d281f7717eaa51ce910282f22799d3a70971
parentb05de5a583e35931967dcc70d2f26f568c9cf0db (diff)
downloadgitlab-ce-62910-task-completion-status-gql-pderichs.tar.gz
Add task count and completed count to graphql types62910-task-completion-status-gql-pderichs
Add specs for task completion status (graphql) Fix style issues Changed format of constants in spec Refactor specs to reduce creation of records Reduce parameters to merge request creation Use set's for project and user Move let's out of it_behaves_like block Fix description parameter Fix format of lets Use dig to get task completion status out of graphql response Modified rspec output Add changelog entry
-rw-r--r--app/graphql/types/issue_type.rb2
-rw-r--r--app/graphql/types/merge_request_type.rb2
-rw-r--r--app/graphql/types/task_completion_status.rb11
-rw-r--r--changelogs/unreleased/62910-task-completion-status-gql-pderichs.yml5
-rw-r--r--spec/requests/api/graphql/tasks/task_completion_status_spec.rb60
-rw-r--r--spec/support/helpers/graphql_helpers.rb2
6 files changed, 81 insertions, 1 deletions
diff --git a/app/graphql/types/issue_type.rb b/app/graphql/types/issue_type.rb
index dd5133189dc..0e0e98fed32 100644
--- a/app/graphql/types/issue_type.rb
+++ b/app/graphql/types/issue_type.rb
@@ -49,5 +49,7 @@ module Types
field :created_at, Types::TimeType, null: false
field :updated_at, Types::TimeType, null: false
+
+ field :task_completion_status, Types::TaskCompletionStatus, null: false
end
end
diff --git a/app/graphql/types/merge_request_type.rb b/app/graphql/types/merge_request_type.rb
index 85ac3102442..a5428267cac 100644
--- a/app/graphql/types/merge_request_type.rb
+++ b/app/graphql/types/merge_request_type.rb
@@ -53,5 +53,7 @@ module Types
field :head_pipeline, Types::Ci::PipelineType, null: true, method: :actual_head_pipeline
field :pipelines, Types::Ci::PipelineType.connection_type,
resolver: Resolvers::MergeRequestPipelinesResolver
+
+ field :task_completion_status, Types::TaskCompletionStatus, null: false
end
end
diff --git a/app/graphql/types/task_completion_status.rb b/app/graphql/types/task_completion_status.rb
new file mode 100644
index 00000000000..c289802509d
--- /dev/null
+++ b/app/graphql/types/task_completion_status.rb
@@ -0,0 +1,11 @@
+# frozen_string_literal: true
+
+module Types
+ class TaskCompletionStatus < BaseObject
+ graphql_name 'TaskCompletionStatus'
+ description 'Completion status of tasks'
+
+ field :count, GraphQL::INT_TYPE, null: false
+ field :completed_count, GraphQL::INT_TYPE, null: false
+ end
+end
diff --git a/changelogs/unreleased/62910-task-completion-status-gql-pderichs.yml b/changelogs/unreleased/62910-task-completion-status-gql-pderichs.yml
new file mode 100644
index 00000000000..dcbfa7c185d
--- /dev/null
+++ b/changelogs/unreleased/62910-task-completion-status-gql-pderichs.yml
@@ -0,0 +1,5 @@
+---
+title: Make task completion status available via GraphQL
+merge_request:
+author:
+type: added
diff --git a/spec/requests/api/graphql/tasks/task_completion_status_spec.rb b/spec/requests/api/graphql/tasks/task_completion_status_spec.rb
new file mode 100644
index 00000000000..c457a6d7c25
--- /dev/null
+++ b/spec/requests/api/graphql/tasks/task_completion_status_spec.rb
@@ -0,0 +1,60 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe 'getting task completion status information' do
+ include GraphqlHelpers
+
+ DESCRIPTION_0_DONE = '- [ ] task 1\n- [ ] task 2'
+ DESCRIPTION_1_DONE = '- [x] task 1\n- [ ] task 2'
+ DESCRIPTION_2_DONE = '- [x] task 1\n- [x] task 2'
+
+ set(:user1) { create(:user) }
+ set(:project) { create(:project, :repository, :public) }
+
+ let(:fields) do
+ <<~QUERY
+ taskCompletionStatus {
+ count,
+ completedCount
+ }
+ QUERY
+ end
+
+ def create_task_completion_status_query_for(type, iid)
+ graphql_query_for(
+ 'project',
+ { 'fullPath' => project.full_path },
+ query_graphql_field(type, { iid: iid }, fields)
+ )
+ end
+
+ shared_examples_for 'graphql task completion status provider' do |type|
+ it 'returns the expected task completion status' do
+ post_graphql(create_task_completion_status_query_for(type, item.iid), current_user: user1)
+
+ expect(response).to have_gitlab_http_status(200)
+
+ task_completion_status = graphql_data.dig('project', type, 'taskCompletionStatus')
+ expect(task_completion_status).not_to be_nil
+ expect(task_completion_status['count']).to eq(item.task_completion_status[:count])
+ expect(task_completion_status['completedCount']).to eq(item.task_completion_status[:completed_count])
+ end
+ end
+
+ [DESCRIPTION_0_DONE, DESCRIPTION_1_DONE, DESCRIPTION_2_DONE].each do |desc|
+ context "with description #{desc}" do
+ context 'when type is issue' do
+ it_behaves_like 'graphql task completion status provider', 'issue' do
+ let(:item) { create(:issue, project: project, description: desc) }
+ end
+ end
+
+ context 'when type is merge request' do
+ it_behaves_like 'graphql task completion status provider', 'mergeRequest' do
+ let(:item) { create(:merge_request, author: user1, source_project: project, description: desc) }
+ end
+ end
+ end
+ end
+end
diff --git a/spec/support/helpers/graphql_helpers.rb b/spec/support/helpers/graphql_helpers.rb
index e95c7f2a6d6..bcf6669f37d 100644
--- a/spec/support/helpers/graphql_helpers.rb
+++ b/spec/support/helpers/graphql_helpers.rb
@@ -157,7 +157,7 @@ module GraphqlHelpers
when Array # multiplexed queries
json_response.map { |response| response['errors'] }
else
- raise "Unkown GraphQL response type #{json_response.class}"
+ raise "Unknown GraphQL response type #{json_response.class}"
end
end