Read about our upcoming Code of Conduct on this issue

This instance will be upgraded to Heptapod 0.28.0 on 2022-01-18 at 14:00 UTC+1 (a few minutes of down time)

Commit 314c4746 authored by Valery Sizov's avatar Valery Sizov
Browse files

Specs for Bitbucket::Connections and Bitbucket::Collections

parent 633b7df6efb2
......@@ -15,18 +15,6 @@ def initialize(options = {})
@refresh_token = options[:refresh_token]
end
def client
@client ||= OAuth2::Client.new(provider.app_id, provider.app_secret, options)
end
def connection
@connection ||= OAuth2::AccessToken.new(client, @token, refresh_token: @refresh_token, expires_at: @expires_at, expires_in: @expires_in)
end
def set_default_query_parameters(params = {})
@default_query.merge!(params)
end
def get(path, extra_query = {})
refresh! if expired?
......@@ -52,6 +40,14 @@ def refresh!
attr_reader :expires_at, :expires_in, :refresh_token, :token
def client
@client ||= OAuth2::Client.new(provider.app_id, provider.app_secret, options)
end
def connection
@connection ||= OAuth2::AccessToken.new(client, @token, refresh_token: @refresh_token, expires_at: @expires_at, expires_in: @expires_in)
end
def build_url(path)
return path if path.starts_with?(root_url)
......
......@@ -7,8 +7,6 @@ def initialize(connection, url, type)
@type = type
@url = url
@page = nil
connection.set_default_query_parameters(pagelen: PAGE_LENGTH, sort: :created_on)
end
def items
......@@ -31,7 +29,7 @@ def next_url
end
def fetch_next_page
parsed_response = connection.get(next_url)
parsed_response = connection.get(next_url, { pagelen: PAGE_LENGTH, sort: :created_on })
Page.new(parsed_response, type)
end
end
......
require 'spec_helper'
# Emulates paginator. It returns 2 pages with results
class TestPaginator
def initialize
@current_page = 0
end
def items
@current_page += 1
raise StopIteration if @current_page > 2
["result_1_page_#{@current_page}", "result_2_page_#{@current_page}"]
end
end
describe Bitbucket::Collection do
it "iterates paginator" do
collection = described_class.new(TestPaginator.new)
expect(collection.to_a).to match(["result_1_page_1", "result_2_page_1", "result_1_page_2", "result_2_page_2"])
end
end
require 'spec_helper'
describe Bitbucket::Connection do
describe '#get' do
it 'calls OAuth2::AccessToken::get' do
expect_any_instance_of(OAuth2::AccessToken).to receive(:get).and_return(double(parsed: true))
connection = described_class.new({})
connection.get('/users')
end
end
describe '#expired?' do
it 'calls connection.expired?' do
expect_any_instance_of(OAuth2::AccessToken).to receive(:expired?).and_return(true)
expect(described_class.new({}).expired?).to be_truthy
end
end
describe '#refresh!' do
it 'calls connection.refresh!' do
response = double(token: nil, expires_at: nil, expires_in: nil, refresh_token: nil)
expect_any_instance_of(OAuth2::AccessToken).to receive(:refresh!).and_return(response)
described_class.new({}).refresh!
end
end
end
......@@ -2,6 +2,7 @@
describe Gitlab::BitbucketImport::ProjectCreator, lib: true do
let(:user) { create(:user) }
let(:repo) do
double(name: 'Vim',
slug: 'vim',
......@@ -12,6 +13,7 @@
visibility_level: Gitlab::VisibilityLevel::PRIVATE,
clone_url: 'ssh://git@bitbucket.org/asd/vim.git')
end
let(:namespace){ create(:group, owner: user) }
let(:token) { "asdasd12345" }
let(:secret) { "sekrettt" }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment