Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-09-20 14:18:08 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-09-20 14:18:08 +0300
commit5afcbe03ead9ada87621888a31a62652b10a7e4f (patch)
tree9918b67a0d0f0bafa6542e839a8be37adf73102d /spec/requests/api/graphql/mutations/admin/abuse_report_labels/create_spec.rb
parentc97c0201564848c1f53226fe19d71fdcc472f7d0 (diff)
Add latest changes from gitlab-org/gitlab@16-4-stable-eev16.4.0-rc42
Diffstat (limited to 'spec/requests/api/graphql/mutations/admin/abuse_report_labels/create_spec.rb')
-rw-r--r--spec/requests/api/graphql/mutations/admin/abuse_report_labels/create_spec.rb55
1 files changed, 55 insertions, 0 deletions
diff --git a/spec/requests/api/graphql/mutations/admin/abuse_report_labels/create_spec.rb b/spec/requests/api/graphql/mutations/admin/abuse_report_labels/create_spec.rb
new file mode 100644
index 00000000000..2a20d96d9c8
--- /dev/null
+++ b/spec/requests/api/graphql/mutations/admin/abuse_report_labels/create_spec.rb
@@ -0,0 +1,55 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Mutations::Admin::AbuseReportLabels::Create, feature_category: :insider_threat do
+ include GraphqlHelpers
+
+ let(:params) do
+ {
+ 'title' => 'foo',
+ 'color' => '#FF0000'
+ }
+ end
+
+ let(:mutation) { graphql_mutation(:abuse_report_label_create, params) }
+
+ subject { post_graphql_mutation(mutation, current_user: current_user) }
+
+ def mutation_response
+ graphql_mutation_response(:abuse_report_label_create)
+ end
+
+ context 'when the user does not have permission to create a label', :enable_admin_mode do
+ let_it_be(:current_user) { create(:user) }
+
+ it_behaves_like 'a mutation that returns a top-level access error'
+
+ it 'does not create the label' do
+ expect { subject }.not_to change { Admin::AbuseReportLabel.count }
+ end
+ end
+
+ context 'when the user has permission to create a label', :enable_admin_mode do
+ let_it_be(:current_user) { create(:admin) }
+
+ it 'creates the label' do
+ expect { subject }.to change { Admin::AbuseReportLabel.count }.to(1)
+
+ expect(mutation_response).to include('label' => a_hash_including(params))
+ end
+
+ context 'when there are errors' do
+ it 'does not create the label', :aggregate_failures do
+ create(:abuse_report_label, title: params['title'])
+
+ expect { subject }.not_to change { Label.count }
+
+ expect(mutation_response).to include({
+ 'label' => nil,
+ 'errors' => ['Title has already been taken']
+ })
+ end
+ end
+ end
+end