gitlab-org--gitlab-foss/spec/requests/api/task_completion_status_spec.rb
Patrick Derichs b70d23c25a Add task count and completed count to responses of Issue and MR
Add spec for task_completion_status

Add test cases for task_completion_status result

Extracted shared samples

Add new spec file for task completion status response

Fix style errors

Add changelog entry

Changed samples to Hashes

Remove test for successful request

Remove not nil expectation

Add task_completion_status to api documentation for issues

Add task_completion_status to api documentation for merge_requests

Refactor spec so it just requests one specific item

Add task_completion_status to Taskable

Simplified task completion status in entities

Refactor spec so it separates status code check and content check

Fix spec description text and field name
2019-06-07 11:15:55 +02:00

85 lines
2.5 KiB
Ruby

# 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