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

synthetic_note_resolver_spec.rb « notes « graphql « api « requests « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 1199aeb4c39b201af2b18667d892341c9be589c3 (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
56
57
58
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'Query.synthetic_note(noteable_id, sha)', feature_category: :team_planning do
  include GraphqlHelpers

  let_it_be(:current_user) { create(:user) }
  let_it_be(:project) { create(:project, :private) }
  let_it_be(:issue) { create(:issue, project: project) }
  let_it_be(:label) { create(:label, project: project) }
  let_it_be(:label_event, refind: true) do
    create(:resource_label_event, user: current_user, issue: issue, label: label, action: 'add', created_at: 2.days.ago)
  end

  let(:label_note) { LabelNote.from_events([label_event]) }
  let(:global_id) { ::Gitlab::GlobalId.build(label_note, model_name: LabelNote.to_s, id: label_note.discussion_id) }
  let(:note_params) { { sha: label_note.discussion_id, noteable_id: global_id_of(issue) } }
  let(:note_data) { graphql_data['syntheticNote'] }
  let(:note_fields) { all_graphql_fields_for('Note'.classify) }

  let(:query) do
    graphql_query_for('synthetic_note', note_params, note_fields)
  end

  context 'when the user does not have access to read the note' do
    it 'returns nil' do
      post_graphql(query, current_user: current_user)

      expect(note_data).to be nil
    end
  end

  context 'when the user has access to read the note' do
    before do
      project.add_guest(current_user)
    end

    it 'returns synthetic note' do
      post_graphql(query, current_user: current_user)

      expect(note_data['id']).to eq(global_id.to_s)
    end

    context 'and notes widget is not available' do
      before do
        WorkItems::Type.default_by_type(:issue).widget_definitions
          .find_by_widget_type(:notes).update!(disabled: true)
      end

      it 'returns nil' do
        post_graphql(query, current_user: current_user)

        expect(note_data).to be nil
      end
    end
  end
end