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

note_entity_shared_examples.rb « serializers « shared_examples « support « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2e557ca090c9413c12af3cbfa045f950c1e7bf80 (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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# frozen_string_literal: true

RSpec.shared_examples 'note entity' do
  subject { entity.as_json }

  context 'basic note' do
    it 'exposes correct elements' do
      expect(subject).to include(
        :attachment,
        :author,
        :award_emoji,
        :base_discussion,
        :current_user,
        :discussion_id,
        :emoji_awardable,
        :note,
        :note_html,
        :noteable_note_url,
        :report_abuse_path,
        :resolvable,
        :type
      )
    end

    it 'does not expose elements for specific notes cases' do
      expect(subject).not_to include(:last_edited_by, :last_edited_at, :system_note_icon_name)
    end

    it 'exposes author correctly' do
      expect(subject[:author]).to include(:id, :name, :username, :state, :avatar_url, :path)
    end

    it 'does not expose web_url for author' do
      expect(subject[:author]).not_to include(:web_url)
    end

    it 'exposes permission fields on current_user' do
      expect(subject[:current_user]).to include(:can_edit, :can_award_emoji, :can_resolve, :can_resolve_discussion)
    end

    describe ':can_resolve_discussion' do
      context 'discussion is resolvable' do
        before do
          expect(note.discussion).to receive(:resolvable?).and_return(true)
        end

        context 'user can resolve' do
          it 'is true' do
            expect(note.discussion).to receive(:can_resolve?).with(user).and_return(true)
            expect(subject[:current_user][:can_resolve_discussion]).to be_truthy
          end
        end

        context 'user cannot resolve' do
          it 'is false' do
            expect(note.discussion).to receive(:can_resolve?).with(user).and_return(false)
            expect(subject[:current_user][:can_resolve_discussion]).to be_falsey
          end
        end
      end

      context 'discussion is not resolvable' do
        it 'is false' do
          expect(note.discussion).to receive(:resolvable?).and_return(false)
          expect(subject[:current_user][:can_resolve_discussion]).to be_falsey
        end
      end
    end
  end

  describe ':outdated_line_change_path' do
    before do
      allow(note).to receive(:show_outdated_changes?).and_return(show_outdated_changes)
    end

    context 'when note shows outdated changes' do
      let(:show_outdated_changes) { true }

      it 'returns correct outdated_line_change_namespace_project_note_path' do
        path = "/#{note.project.namespace.path}/#{note.project.path}/notes/#{note.id}/outdated_line_change"
        expect(subject[:outdated_line_change_path]).to eq(path)
      end
    end

    context 'when note does not show outdated changes' do
      let(:show_outdated_changes) { false }

      it 'does not expose outdated_line_change_path' do
        expect(subject).not_to include(:outdated_line_change_path)
      end
    end
  end

  context 'when note was edited' do
    before do
      note.update!(updated_at: 1.minute.from_now, updated_by: user)
    end

    it 'exposes last_edited_at and last_edited_by elements' do
      expect(subject).to include(:last_edited_at, :last_edited_by)
    end
  end

  context 'when note is a system note' do
    before do
      note.update!(system: true)
    end

    it 'exposes system_note_icon_name element' do
      expect(subject).to include(:system_note_icon_name)
    end
  end
end