diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-05-19 10:33:21 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-05-19 10:33:21 +0300 |
commit | 36a59d088eca61b834191dacea009677a96c052f (patch) | |
tree | e4f33972dab5d8ef79e3944a9f403035fceea43f /spec/support/shared_examples/graphql/mutations/incident_management_timeline_events_shared_examples.rb | |
parent | a1761f15ec2cae7c7f7bbda39a75494add0dfd6f (diff) |
Add latest changes from gitlab-org/gitlab@15-0-stable-eev15.0.0-rc42
Diffstat (limited to 'spec/support/shared_examples/graphql/mutations/incident_management_timeline_events_shared_examples.rb')
-rw-r--r-- | spec/support/shared_examples/graphql/mutations/incident_management_timeline_events_shared_examples.rb | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/spec/support/shared_examples/graphql/mutations/incident_management_timeline_events_shared_examples.rb b/spec/support/shared_examples/graphql/mutations/incident_management_timeline_events_shared_examples.rb new file mode 100644 index 00000000000..b989dbc6524 --- /dev/null +++ b/spec/support/shared_examples/graphql/mutations/incident_management_timeline_events_shared_examples.rb @@ -0,0 +1,48 @@ +# frozen_string_literal: true + +require 'spec_helper' + +# Requres: +# * subject with a 'resolve' name +# * Defined expected timeline event via `let(:expected_timeline_event) { instance_double(...) }` +RSpec.shared_examples 'creating an incident timeline event' do + it 'creates a timeline event' do + expect { resolve }.to change(IncidentManagement::TimelineEvent, :count).by(1) + end + + it 'responds with a timeline event', :aggregate_failures do + response = resolve + timeline_event = IncidentManagement::TimelineEvent.last! + + expect(response).to match(timeline_event: timeline_event, errors: be_empty) + + expect(timeline_event.promoted_from_note).to eq(expected_timeline_event.promoted_from_note) + expect(timeline_event.note).to eq(expected_timeline_event.note) + expect(timeline_event.occurred_at.to_s).to eq(expected_timeline_event.occurred_at) + expect(timeline_event.incident).to eq(expected_timeline_event.incident) + expect(timeline_event.author).to eq(expected_timeline_event.author) + end +end + +# Requres +# * subject with a 'resolve' name +# * a user factory with a 'current_user' name +RSpec.shared_examples 'failing to create an incident timeline event' do + context 'when a user has no permissions to create timeline event' do + before do + project.add_guest(current_user) + end + + it 'raises an error' do + expect { resolve }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable) + end + end +end + +# Requres: +# * subject with a 'resolve' name +RSpec.shared_examples 'responding with an incident timeline errors' do |errors:| + it 'returns errors' do + expect(resolve).to eq(timeline_event: nil, errors: errors) + end +end |