Welcome to mirror list, hosted at ThFree Co, Russian Federation.

user_counts_spec.rb « api « requests « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 27ebf02dd811281d2d7c0e7deb29c83a11808aae (plain)
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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe API::UserCounts do
  let_it_be(:user) { create(:user) }
  let_it_be(:project) { create(:project, :public) }
  let_it_be(:issue) { create(:issue, project: project, author: user, assignees: [user]) }
  let_it_be(:todo) { create(:todo, :pending, user: user, project: project) }

  let!(:merge_request) { create(:merge_request, :simple, author: user, assignees: [user], source_project: project, title: "Test") }

  describe 'GET /user_counts' do
    context 'when unauthenticated' do
      it 'returns authentication error' do
        get api('/user_counts')

        expect(response).to have_gitlab_http_status(:unauthorized)
      end
    end

    context 'when authenticated' do
      it 'returns assigned issue counts for current_user' do
        get api('/user_counts', user)

        expect(json_response['assigned_issues']).to eq(1)
      end

      context 'merge requests' do
        it 'returns assigned MR counts for current user' do
          get api('/user_counts', user)

          expect(response).to have_gitlab_http_status(:ok)
          expect(json_response).to be_a Hash
          expect(json_response['merge_requests']).to eq(1)
        end

        it 'updates the mr count when a new mr is assigned' do
          create(:merge_request, source_project: project, author: user, assignees: [user])

          get api('/user_counts', user)

          expect(response).to have_gitlab_http_status(:ok)
          expect(json_response).to be_a Hash
          expect(json_response['merge_requests']).to eq(2)
          expect(json_response['attention_requests']).to eq(2)
        end

        describe 'mr_attention_requests is disabled' do
          before do
            stub_feature_flags(mr_attention_requests: false)
          end

          it 'does not include attention_requests count' do
            create(:merge_request, source_project: project, author: user, assignees: [user])

            get api('/user_counts', user)

            expect(json_response.key?('attention_requests')).to be(false)
          end
        end
      end

      it 'returns pending todo counts for current_user' do
        get api('/user_counts', user)

        expect(json_response['todos']).to eq(1)
      end
    end
  end
end