File: task_completion_status_spec.rb

package info (click to toggle)
gitlab 17.6.5-19
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 629,368 kB
  • sloc: ruby: 1,915,304; javascript: 557,307; sql: 60,639; xml: 6,509; sh: 4,567; makefile: 1,239; python: 406
file content (60 lines) | stat: -rw-r--r-- 2,015 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'getting task completion status information', feature_category: :team_planning 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'

  let_it_be(:user1) { create(:user) }
  let_it_be(: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.to_s }, 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(:ok)

      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