summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/phabricator_import/conduit/user_spec.rb
blob: e88eec2c393de5bd8505b22a51718c8ffeeba4f0 (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
# frozen_string_literal: true
require 'spec_helper'

describe Gitlab::PhabricatorImport::Conduit::User do
  let(:user_client) do
    described_class.new(phabricator_url: 'https://see-ya-later.phabricator', api_token: 'api-token')
  end

  describe '#users' do
    let(:fake_client) { double('Phabricator client') }

    before do
      allow(user_client).to receive(:client).and_return(fake_client)
    end

    it 'calls the api with the correct params' do
      expected_params = {
         constraints: { phids: ['phid-1', 'phid-2'] }
      }

      expect(fake_client).to receive(:get).with('user.search',
                                                params: expected_params)

      user_client.users(['phid-1', 'phid-2'])
    end

    it 'returns an array of parsed responses' do
      response = Gitlab::PhabricatorImport::Conduit::Response
                   .new(fixture_file('phabricator_responses/user.search.json'))

      allow(fake_client).to receive(:get).and_return(response)

      expect(user_client.users(%w[some phids])).to match_array([an_instance_of(Gitlab::PhabricatorImport::Conduit::UsersResponse)])
    end

    it 'performs multiple requests if more phids than the maximum page size are passed' do
      stub_const('Gitlab::PhabricatorImport::Conduit::User::MAX_PAGE_SIZE', 1)
      first_params = { constraints: { phids: ['phid-1'] } }
      second_params = { constraints: { phids: ['phid-2'] } }

      expect(fake_client).to receive(:get).with('user.search',
                                                params: first_params).once
      expect(fake_client).to receive(:get).with('user.search',
                                                params: second_params).once

      user_client.users(['phid-1', 'phid-2'])
    end
  end
end