diff options
Diffstat (limited to 'spec/graphql/mutations')
11 files changed, 258 insertions, 21 deletions
diff --git a/spec/graphql/mutations/alert_management/alerts/set_assignees_spec.rb b/spec/graphql/mutations/alert_management/alerts/set_assignees_spec.rb index 31abbabe385..125e15b70cf 100644 --- a/spec/graphql/mutations/alert_management/alerts/set_assignees_spec.rb +++ b/spec/graphql/mutations/alert_management/alerts/set_assignees_spec.rb @@ -56,6 +56,15 @@ RSpec.describe Mutations::AlertManagement::Alerts::SetAssignees do context 'when operation mode is not specified' do it_behaves_like 'successful resolution' it_behaves_like 'an incident management tracked event', :incident_management_alert_assigned + + it_behaves_like 'Snowplow event tracking with RedisHLL context' do + let(:feature_flag_name) { :route_hll_to_snowplow_phase2 } + let(:namespace) { project.namespace.reload } + let(:category) { described_class.to_s } + let(:user) { current_user } + let(:action) { 'incident_management_alert_assigned' } + let(:label) { 'redis_hll_counters.incident_management.incident_management_total_unique_counts_monthly' } + end end context 'when user does not have permission to update alerts' do diff --git a/spec/graphql/mutations/alert_management/alerts/todo/create_spec.rb b/spec/graphql/mutations/alert_management/alerts/todo/create_spec.rb index ea5e21ec4b8..bcb7c74fa09 100644 --- a/spec/graphql/mutations/alert_management/alerts/todo/create_spec.rb +++ b/spec/graphql/mutations/alert_management/alerts/todo/create_spec.rb @@ -19,6 +19,15 @@ RSpec.describe Mutations::AlertManagement::Alerts::Todo::Create do it_behaves_like 'an incident management tracked event', :incident_management_alert_todo + it_behaves_like 'Snowplow event tracking with RedisHLL context' do + let(:feature_flag_name) { :route_hll_to_snowplow_phase2 } + let(:namespace) { project.namespace.reload } + let(:category) { described_class.to_s } + let(:user) { current_user } + let(:action) { 'incident_management_alert_todo' } + let(:label) { 'redis_hll_counters.incident_management.incident_management_total_unique_counts_monthly' } + end + context 'when user does not have permissions' do let(:current_user) { nil } diff --git a/spec/graphql/mutations/alert_management/create_alert_issue_spec.rb b/spec/graphql/mutations/alert_management/create_alert_issue_spec.rb index 4758ac526a5..e49596b37c9 100644 --- a/spec/graphql/mutations/alert_management/create_alert_issue_spec.rb +++ b/spec/graphql/mutations/alert_management/create_alert_issue_spec.rb @@ -30,6 +30,15 @@ RSpec.describe Mutations::AlertManagement::CreateAlertIssue do it_behaves_like 'an incident management tracked event', :incident_management_incident_created it_behaves_like 'an incident management tracked event', :incident_management_alert_create_incident + + it_behaves_like 'Snowplow event tracking with RedisHLL context' do + let(:feature_flag_name) { :route_hll_to_snowplow_phase2 } + let(:namespace) { project.namespace.reload } + let(:category) { described_class.to_s } + let(:user) { current_user } + let(:action) { 'incident_management_incident_created' } + let(:label) { 'redis_hll_counters.incident_management.incident_management_total_unique_counts_monthly' } + end end context 'when CreateAlertIssue responds with an error' do @@ -46,6 +55,15 @@ RSpec.describe Mutations::AlertManagement::CreateAlertIssue do errors: ['An issue already exists'] ) end + + it_behaves_like 'Snowplow event tracking with RedisHLL context' do + let(:feature_flag_name) { :route_hll_to_snowplow_phase2 } + let(:namespace) { project.namespace.reload } + let(:category) { described_class.to_s } + let(:user) { current_user } + let(:action) { 'incident_management_incident_created' } + let(:label) { 'redis_hll_counters.incident_management.incident_management_total_unique_counts_monthly' } + end end end diff --git a/spec/graphql/mutations/alert_management/update_alert_status_spec.rb b/spec/graphql/mutations/alert_management/update_alert_status_spec.rb index 2c2518e046a..22ad93df79b 100644 --- a/spec/graphql/mutations/alert_management/update_alert_status_spec.rb +++ b/spec/graphql/mutations/alert_management/update_alert_status_spec.rb @@ -35,6 +35,15 @@ RSpec.describe Mutations::AlertManagement::UpdateAlertStatus do let(:user) { current_user } end + it_behaves_like 'Snowplow event tracking with RedisHLL context' do + let(:feature_flag_name) { :route_hll_to_snowplow_phase2 } + let(:namespace) { project.namespace } + let(:category) { described_class.to_s } + let(:user) { current_user } + let(:action) { 'incident_management_alert_status_changed' } + let(:label) { 'redis_hll_counters.incident_management.incident_management_total_unique_counts_monthly' } + end + context 'error occurs when updating' do it 'returns the alert with errors' do # Stub an error on the alert diff --git a/spec/graphql/mutations/ci/runner/bulk_delete_spec.rb b/spec/graphql/mutations/ci/runner/bulk_delete_spec.rb index 2eccfd3409f..aaa74fa78aa 100644 --- a/spec/graphql/mutations/ci/runner/bulk_delete_spec.rb +++ b/spec/graphql/mutations/ci/runner/bulk_delete_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Mutations::Ci::Runner::BulkDelete do +RSpec.describe Mutations::Ci::Runner::BulkDelete, feature_category: :runner_fleet do include GraphqlHelpers let_it_be(:admin_user) { create(:user, :admin) } diff --git a/spec/graphql/mutations/ci/runner/delete_spec.rb b/spec/graphql/mutations/ci/runner/delete_spec.rb index 06d360430f8..f19fa7c34a9 100644 --- a/spec/graphql/mutations/ci/runner/delete_spec.rb +++ b/spec/graphql/mutations/ci/runner/delete_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Mutations::Ci::Runner::Delete do +RSpec.describe Mutations::Ci::Runner::Delete, feature_category: :runner_fleet do include GraphqlHelpers let_it_be(:runner) { create(:ci_runner) } diff --git a/spec/graphql/mutations/ci/runner/update_spec.rb b/spec/graphql/mutations/ci/runner/update_spec.rb index 098b7ac6aa4..e0c8219e0f6 100644 --- a/spec/graphql/mutations/ci/runner/update_spec.rb +++ b/spec/graphql/mutations/ci/runner/update_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Mutations::Ci::Runner::Update do +RSpec.describe Mutations::Ci::Runner::Update, feature_category: :runner_fleet do include GraphqlHelpers let_it_be(:user) { create(:user) } diff --git a/spec/graphql/mutations/container_repositories/destroy_spec.rb b/spec/graphql/mutations/container_repositories/destroy_spec.rb index 9f3ff8da80b..50e83ccdd30 100644 --- a/spec/graphql/mutations/container_repositories/destroy_spec.rb +++ b/spec/graphql/mutations/container_repositories/destroy_spec.rb @@ -55,23 +55,6 @@ RSpec.describe Mutations::ContainerRepositories::Destroy do it_behaves_like params[:shared_examples_name] end - - context 'with container_registry_delete_repository_with_cron_worker disabled' do - before do - project.add_maintainer(user) - stub_feature_flags(container_registry_delete_repository_with_cron_worker: false) - end - - it 'enqueues a removal job' do - expect(::Packages::CreateEventService) - .to receive(:new).with(nil, user, event_name: :delete_repository, scope: :container).and_call_original - expect(DeleteContainerRepositoryWorker) - .to receive(:perform_async).with(user.id, container_repository.id) - - expect { subject }.to change { ::Packages::Event.count }.by(1) - expect(container_repository.reload.delete_scheduled?).to be true - end - end end end end diff --git a/spec/graphql/mutations/incident_management/timeline_event/update_spec.rb b/spec/graphql/mutations/incident_management/timeline_event/update_spec.rb index 7081fb7117e..317e8f5fcb6 100644 --- a/spec/graphql/mutations/incident_management/timeline_event/update_spec.rb +++ b/spec/graphql/mutations/incident_management/timeline_event/update_spec.rb @@ -7,21 +7,33 @@ RSpec.describe Mutations::IncidentManagement::TimelineEvent::Update do let_it_be(:reporter) { create(:user) } let_it_be(:project) { create(:project) } let_it_be(:incident) { create(:incident, project: project) } + let_it_be(:tag1) { create(:incident_management_timeline_event_tag, project: project, name: 'Tag 1') } + let_it_be(:tag2) { create(:incident_management_timeline_event_tag, project: project, name: 'Tag 2') } let_it_be_with_reload(:timeline_event) do create(:incident_management_timeline_event, project: project, incident: incident) end + # Pre-attach a tag to the event + let_it_be(:tag_link1) do + create(:incident_management_timeline_event_tag_link, + timeline_event: timeline_event, + timeline_event_tag: tag1 + ) + end + let(:args) do { id: timeline_event_id, note: note, - occurred_at: occurred_at + occurred_at: occurred_at, + timeline_event_tag_names: tag_names } end let(:note) { 'Updated Note' } let(:timeline_event_id) { GitlabSchema.id_from_object(timeline_event).to_s } let(:occurred_at) { 1.minute.ago } + let(:tag_names) { [] } before do project.add_developer(developer) @@ -92,6 +104,36 @@ RSpec.describe Mutations::IncidentManagement::TimelineEvent::Update do expect(resolve).to eq(timeline_event: nil, errors: ["Occurred at can't be blank"]) end end + + context 'when timeline event tag do not exist' do + let(:tag_names) { ['some other tag'] } + + it 'does not update the timeline event' do + expect { resolve }.not_to change { timeline_event.reload.updated_at } + end + + it 'responds with error' do + expect(resolve).to eq(timeline_event: nil, errors: ["Following tags don't exist: [\"some other tag\"]"]) + end + end + end + + context 'when timeline event tags are passed' do + let(:tag_names) { [tag2.name] } + + it 'returns updated timeline event' do + expect(resolve).to eq( + timeline_event: timeline_event.reload, + errors: [] + ) + end + + it 'removes tag1 and assigns tag2 to the event' do + response = resolve + timeline_event = response[:timeline_event] + + expect(timeline_event.timeline_event_tags).to contain_exactly(tag2) + end end end diff --git a/spec/graphql/mutations/issues/link_alerts_spec.rb b/spec/graphql/mutations/issues/link_alerts_spec.rb new file mode 100644 index 00000000000..a6ce5cdd7ab --- /dev/null +++ b/spec/graphql/mutations/issues/link_alerts_spec.rb @@ -0,0 +1,84 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Mutations::Issues::LinkAlerts, feature_category: :incident_management do + let_it_be(:project) { create(:project) } + let_it_be(:guest) { create(:user) } + let_it_be(:developer) { create(:user) } + let_it_be(:issue) { create(:incident, project: project) } + let_it_be(:alert1) { create(:alert_management_alert, project: project) } + let_it_be(:alert2) { create(:alert_management_alert, project: project) } + + let(:mutation) { described_class.new(object: nil, context: { current_user: user }, field: nil) } + + specify { expect(described_class).to require_graphql_authorizations(:update_issue, :admin_issue) } + + before_all do + project.add_guest(guest) + project.add_developer(developer) + end + + describe '#resolve' do + let(:alert_references) { [alert1.to_reference, alert2.details_url, 'invalid-reference'] } + + subject(:resolve) do + mutation.resolve( + project_path: issue.project.full_path, + iid: issue.iid, + alert_references: alert_references + ) + end + + context 'when the user is a guest' do + let(:user) { guest } + + it 'raises an error' do + expect { resolve }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable) + end + + context 'when a user is also an author' do + let!(:issue) { create(:incident, project: project, author: user) } + + it 'raises an error' do + expect { resolve }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable) + end + end + + context 'when a user is also an assignee' do + let!(:issue) { create(:incident, project: project, assignee_ids: [user.id]) } + + it 'raises an error' do + expect { resolve }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable) + end + end + end + + context 'when the user is a developer' do + let(:user) { developer } + + context 'when issue type is an incident' do + it 'calls LinkAlerts::CreateService with correct arguments' do + expect(::IncidentManagement::LinkAlerts::CreateService) + .to receive(:new) + .with(issue, user, alert_references) + .and_call_original + + resolve + end + + it 'returns no errors' do + expect(resolve[:errors]).to be_empty + end + end + + context 'when issue type is not an incident' do + let!(:issue) { create(:issue, project: project) } + + it 'does not update alert_management_alerts' do + expect { resolve }.not_to change { issue.alert_management_alerts } + end + end + end + end +end diff --git a/spec/graphql/mutations/issues/unlink_alert_spec.rb b/spec/graphql/mutations/issues/unlink_alert_spec.rb new file mode 100644 index 00000000000..2f1d5084faf --- /dev/null +++ b/spec/graphql/mutations/issues/unlink_alert_spec.rb @@ -0,0 +1,83 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Mutations::Issues::UnlinkAlert, feature_category: :incident_management do + let_it_be(:project) { create(:project) } + let_it_be(:another_project) { create(:project) } + let_it_be(:guest) { create(:user) } + let_it_be(:developer) { create(:user) } + let_it_be(:internal_alert) { create(:alert_management_alert, project: project) } + let_it_be(:external_alert) { create(:alert_management_alert, project: another_project) } + let_it_be(:issue) { create(:incident, project: project, alert_management_alerts: [internal_alert, external_alert]) } + + let(:mutation) { described_class.new(object: nil, context: { current_user: user }, field: nil) } + + specify { expect(described_class).to require_graphql_authorizations(:update_issue, :admin_issue) } + + before_all do + project.add_guest(guest) + project.add_developer(developer) + end + + describe '#resolve' do + let(:alert_to_unlink) { internal_alert } + + subject(:resolve) do + mutation.resolve( + project_path: issue.project.full_path, + iid: issue.iid, + alert_id: alert_to_unlink.to_global_id.to_s + ) + end + + context 'when the user is a guest' do + let(:user) { guest } + + it 'raises an error' do + expect { resolve }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable) + end + end + + context 'when the user is a developer' do + let(:user) { developer } + + shared_examples 'unlinking an alert' do + it 'unlinks the alert' do + expect { resolve }.to change { issue.reload.alert_management_alerts }.to match_array(remainded_alerts) + end + + it 'returns no errors' do + expect(resolve[:errors]).to be_empty + end + end + + context 'when unlinking internal alert' do + let(:alert_to_unlink) { internal_alert } + let(:remainded_alerts) { [external_alert] } + + it_behaves_like 'unlinking an alert' + end + + context 'when unlinking external alert' do + let(:alert_to_unlink) { external_alert } + let(:remainded_alerts) { [internal_alert] } + + it_behaves_like 'unlinking an alert' + end + + context 'when LinkAlerts::DestroyService responds with an error' do + it 'returns the error' do + service_instance = instance_double( + ::IncidentManagement::LinkAlerts::DestroyService, + execute: ServiceResponse.error(message: 'some error message') + ) + + allow(::IncidentManagement::LinkAlerts::DestroyService).to receive(:new).and_return(service_instance) + + expect(resolve[:errors]).to match_array(['some error message']) + end + end + end + end +end |