2019-11-20 01:06:16 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-03-22 21:07:33 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 14:09:03 -04:00
|
|
|
RSpec.describe Gitlab::GitlabImport::Client do
|
2016-06-08 10:49:01 -04:00
|
|
|
include ImportSpecHelper
|
|
|
|
|
2015-03-22 21:07:33 -04:00
|
|
|
let(:token) { '123456' }
|
2017-07-25 13:09:00 -04:00
|
|
|
let(:client) { described_class.new(token) }
|
2015-03-22 21:07:33 -04:00
|
|
|
|
|
|
|
before do
|
2016-06-08 10:49:01 -04:00
|
|
|
stub_omniauth_provider('gitlab')
|
2015-03-22 21:07:33 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'all OAuth2 client options are symbols' do
|
2020-01-23 10:08:46 -05:00
|
|
|
expect(client.client.options.keys).to all(be_kind_of(Symbol))
|
2015-03-22 21:07:33 -04:00
|
|
|
end
|
2018-07-23 03:52:15 -04:00
|
|
|
|
|
|
|
it 'uses membership and simple flags' do
|
|
|
|
stub_request('/api/v4/projects?membership=true&page=1&per_page=100&simple=true')
|
|
|
|
|
2019-12-06 19:07:51 -05:00
|
|
|
expect_next_instance_of(OAuth2::Response) do |instance|
|
|
|
|
expect(instance).to receive(:parsed).and_return([])
|
|
|
|
end
|
2018-07-23 03:52:15 -04:00
|
|
|
|
|
|
|
expect(client.projects.to_a).to eq []
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples 'pagination params' do
|
|
|
|
before do
|
2019-12-06 19:07:51 -05:00
|
|
|
allow_next_instance_of(OAuth2::Response) do |instance|
|
|
|
|
allow(instance).to receive(:parsed).and_return([])
|
|
|
|
end
|
2018-07-23 03:52:15 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'allows page_limit param' do
|
2019-12-06 19:07:51 -05:00
|
|
|
allow_next_instance_of(OAuth2::Response) do |instance|
|
|
|
|
allow(instance).to receive(:parsed).and_return(element_list)
|
|
|
|
end
|
2018-07-23 03:52:15 -04:00
|
|
|
|
|
|
|
expect(client).to receive(:lazy_page_iterator).with(hash_including(page_limit: 2)).and_call_original
|
|
|
|
|
|
|
|
client.send(method, *args, page_limit: 2, per_page: 1).to_a
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'allows per_page param' do
|
|
|
|
expect(client).to receive(:lazy_page_iterator).with(hash_including(per_page: 2)).and_call_original
|
|
|
|
|
|
|
|
client.send(method, *args, per_page: 2).to_a
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'allows starting_page param' do
|
|
|
|
expect(client).to receive(:lazy_page_iterator).with(hash_including(starting_page: 3)).and_call_original
|
|
|
|
|
|
|
|
client.send(method, *args, starting_page: 3).to_a
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#projects' do
|
|
|
|
subject(:method) { :projects }
|
2019-10-18 07:11:44 -04:00
|
|
|
|
2018-07-23 03:52:15 -04:00
|
|
|
let(:args) { [] }
|
|
|
|
let(:element_list) { build_list(:project, 2) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
stub_request('/api/v4/projects?membership=true&page=1&per_page=1&simple=true')
|
|
|
|
stub_request('/api/v4/projects?membership=true&page=2&per_page=1&simple=true')
|
|
|
|
stub_request('/api/v4/projects?membership=true&page=1&per_page=2&simple=true')
|
|
|
|
stub_request('/api/v4/projects?membership=true&page=3&per_page=100&simple=true')
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'pagination params'
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#issues' do
|
|
|
|
subject(:method) { :issues }
|
2019-10-18 07:11:44 -04:00
|
|
|
|
2018-07-23 03:52:15 -04:00
|
|
|
let(:args) { [1] }
|
|
|
|
let(:element_list) { build_list(:issue, 2) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
stub_request('/api/v4/projects/1/issues?page=1&per_page=1')
|
|
|
|
stub_request('/api/v4/projects/1/issues?page=2&per_page=1')
|
|
|
|
stub_request('/api/v4/projects/1/issues?page=1&per_page=2')
|
|
|
|
stub_request('/api/v4/projects/1/issues?page=3&per_page=100')
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'pagination params'
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#issue_comments' do
|
|
|
|
subject(:method) { :issue_comments }
|
2019-10-18 07:11:44 -04:00
|
|
|
|
2018-07-23 03:52:15 -04:00
|
|
|
let(:args) { [1, 1] }
|
|
|
|
let(:element_list) { build_list(:note_on_issue, 2) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
stub_request('/api/v4/projects/1/issues/1/notes?page=1&per_page=1')
|
|
|
|
stub_request('/api/v4/projects/1/issues/1/notes?page=2&per_page=1')
|
|
|
|
stub_request('/api/v4/projects/1/issues/1/notes?page=1&per_page=2')
|
|
|
|
stub_request('/api/v4/projects/1/issues/1/notes?page=3&per_page=100')
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'pagination params'
|
|
|
|
end
|
|
|
|
|
|
|
|
def stub_request(path)
|
|
|
|
WebMock.stub_request(:get, "https://gitlab.com#{path}")
|
|
|
|
.to_return(status: 200)
|
|
|
|
end
|
2015-03-22 21:07:33 -04:00
|
|
|
end
|