File: sidebar_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 (83 lines) | stat: -rw-r--r-- 2,207 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'Namespace.sidebar', feature_category: :navigation do
  include GraphqlHelpers

  let_it_be(:group) { create(:group, :private) }
  let_it_be(:project) { create(:project, :repository, namespace: group) }

  let_it_be(:reporter) { create(:user, reporter_of: group) }

  let(:query) do
    <<~QUERY
    query {
      namespace(fullPath: "#{namespace.full_path}") {
        sidebar {
          openIssuesCount
          openMergeRequestsCount
        }
      }
    }
    QUERY
  end

  before_all do
    create_list(:issue, 2, project: project)
    create(:merge_request, source_project: project)
  end

  context 'with a Group' do
    let(:namespace) { group }

    it 'returns the group counts' do
      post_graphql(query, current_user: reporter)

      expect(response).to have_gitlab_http_status(:ok)

      expect(graphql_data_at(:namespace, :sidebar)).to eq({
        'openIssuesCount' => 2,
        'openMergeRequestsCount' => 1
      })
    end

    context 'when issue count query times out' do
      before do
        allow_next_instance_of(::Groups::OpenIssuesCountService) do |service|
          allow(service).to receive(:count).and_raise(ActiveRecord::QueryCanceled)
        end
      end

      it 'logs the error and returns a null issue count' do
        expect(Gitlab::ErrorTracking).to receive(:log_exception).with(
          ActiveRecord::QueryCanceled, group_id: namespace.id, query: 'group_sidebar_issues_count'
        ).and_call_original

        post_graphql(query, current_user: reporter)

        expect(response).to have_gitlab_http_status(:ok)

        expect(graphql_data_at(:namespace, :sidebar)).to eq({
          'openIssuesCount' => nil,
          'openMergeRequestsCount' => 1
        })
      end
    end
  end

  context 'with a ProjectNamespace' do
    let(:namespace) { project.project_namespace }

    it 'returns the project counts' do
      post_graphql(query, current_user: reporter)

      expect(response).to have_gitlab_http_status(:ok)

      expect(graphql_data_at(:namespace, :sidebar)).to eq({
        'openIssuesCount' => 2,
        'openMergeRequestsCount' => 1
      })
    end
  end
end