summaryrefslogtreecommitdiff
path: root/spec/serializers/issue_sidebar_basic_entity_spec.rb
blob: da07290f34924a1ad5f19fb1ffe4347a576915b7 (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
72
73
74
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe IssueSidebarBasicEntity do
  let_it_be(:project) { create(:project, :repository) }
  let_it_be(:user) { create(:user, developer_projects: [project]) }
  let_it_be(:issue) { create(:issue, project: project, assignees: [user]) }

  let(:serializer) { IssueSerializer.new(current_user: user, project: project) }

  subject(:entity) { serializer.represent(issue, serializer: 'sidebar') }

  it 'contains keys related to issuables' do
    expect(entity).to include(
      :id, :iid, :type, :author_id, :project_id, :discussion_locked, :reference, :milestone,
      :labels, :current_user, :issuable_json_path, :namespace_path, :project_path,
      :project_full_path, :project_issuables_path, :create_todo_path, :project_milestones_path,
      :project_labels_path, :toggle_subscription_path, :move_issue_path, :projects_autocomplete_path,
      :project_emails_disabled, :create_note_email, :supports_time_tracking, :supports_milestone,
      :supports_severity, :supports_escalation
    )
  end

  it 'contains attributes related to the issue' do
    expect(entity).to include(:due_date, :confidential, :severity)
  end

  describe 'current_user' do
    it 'contains attributes related to the current user' do
      expect(entity[:current_user]).to include(
        :id, :name, :username, :state, :avatar_url, :web_url, :todo,
        :can_edit, :can_move, :can_admin_label
      )
    end

    describe 'can_update_escalation_status' do
      context 'for a standard issue' do
        it 'is not present' do
          expect(entity[:current_user]).not_to have_key(:can_update_escalation_status)
        end
      end

      context 'for an incident issue' do
        before do
          issue.update!(issue_type: Issue.issue_types[:incident])
        end

        it 'is present and true' do
          expect(entity[:current_user][:can_update_escalation_status]).to be(true)
        end

        context 'without permissions' do
          let(:serializer) { IssueSerializer.new(current_user: create(:user), project: project) }

          it 'is present and false' do
            expect(entity[:current_user]).to have_key(:can_update_escalation_status)
            expect(entity[:current_user][:can_update_escalation_status]).to be(false)
          end
        end

        context 'with :incident_escalations feature flag disabled' do
          before do
            stub_feature_flags(incident_escalations: false)
          end

          it 'is not present' do
            expect(entity[:current_user]).not_to include(:can_update_escalation_status)
          end
        end
      end
    end
  end
end