2019-07-25 01:21:37 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-07-27 02:05:22 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe BitbucketServer::Client do
|
2018-08-01 00:14:36 -04:00
|
|
|
let(:base_uri) { 'https://test:7990/stash/' }
|
|
|
|
let(:options) { { base_uri: base_uri, user: 'bitbucket', password: 'mypassword' } }
|
2018-07-27 02:05:22 -04:00
|
|
|
let(:project) { 'SOME-PROJECT' }
|
|
|
|
let(:repo_slug) { 'my-repo' }
|
2018-07-28 20:09:10 -04:00
|
|
|
let(:headers) { { "Content-Type" => "application/json" } }
|
2018-07-27 02:05:22 -04:00
|
|
|
|
|
|
|
subject { described_class.new(options) }
|
|
|
|
|
|
|
|
describe '#pull_requests' do
|
|
|
|
let(:path) { "/projects/#{project}/repos/#{repo_slug}/pull-requests?state=ALL" }
|
|
|
|
|
|
|
|
it 'requests a collection' do
|
2018-11-05 18:37:21 -05:00
|
|
|
expect(BitbucketServer::Paginator).to receive(:new).with(anything, path, :pull_request, page_offset: 0, limit: nil)
|
2018-07-27 02:05:22 -04:00
|
|
|
|
|
|
|
subject.pull_requests(project, repo_slug)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#activities' do
|
|
|
|
let(:path) { "/projects/#{project}/repos/#{repo_slug}/pull-requests/1/activities" }
|
|
|
|
|
|
|
|
it 'requests a collection' do
|
2018-11-05 18:37:21 -05:00
|
|
|
expect(BitbucketServer::Paginator).to receive(:new).with(anything, path, :activity, page_offset: 0, limit: nil)
|
2018-07-27 02:05:22 -04:00
|
|
|
|
|
|
|
subject.activities(project, repo_slug, 1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#repo' do
|
|
|
|
let(:path) { "/projects/#{project}/repos/#{repo_slug}" }
|
2018-08-01 00:14:36 -04:00
|
|
|
let(:url) { "#{base_uri}rest/api/1.0/projects/SOME-PROJECT/repos/my-repo" }
|
2018-07-27 02:05:22 -04:00
|
|
|
|
|
|
|
it 'requests a specific repository' do
|
2018-07-28 20:09:10 -04:00
|
|
|
stub_request(:get, url).to_return(status: 200, headers: headers, body: '{}')
|
2018-07-27 02:05:22 -04:00
|
|
|
|
|
|
|
subject.repo(project, repo_slug)
|
|
|
|
|
|
|
|
expect(WebMock).to have_requested(:get, url)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#repos' do
|
|
|
|
let(:path) { "/repos" }
|
|
|
|
|
|
|
|
it 'requests a collection' do
|
2018-11-05 18:37:21 -05:00
|
|
|
expect(BitbucketServer::Paginator).to receive(:new).with(anything, path, :repo, page_offset: 0, limit: nil)
|
2018-07-27 02:05:22 -04:00
|
|
|
|
|
|
|
subject.repos
|
|
|
|
end
|
2018-11-05 18:37:21 -05:00
|
|
|
|
|
|
|
it 'requests a collection with an offset and limit' do
|
|
|
|
expect(BitbucketServer::Paginator).to receive(:new).with(anything, path, :repo, page_offset: 10, limit: 25)
|
|
|
|
|
|
|
|
subject.repos(page_offset: 10, limit: 25)
|
|
|
|
end
|
2019-08-02 13:34:06 -04:00
|
|
|
|
|
|
|
context 'when filter param is passed' do
|
|
|
|
let(:filter) { 'test' }
|
|
|
|
let(:expected_path) { "#{path}?name=#{filter}" }
|
|
|
|
|
|
|
|
it 'requests a collection with filter applied' do
|
|
|
|
expect(BitbucketServer::Paginator).to receive(:new).with(anything, expected_path, :repo, page_offset: 0, limit: nil)
|
|
|
|
|
|
|
|
subject.repos(filter: filter)
|
|
|
|
end
|
|
|
|
end
|
2018-07-27 02:05:22 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '#create_branch' do
|
|
|
|
let(:branch) { 'test-branch' }
|
|
|
|
let(:sha) { '12345678' }
|
2018-08-01 00:14:36 -04:00
|
|
|
let(:url) { "#{base_uri}rest/api/1.0/projects/SOME-PROJECT/repos/my-repo/branches" }
|
2018-07-27 02:05:22 -04:00
|
|
|
|
|
|
|
it 'requests Bitbucket to create a branch' do
|
2019-02-16 18:30:02 -05:00
|
|
|
stub_request(:post, url).to_return(status: 204, headers: headers, body: nil)
|
2018-07-27 02:05:22 -04:00
|
|
|
|
|
|
|
subject.create_branch(project, repo_slug, branch, sha)
|
|
|
|
|
|
|
|
expect(WebMock).to have_requested(:post, url)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#delete_branch' do
|
|
|
|
let(:branch) { 'test-branch' }
|
|
|
|
let(:sha) { '12345678' }
|
2018-08-01 00:14:36 -04:00
|
|
|
let(:url) { "#{base_uri}rest/branch-utils/1.0/projects/SOME-PROJECT/repos/my-repo/branches" }
|
2018-07-27 02:05:22 -04:00
|
|
|
|
|
|
|
it 'requests Bitbucket to create a branch' do
|
2019-02-16 18:30:02 -05:00
|
|
|
stub_request(:delete, url).to_return(status: 204, headers: headers, body: nil)
|
2018-07-27 02:05:22 -04:00
|
|
|
|
|
|
|
subject.delete_branch(project, repo_slug, branch, sha)
|
|
|
|
|
|
|
|
expect(WebMock).to have_requested(:delete, url)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|