debian-mirror-gitlab/spec/lib/gitlab/gitlab_import/client_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

112 lines
3.2 KiB
Ruby
Raw Normal View History

2020-01-01 13:55:28 +05:30
# frozen_string_literal: true
2015-04-26 12:48:37 +05:30
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe Gitlab::GitlabImport::Client do
include ImportSpecHelper
2015-04-26 12:48:37 +05:30
let(:token) { '123456' }
2017-09-10 17:25:29 +05:30
let(:client) { described_class.new(token) }
2015-04-26 12:48:37 +05:30
before do
stub_omniauth_provider('gitlab')
2015-04-26 12:48:37 +05:30
end
it 'all OAuth2 client options are symbols' do
2020-03-09 13:42:32 +05:30
expect(client.client.options.keys).to all(be_kind_of(Symbol))
2015-04-26 12:48:37 +05:30
end
2018-11-18 11:00:15 +05:30
it 'uses membership and simple flags' do
stub_request('/api/v4/projects?membership=true&page=1&per_page=100&simple=true')
2020-01-01 13:55:28 +05:30
expect_next_instance_of(OAuth2::Response) do |instance|
expect(instance).to receive(:parsed).and_return([])
end
2018-11-18 11:00:15 +05:30
expect(client.projects.to_a).to eq []
end
shared_examples 'pagination params' do
before do
2020-01-01 13:55:28 +05:30
allow_next_instance_of(OAuth2::Response) do |instance|
allow(instance).to receive(:parsed).and_return([])
end
2018-11-18 11:00:15 +05:30
end
it 'allows page_limit param' do
2020-01-01 13:55:28 +05:30
allow_next_instance_of(OAuth2::Response) do |instance|
allow(instance).to receive(:parsed).and_return(element_list)
end
2018-11-18 11:00:15 +05:30
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-12-21 20:55:43 +05:30
2018-11-18 11:00:15 +05:30
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-12-21 20:55:43 +05:30
2018-11-18 11:00:15 +05:30
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-12-21 20:55:43 +05:30
2018-11-18 11:00:15 +05:30
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-04-26 12:48:37 +05:30
end