File: comment_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 (120 lines) | stat: -rw-r--r-- 3,580 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
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
114
115
116
117
118
119
120
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe BitbucketServer::Representation::Comment, feature_category: :importers do
  let(:activities) { Gitlab::Json.parse(fixture_file('importers/bitbucket_server/activities.json'))['values'] }
  let(:comment) { activities.first }

  subject(:comment_representation) { described_class.new(comment) }

  describe '#id' do
    it { expect(comment_representation.id).to eq(9) }
  end

  describe '#author_name' do
    it { expect(comment_representation.author_name).to eq('root') }
  end

  describe '#author_username' do
    it 'returns username' do
      expect(comment_representation.author_username).to eq('username')
    end

    context 'when username is absent' do
      before do
        comment['comment']['author'].delete('username')
      end

      it 'returns slug' do
        expect(comment_representation.author_username).to eq('slug')
      end
    end

    context 'when slug and username are absent' do
      before do
        comment['comment']['author'].delete('username')
        comment['comment']['author'].delete('slug')
      end

      it 'returns displayName' do
        expect(comment_representation.author_username).to eq('root')
      end
    end
  end

  describe '#author_email' do
    it { expect(comment_representation.author_email).to eq('test.user@example.com') }
  end

  describe '#note' do
    it { expect(comment_representation.note).to eq('is this a new line?') }
  end

  describe '#created_at' do
    it { expect(comment_representation.created_at).to be_a(Time) }
  end

  describe '#updated_at' do
    it { expect(comment_representation.updated_at).to be_a(Time) }
  end

  describe '#comments' do
    it { expect(comment_representation.comments.count).to eq(4) }
    it { expect(comment_representation.comments).to all(be_a(described_class)) }
    it { expect(comment_representation.comments.map(&:note)).to match_array(["Hello world", "Ok", "hello", "hi"]) }

    # The thread should look like:
    #
    # is this a new line? (comment_representation)
    #   -> Hello world (first)
    #      -> Ok (third)
    #      -> Hi (fourth)
    #   -> hello (second)
    it 'comments have the right parent' do
      first, second, third, fourth = comment_representation.comments[0..4]

      expect(comment_representation.parent_comment).to be_nil
      expect(first.parent_comment).to eq(comment_representation)
      expect(second.parent_comment).to eq(comment_representation)
      expect(third.parent_comment).to eq(first)
      expect(fourth.parent_comment).to eq(first)
    end
  end

  describe '#to_hash' do
    specify do
      expect(comment_representation.to_hash).to match(
        a_hash_including(
          id: 9,
          author_name: 'root',
          author_email: 'test.user@example.com',
          author_username: 'username',
          note: 'is this a new line?',
          comments: array_including(
            hash_including(
              note: 'Hello world',
              comments: [],
              parent_comment_note: 'is this a new line?'
            ),
            hash_including(
              note: 'Ok',
              comments: [],
              parent_comment_note: 'Hello world'
            ),
            hash_including(
              note: 'hi',
              comments: [],
              parent_comment_note: 'Hello world'
            ),
            hash_including(
              note: 'hello',
              comments: [],
              parent_comment_note: 'is this a new line?'
            )
          )
        )
      )
    end
  end
end