diff options
author | Sean McGivern <sean@gitlab.com> | 2019-06-07 10:24:17 +0000 |
---|---|---|
committer | Sean McGivern <sean@gitlab.com> | 2019-06-07 10:24:17 +0000 |
commit | 3ef0c54966ec79de0a713e089b62b46c79e8a663 (patch) | |
tree | 4b3dc4893d8620991576a33d747ba23675c47aee /spec/requests | |
parent | 2fc7c09cb7675db6d8319cce6f1aab857b37222f (diff) | |
parent | b70d23c25a4bc54fda22135b0a76bae102cfd88b (diff) | |
download | gitlab-ce-3ef0c54966ec79de0a713e089b62b46c79e8a663.tar.gz |
Merge branch '51636-task-list-api-pderichs' into 'master'
Add task count and completed count to responses of Issue and MR
See merge request gitlab-org/gitlab-ce!28859
Diffstat (limited to 'spec/requests')
-rw-r--r-- | spec/requests/api/task_completion_status_spec.rb | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/spec/requests/api/task_completion_status_spec.rb b/spec/requests/api/task_completion_status_spec.rb new file mode 100644 index 00000000000..ee2531197b1 --- /dev/null +++ b/spec/requests/api/task_completion_status_spec.rb @@ -0,0 +1,85 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe 'task completion status response' do + set(:user) { create(:user) } + set(:project) do + create(:project, :public, creator_id: user.id, namespace: user.namespace) + end + + shared_examples 'taskable completion status provider' do |path| + samples = [ + { + description: '', + expected_count: 0, + expected_completed_count: 0 + }, + { + description: 'Lorem ipsum', + expected_count: 0, + expected_completed_count: 0 + }, + { + description: %{- [ ] task 1 + - [x] task 2 }, + expected_count: 2, + expected_completed_count: 1 + }, + { + description: %{- [ ] task 1 + - [ ] task 2 }, + expected_count: 2, + expected_completed_count: 0 + }, + { + description: %{- [x] task 1 + - [x] task 2 }, + expected_count: 2, + expected_completed_count: 2 + }, + { + description: %{- [ ] task 1}, + expected_count: 1, + expected_completed_count: 0 + }, + { + description: %{- [x] task 1}, + expected_count: 1, + expected_completed_count: 1 + } + ] + samples.each do |sample_data| + context "with a description of #{sample_data[:description].inspect}" do + before do + taskable.update!(description: sample_data[:description]) + + get api("#{path}?iids[]=#{taskable.iid}", user) + end + + it { expect(response).to have_gitlab_http_status(200) } + + it 'returns the expected results' do + expect(json_response).to be_an Array + expect(json_response).not_to be_empty + + task_completion_status = json_response.first['task_completion_status'] + expect(task_completion_status['count']).to eq(sample_data[:expected_count]) + expect(task_completion_status['completed_count']).to eq(sample_data[:expected_completed_count]) + end + end + end + end + + context 'task list completion status for issues' do + it_behaves_like 'taskable completion status provider', '/issues' do + let(:taskable) { create(:issue, project: project, author: user) } + end + end + + context 'task list completion status for merge_requests' do + it_behaves_like 'taskable completion status provider', '/merge_requests' do + let(:taskable) { create(:merge_request, source_project: project, target_project: project, author: user) } + end + end +end |