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

create_alert_issue_spec.rb « alerts « alert_management « mutations « graphql « api « requests « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: fbe6d95dfff02fdeb5ad9ed3f91f20122238c258 (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
75
76
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'Create an alert issue from an alert', feature_category: :incident_management do
  include GraphqlHelpers

  let_it_be(:user) { create(:user) }
  let_it_be(:project) { create(:project) }
  let_it_be(:alert) { create(:alert_management_alert, project: project) }

  let(:mutation) do
    variables = {
      project_path: project.full_path,
      iid: alert.iid.to_s
    }
    graphql_mutation(:create_alert_issue, variables,
                     <<~QL
                       clientMutationId
                       errors
                       alert {
                         iid
                         issue {
                           iid
                         }
                       }
                       issue {
                         iid
                         title
                       }
                     QL
    )
  end

  let(:mutation_response) { graphql_mutation_response(:create_alert_issue) }

  before do
    project.add_developer(user)
  end

  context 'when there is no issue associated with the alert' do
    it 'creates an alert issue' do
      post_graphql_mutation(mutation, current_user: user)

      new_issue = Issue.last!

      expect(response).to have_gitlab_http_status(:success)
      expect(mutation_response.slice('alert', 'issue')).to eq(
        'alert' => {
          'iid' => alert.iid.to_s,
          'issue' => { 'iid' => new_issue.iid.to_s }
        },
        'issue' => {
          'iid' => new_issue.iid.to_s,
          'title' => new_issue.title
        }
      )
    end
  end

  context 'when there is an issue already associated with the alert' do
    before do
      AlertManagement::CreateAlertIssueService.new(alert, user).execute
    end

    it 'responds with an error' do
      post_graphql_mutation(mutation, current_user: user)

      expect(response).to have_gitlab_http_status(:success)
      expect(mutation_response.slice('errors', 'issue')).to eq(
        'errors' => ['An issue already exists'],
        'issue' => nil
      )
    end
  end
end