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

create_spec.rb « abuse_report_labels « admin « mutations « graphql « api « requests « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2a20d96d9c8c21fb21724b20e7edbe43897665ad (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
53
54
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