File: set_severity_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 (88 lines) | stat: -rw-r--r-- 2,559 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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Mutations::Issues::SetSeverity, feature_category: :api do
  include GraphqlHelpers

  let_it_be(:project) { create(:project) }
  let_it_be(:guest) { create(:user, guest_of: project) }
  let_it_be(:reporter) { create(:user, reporter_of: project) }
  let_it_be(:issue) { create(:incident, project: project) }

  let(:mutation) { described_class.new(object: nil, context: query_context, field: nil) }

  specify { expect(described_class).to require_graphql_authorizations(:update_issue, :admin_issue) }

  describe '#resolve' do
    let(:severity) { 'critical' }

    subject(:resolve) do
      mutation.resolve(
        project_path: issue.project.full_path,
        iid: issue.iid,
        severity: severity
      )
    end

    context 'as guest' do
      let(:current_user) { guest }

      it 'raises an error' do
        expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
      end

      context 'and also author' do
        let!(:issue) { create(:incident, project: project, author: current_user) }

        it 'raises an error' do
          expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
        end
      end

      context 'and also assignee' do
        let!(:issue) { create(:incident, project: project, assignee_ids: [current_user.id]) }

        it 'raises an error' do
          expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
        end
      end
    end

    context 'as reporter' do
      let(:current_user) { reporter }

      context 'when issue type is incident' do
        context 'when severity has a correct value' do
          it 'updates severity' do
            expect(resolve[:issue].severity).to eq('critical')
          end

          it 'returns no errors' do
            expect(resolve[:errors]).to be_empty
          end
        end

        context 'when severity has an unsuported value' do
          let(:severity) { 'unsupported-severity' }

          it 'sets severity to default' do
            expect(resolve[:issue].severity).to eq(IssuableSeverity::DEFAULT)
          end

          it 'returns no errorsr' do
            expect(resolve[:errors]).to be_empty
          end
        end
      end

      context 'when issue type is not incident' do
        let!(:issue) { create(:issue, project: project) }

        it 'does not update the issue' do
          expect { resolve }.not_to change { issue.updated_at }
        end
      end
    end
  end
end