BigW Consortium Gitlab

client_spec.rb 2.19 KB
Newer Older
1 2
require 'spec_helper'

Douwe Maan committed
3
describe Gitlab::BitbucketImport::Client, lib: true do
4 5 6 7 8 9 10 11 12 13 14 15 16
  let(:token) { '123456' }
  let(:secret) { 'secret' }
  let(:client) { Gitlab::BitbucketImport::Client.new(token, secret) }

  before do
    Gitlab.config.omniauth.providers << OpenStruct.new(app_id: "asd123", app_secret: "asd123", name: "bitbucket")
  end

  it 'all OAuth client options are symbols' do
    client.consumer.options.keys.each do |key|
      expect(key).to be_kind_of(Symbol)
    end
  end
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36

  context 'issues' do
    let(:per_page) { 50 }
    let(:count) { 95 }
    let(:sample_issues) do
      issues = []

      count.times do |i|
        issues << { local_id: i }
      end

      issues
    end
    let(:first_sample_data) { { count: count, issues: sample_issues[0..per_page - 1] } }
    let(:second_sample_data) { { count: count, issues: sample_issues[per_page..count] } }
    let(:project_id) { 'namespace/repo' }

    it 'retrieves issues over a number of pages' do
      stub_request(:get,
                   "https://bitbucket.org/api/1.0/repositories/#{project_id}/issues?limit=50&sort=utc_created_on&start=0").
37 38 39
        to_return(status: 200,
                  body: first_sample_data.to_json,
                  headers: {})
40 41 42

      stub_request(:get,
                   "https://bitbucket.org/api/1.0/repositories/#{project_id}/issues?limit=50&sort=utc_created_on&start=50").
43 44 45
        to_return(status: 200,
                  body: second_sample_data.to_json,
                  headers: {})
46 47 48 49 50

      issues = client.issues(project_id)
      expect(issues.count).to eq(95)
    end
  end
51 52 53 54 55

  context 'project import' do
    it 'calls .from_project with no errors' do
      project = create(:empty_project)
      project.create_or_update_import_data(credentials:
James Lopez committed
56 57 58 59
                                             { user: "git",
                                               password: nil,
                                               bb_session: { bitbucket_access_token: "test",
                                                             bitbucket_access_token_secret: "test" } })
60 61 62 63 64
      project.import_url = "ssh://git@bitbucket.org/test/test.git"

      expect { described_class.from_project(project) }.to_not raise_error
    end
  end
65
end