File: create_spec.rb

package info (click to toggle)
gitlab 17.6.5-19
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 629,368 kB
  • sloc: ruby: 1,915,304; javascript: 557,307; sql: 60,639; xml: 6,509; sh: 4,567; makefile: 1,239; python: 406
file content (82 lines) | stat: -rw-r--r-- 2,542 bytes parent folder | download
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'Adding an abuse report note', feature_category: :insider_threat do
  include GraphqlHelpers

  let_it_be(:user) { create(:user) }
  let_it_be(:admin) { create(:admin) }
  let_it_be(:abuse_report) { create(:abuse_report) }
  let_it_be(:discussion_note) { create(:abuse_report_discussion_note) }

  let(:discussion) { nil }
  let(:body) { 'Body text' }
  let(:current_user) { user }
  let(:mutation) do
    variables = {
      abuse_report_id: GitlabSchema.id_from_object(abuse_report).to_s,
      discussion_id: (GitlabSchema.id_from_object(discussion).to_s if discussion),
      body: body
    }

    graphql_mutation(:create_abuse_report_note, variables)
  end

  def mutation_response
    graphql_mutation_response(:create_abuse_report_note)
  end

  it_behaves_like 'a Note mutation when the user does not have permission'

  context 'when the user has permission' do
    let(:current_user) { admin }

    context 'when abuse_report_notes FF is not enabled' do
      before do
        stub_feature_flags(abuse_report_notes: false)
      end

      it_behaves_like 'a mutation that returns a top-level access error'
    end

    context 'when abuse_report_notes FF is enabled' do
      before do
        stub_feature_flags(abuse_report_notes: true)
      end

      it_behaves_like 'a working GraphQL mutation'
      it_behaves_like 'a Note mutation when there are active record validation errors', model: AntiAbuse::Reports::Note

      it do
        expect do
          post_graphql_mutation(mutation, current_user: current_user)
        end.to change { AntiAbuse::Reports::Note.count }.by(1)
      end

      it 'returns the note' do
        post_graphql_mutation(mutation, current_user: current_user)

        expect(mutation_response['note']['body']).to eq('Body text')
      end

      describe 'creating Notes in reply to a discussion' do
        let(:discussion) { discussion_note.to_discussion }

        it 'creates a Note in a discussion' do
          post_graphql_mutation(mutation, current_user: current_user)

          expect(mutation_response['note']['discussion']).to match a_graphql_entity_for(discussion)
        end

        context 'when the discussion_id is not for a Discussion' do
          let(:discussion) { create(:issue) }

          it_behaves_like 'a mutation that returns top-level errors' do
            let(:match_errors) { include(/ does not represent an instance of Discussion/) }
          end
        end
      end
    end
  end
end