File: work_items_controller_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 (129 lines) | stat: -rw-r--r-- 3,587 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'Group Level Work Items', feature_category: :team_planning do
  let_it_be(:group) { create(:group, :private) }
  let_it_be(:developer) { create(:user, developer_of: group) }

  describe 'GET /groups/:group/-/work_items' do
    let(:work_items_path) { url_for(controller: 'groups/work_items', action: :index, group_id: group.full_path) }

    before do
      sign_in(current_user)
    end

    context 'when the user can read the group' do
      let(:current_user) { developer }

      it 'renders index' do
        get work_items_path

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

      context 'when the namespace_level_work_items feature flag is disabled' do
        before do
          stub_feature_flags(namespace_level_work_items: false)
        end

        it 'returns not found' do
          get work_items_path

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

    context 'when the user cannot read the group' do
      let(:current_user) { create(:user) }

      it 'returns not found' do
        get work_items_path

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

  describe 'GET /groups/:group/-/work_items/:iid' do
    let_it_be(:work_item) { create(:work_item, :group_level, namespace: group) }
    let(:iid) { work_item.iid }
    let(:work_items_path) do
      url_for(controller: 'groups/work_items', action: :show, group_id: group.full_path, iid: iid)
    end

    before do
      sign_in(current_user)
    end

    context 'when the user can read the group' do
      let(:current_user) { developer }

      it 'renders show' do
        get work_items_path

        expect(response).to have_gitlab_http_status(:ok)
        expect(response).to render_template(:show)
      end

      context 'when the new page gets requested' do
        let(:iid) { 'new' }

        it 'renders show' do
          get work_items_path

          expect(response).to have_gitlab_http_status(:ok)
          expect(response).to render_template(:show)
          expect(response.body).to have_pushed_frontend_feature_flags(namespaceLevelWorkItems: true)
        end
      end

      it 'has correct metadata' do
        get work_items_path

        expect(response.body).to include("#{work_item.title} (#{work_item.to_reference})")
        expect(response.body).to include(work_item.work_item_type.name.pluralize)
      end

      context 'when the namespace_level_work_items feature flag is disabled' do
        before do
          stub_feature_flags(namespace_level_work_items: false)
        end

        it 'returns not found' do
          get work_items_path

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

        context 'on new page' do
          let(:iid) { 'new' }

          it 'returns not found' do
            get work_items_path

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

    context 'when the user cannot read the group' do
      let(:current_user) { create(:user) }

      it 'returns not found' do
        get work_items_path

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

      it 'does not include sensitive metadata' do
        get work_items_path

        expect(response.body).not_to include("#{work_item.title} (#{work_item.to_reference})")
        expect(response.body).not_to include(work_item.work_item_type.name.pluralize)
      end
    end
  end
end