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

require 'spec_helper'

RSpec.describe Mutations::IncidentManagement::TimelineEvent::Create do
  let_it_be(:current_user) { create(:user) }
  let_it_be(:project) { create(:project) }
  let_it_be(:incident) { create(:incident, project: project) }

  let(:args) { { note: 'note', occurred_at: Time.current } }

  specify { expect(described_class).to require_graphql_authorizations(:admin_incident_management_timeline_event) }

  describe '#resolve' do
    subject(:resolve) { mutation_for(project, current_user).resolve(incident_id: incident.to_global_id, **args) }

    context 'when a user has permissions to create a timeline event' do
      let(:expected_timeline_event) do
        instance_double(
          'IncidentManagement::TimelineEvent',
          note: args[:note],
          occurred_at: args[:occurred_at].to_s,
          incident: incident,
          author: current_user,
          promoted_from_note: nil,
          editable: true
        )
      end

      before do
        project.add_developer(current_user)
      end

      it_behaves_like 'creating an incident timeline event'

      context 'when TimelineEvents::CreateService responds with an error' do
        let(:args) { {} }

        it_behaves_like 'responding with an incident timeline errors',
          errors: ["Occurred at can't be blank, Note can't be blank, and Note html can't be blank"]
      end
    end

    it_behaves_like 'failing to create an incident timeline event'
  end

  private

  def mutation_for(project, user)
    described_class.new(object: project, context: { current_user: user }, field: nil)
  end
end