diff options
Diffstat (limited to 'spec/requests/api/graphql/mutations/incident_management')
4 files changed, 269 insertions, 0 deletions
diff --git a/spec/requests/api/graphql/mutations/incident_management/timeline_event/create_spec.rb b/spec/requests/api/graphql/mutations/incident_management/timeline_event/create_spec.rb new file mode 100644 index 00000000000..3ea8b38e20f --- /dev/null +++ b/spec/requests/api/graphql/mutations/incident_management/timeline_event/create_spec.rb @@ -0,0 +1,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 diff --git a/spec/requests/api/graphql/mutations/incident_management/timeline_event/destroy_spec.rb b/spec/requests/api/graphql/mutations/incident_management/timeline_event/destroy_spec.rb new file mode 100644 index 00000000000..faff3bfe23a --- /dev/null +++ b/spec/requests/api/graphql/mutations/incident_management/timeline_event/destroy_spec.rb @@ -0,0 +1,67 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'Removing 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(:timeline_event) { create(:incident_management_timeline_event, incident: incident, project: project) } + + let(:variables) { { id: timeline_event.to_global_id.to_s } } + + let(:mutation) do + graphql_mutation(:timeline_event_destroy, variables) do + <<~QL + clientMutationId + errors + timelineEvent { + id + author { id username } + incident { id title } + note + noteHtml + editable + action + occurredAt + createdAt + updatedAt + } + QL + end + end + + let(:mutation_response) { graphql_mutation_response(:timeline_event_destroy) } + + before do + project.add_developer(user) + end + + it 'removes 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' => timeline_event.author.to_global_id.to_s, + 'username' => timeline_event.author.username + }, + 'incident' => { + 'id' => incident.to_global_id.to_s, + 'title' => incident.title + }, + 'note' => timeline_event.note, + 'noteHtml' => timeline_event.note_html, + 'editable' => false, + 'action' => timeline_event.action, + 'occurredAt' => timeline_event.occurred_at.iso8601, + 'createdAt' => timeline_event.created_at.iso8601, + 'updatedAt' => timeline_event.updated_at.iso8601 + ) + expect { timeline_event.reload }.to raise_error ActiveRecord::RecordNotFound + end +end diff --git a/spec/requests/api/graphql/mutations/incident_management/timeline_event/promote_from_note_spec.rb b/spec/requests/api/graphql/mutations/incident_management/timeline_event/promote_from_note_spec.rb new file mode 100644 index 00000000000..b92f6af1d3d --- /dev/null +++ b/spec/requests/api/graphql/mutations/incident_management/timeline_event/promote_from_note_spec.rb @@ -0,0 +1,62 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'Promote an incident timeline event from a comment' 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(:comment) { create(:note, project: project, noteable: incident) } + + let(:input) { { note_id: comment.to_global_id.to_s } } + let(:mutation) do + graphql_mutation(:timeline_event_promote_from_note, input) do + <<~QL + clientMutationId + errors + timelineEvent { + author { id username } + incident { id title } + promotedFromNote { id } + note + action + editable + occurredAt + } + QL + end + end + + let(:mutation_response) { graphql_mutation_response(:timeline_event_promote_from_note) } + + before do + project.add_developer(user) + end + + it 'creates incident timeline event from the note', :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 + }, + 'promotedFromNote' => { + 'id' => comment.to_global_id.to_s + }, + 'note' => comment.note, + 'action' => 'comment', + 'editable' => false, + 'occurredAt' => comment.created_at.iso8601 + ) + end +end diff --git a/spec/requests/api/graphql/mutations/incident_management/timeline_event/update_spec.rb b/spec/requests/api/graphql/mutations/incident_management/timeline_event/update_spec.rb new file mode 100644 index 00000000000..1c4439cec6f --- /dev/null +++ b/spec/requests/api/graphql/mutations/incident_management/timeline_event/update_spec.rb @@ -0,0 +1,80 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'Updating 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_with_reload(:timeline_event) do + create(:incident_management_timeline_event, incident: incident, project: project) + end + + let(:occurred_at) { 1.minute.ago.iso8601 } + + let(:variables) do + { + id: timeline_event.to_global_id.to_s, + note: 'Updated note', + occurred_at: occurred_at + } + end + + let(:mutation) do + graphql_mutation(:timeline_event_update, variables) do + <<~QL + clientMutationId + errors + timelineEvent { + id + author { id username } + updatedByUser { id username } + incident { id title } + note + noteHtml + occurredAt + createdAt + updatedAt + } + QL + end + end + + let(:mutation_response) { graphql_mutation_response(:timeline_event_update) } + + before do + project.add_developer(user) + end + + it 'updates the timeline event', :aggregate_failures do + post_graphql_mutation(mutation, current_user: user) + + timeline_event_response = mutation_response['timelineEvent'] + + timeline_event.reload + + expect(response).to have_gitlab_http_status(:success) + expect(timeline_event_response).to include( + 'id' => timeline_event.to_global_id.to_s, + 'author' => { + 'id' => timeline_event.author.to_global_id.to_s, + 'username' => timeline_event.author.username + }, + 'updatedByUser' => { + 'id' => user.to_global_id.to_s, + 'username' => user.username + }, + 'incident' => { + 'id' => incident.to_global_id.to_s, + 'title' => incident.title + }, + 'note' => 'Updated note', + 'noteHtml' => timeline_event.note_html, + 'occurredAt' => occurred_at, + 'createdAt' => timeline_event.created_at.iso8601, + 'updatedAt' => timeline_event.updated_at.iso8601 + ) + end +end |