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

pull_request_review_spec.rb « representation « github_import « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d6e7a8172f7d6f4014d62d1ba5ce1e0a33e95973 (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
# frozen_string_literal: true

require 'fast_spec_helper'

RSpec.describe Gitlab::GithubImport::Representation::PullRequestReview do
  let(:submitted_at) { Time.new(2017, 1, 1, 12, 00).utc }

  shared_examples 'a PullRequest review' do
    it 'returns an instance of PullRequest' do
      expect(review).to be_an_instance_of(described_class)
      expect(review.author).to be_an_instance_of(Gitlab::GithubImport::Representation::User)
      expect(review.author.id).to eq(4)
      expect(review.author.login).to eq('alice')
      expect(review.note).to eq('note')
      expect(review.review_type).to eq('APPROVED')
      expect(review.submitted_at).to eq(submitted_at)
      expect(review.review_id).to eq(999)
      expect(review.merge_request_id).to eq(42)
    end
  end

  describe '.from_api_response' do
    let(:response) do
      double(
        :response,
        id: 999,
        merge_request_id: 42,
        body: 'note',
        state: 'APPROVED',
        user: double(:user, id: 4, login: 'alice'),
        submitted_at: submitted_at
      )
    end

    it_behaves_like 'a PullRequest review' do
      let(:review) { described_class.from_api_response(response) }
    end

    it 'does not set the user if the response did not include a user' do
      allow(response)
        .to receive(:user)
        .and_return(nil)

      review = described_class.from_api_response(response)

      expect(review.author).to be_nil
    end
  end

  describe '.from_json_hash' do
    let(:hash) do
      {
        'review_id' => 999,
        'merge_request_id' => 42,
        'note' => 'note',
        'review_type' => 'APPROVED',
        'author' => { 'id' => 4, 'login' => 'alice' },
        'submitted_at' => submitted_at.to_s
      }
    end

    it_behaves_like 'a PullRequest review' do
      let(:review) { described_class.from_json_hash(hash) }
    end

    it 'does not set the user if the response did not include a user' do
      review = described_class.from_json_hash(hash.except('author'))

      expect(review.author).to be_nil
    end

    it 'does not fail when submitted_at is blank' do
      review = described_class.from_json_hash(hash.except('submitted_at'))

      expect(review.submitted_at).to be_nil
    end
  end

  describe '#github_identifiers' do
    it 'returns a hash with needed identifiers' do
      github_identifiers = {
        review_id: 999,
        merge_request_id: 42
      }
      other_attributes = { something_else: '_something_else_' }
      review = described_class.new(github_identifiers.merge(other_attributes))

      expect(review.github_identifiers).to eq(github_identifiers)
    end
  end
end