summaryrefslogtreecommitdiff
path: root/spec/requests/api/graphql/mutations/incident_management/timeline_event/create_spec.rb
blob: 3ea8b38e20fd198fe391a011ef3fd4a087df661a (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'Creating an incident timeline event' do
  include GraphqlHelpers

  let_it_be(:user) { create(:user) }
  let_it_be(:project) { create(:project) }
  let_it_be(:incident) { create(:incident, project: project) }
  let_it_be(:event_occurred_at) { Time.current }
  let_it_be(:note) { 'demo note' }

  let(:input) { { incident_id: incident.to_global_id.to_s, note: note, occurred_at: event_occurred_at } }
  let(:mutation) do
    graphql_mutation(:timeline_event_create, input) do
      <<~QL
        clientMutationId
        errors
        timelineEvent {
          id
          author { id username }
          incident { id title }
          note
          editable
          action
          occurredAt
        }
      QL
    end
  end

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

  before do
    project.add_developer(user)
  end

  it 'creates incident timeline event', :aggregate_failures do
    post_graphql_mutation(mutation, current_user: user)

    timeline_event_response = mutation_response['timelineEvent']

    expect(response).to have_gitlab_http_status(:success)
    expect(timeline_event_response).to include(
      'author' => {
        'id' => user.to_global_id.to_s,
        'username' => user.username
      },
      'incident' => {
        'id' => incident.to_global_id.to_s,
        'title' => incident.title
      },
      'note' => note,
      'action' => 'comment',
      'editable' => false,
      'occurredAt' => event_occurred_at.iso8601
    )
  end
end