1# frozen_string_literal: true 2require 'spec_helper' 3 4RSpec.describe Gitlab::PhabricatorImport::Conduit::User do 5 let(:user_client) do 6 described_class.new(phabricator_url: 'https://see-ya-later.phabricator', api_token: 'api-token') 7 end 8 9 describe '#users' do 10 let(:fake_client) { double('Phabricator client') } 11 12 before do 13 allow(user_client).to receive(:client).and_return(fake_client) 14 end 15 16 it 'calls the api with the correct params' do 17 expected_params = { 18 constraints: { phids: %w[phid-1 phid-2] } 19 } 20 21 expect(fake_client).to receive(:get).with('user.search', 22 params: expected_params) 23 24 user_client.users(%w[phid-1 phid-2]) 25 end 26 27 it 'returns an array of parsed responses' do 28 response = Gitlab::PhabricatorImport::Conduit::Response 29 .new(fixture_file('phabricator_responses/user.search.json')) 30 31 allow(fake_client).to receive(:get).and_return(response) 32 33 expect(user_client.users(%w[some phids])).to match_array([an_instance_of(Gitlab::PhabricatorImport::Conduit::UsersResponse)]) 34 end 35 36 it 'performs multiple requests if more phids than the maximum page size are passed' do 37 stub_const('Gitlab::PhabricatorImport::Conduit::User::MAX_PAGE_SIZE', 1) 38 first_params = { constraints: { phids: ['phid-1'] } } 39 second_params = { constraints: { phids: ['phid-2'] } } 40 41 expect(fake_client).to receive(:get).with('user.search', 42 params: first_params).once 43 expect(fake_client).to receive(:get).with('user.search', 44 params: second_params).once 45 46 user_client.users(%w[phid-1 phid-2]) 47 end 48 end 49end 50