2019-04-15 06:17:05 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2014-12-31 08:07:48 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2015-02-02 20:01:07 -05:00
|
|
|
describe Import::GithubController do
|
2015-05-21 17:40:13 -04:00
|
|
|
include ImportSpecHelper
|
|
|
|
|
2016-12-15 11:31:14 -05:00
|
|
|
let(:provider) { :github }
|
2015-08-07 03:06:20 -04:00
|
|
|
|
2016-12-15 11:31:14 -05:00
|
|
|
include_context 'a GitHub-ish import controller'
|
2014-12-31 08:07:48 -05:00
|
|
|
|
2016-05-02 11:22:38 -04:00
|
|
|
describe "GET new" do
|
2016-12-15 11:31:14 -05:00
|
|
|
it_behaves_like 'a GitHub-ish import controller: GET new'
|
2016-05-02 11:22:38 -04:00
|
|
|
|
2016-12-15 11:31:14 -05:00
|
|
|
it "redirects to GitHub for an access token if logged in with GitHub" do
|
|
|
|
allow(controller).to receive(:logged_in_with_provider?).and_return(true)
|
2019-01-22 12:38:08 -05:00
|
|
|
expect(controller).to receive(:go_to_provider_for_permissions).and_call_original
|
|
|
|
allow_any_instance_of(Gitlab::LegacyGithubImport::Client)
|
|
|
|
.to receive(:authorize_url)
|
|
|
|
.with(users_import_github_callback_url)
|
|
|
|
.and_call_original
|
2016-05-02 11:22:38 -04:00
|
|
|
|
|
|
|
get :new
|
2019-01-22 12:38:08 -05:00
|
|
|
|
|
|
|
expect(response).to have_http_status(302)
|
2016-05-02 11:22:38 -04:00
|
|
|
end
|
2018-12-10 14:52:04 -05:00
|
|
|
|
|
|
|
it "prompts for an access token if GitHub not configured" do
|
|
|
|
allow(controller).to receive(:github_import_configured?).and_return(false)
|
|
|
|
expect(controller).not_to receive(:go_to_provider_for_permissions)
|
|
|
|
|
|
|
|
get :new
|
|
|
|
|
|
|
|
expect(response).to have_http_status(200)
|
|
|
|
end
|
2016-05-02 11:22:38 -04:00
|
|
|
end
|
|
|
|
|
2014-12-31 08:07:48 -05:00
|
|
|
describe "GET callback" do
|
|
|
|
it "updates access token" do
|
|
|
|
token = "asdasd12345"
|
2017-10-13 12:50:36 -04:00
|
|
|
allow_any_instance_of(Gitlab::LegacyGithubImport::Client)
|
2017-06-21 09:48:12 -04:00
|
|
|
.to receive(:get_token).and_return(token)
|
2017-10-13 12:50:36 -04:00
|
|
|
allow_any_instance_of(Gitlab::LegacyGithubImport::Client)
|
2017-06-21 09:48:12 -04:00
|
|
|
.to receive(:github_options).and_return({})
|
2015-05-21 17:40:13 -04:00
|
|
|
stub_omniauth_provider('github')
|
2014-12-31 08:07:48 -05:00
|
|
|
|
|
|
|
get :callback
|
2015-02-12 13:32:58 -05:00
|
|
|
|
2016-12-16 11:43:34 -05:00
|
|
|
expect(session[:github_access_token]).to eq(token)
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(controller).to redirect_to(status_import_github_url)
|
2014-12-31 08:07:48 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-05-02 11:22:38 -04:00
|
|
|
describe "POST personal_access_token" do
|
2016-12-15 11:31:14 -05:00
|
|
|
it_behaves_like 'a GitHub-ish import controller: POST personal_access_token'
|
2016-05-02 11:22:38 -04:00
|
|
|
end
|
|
|
|
|
2014-12-31 08:07:48 -05:00
|
|
|
describe "GET status" do
|
2016-12-15 11:31:14 -05:00
|
|
|
it_behaves_like 'a GitHub-ish import controller: GET status'
|
2014-12-31 08:07:48 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "POST create" do
|
2016-12-15 11:31:14 -05:00
|
|
|
it_behaves_like 'a GitHub-ish import controller: POST create'
|
2014-12-31 08:07:48 -05:00
|
|
|
end
|
2018-11-07 11:44:21 -05:00
|
|
|
|
|
|
|
describe "GET realtime_changes" do
|
|
|
|
it_behaves_like 'a GitHub-ish import controller: GET realtime_changes'
|
|
|
|
end
|
2014-12-31 08:07:48 -05:00
|
|
|
end
|