debian-mirror-gitlab/spec/controllers/import/github_controller_spec.rb

82 lines
2.4 KiB
Ruby
Raw Normal View History

2019-07-31 22:56:46 +05:30
# frozen_string_literal: true
2015-04-26 12:48:37 +05:30
require 'spec_helper'
describe Import::GithubController do
2015-09-11 14:41:01 +05:30
include ImportSpecHelper
2017-08-17 22:00:37 +05:30
let(:provider) { :github }
2015-09-25 12:07:36 +05:30
2017-08-17 22:00:37 +05:30
include_context 'a GitHub-ish import controller'
2015-04-26 12:48:37 +05:30
2016-08-24 12:49:21 +05:30
describe "GET new" do
2017-08-17 22:00:37 +05:30
it_behaves_like 'a GitHub-ish import controller: GET new'
2016-08-24 12:49:21 +05:30
2017-08-17 22:00:37 +05:30
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-02-02 18:00:53 +05:30
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-08-24 12:49:21 +05:30
get :new
2019-02-02 18:00:53 +05:30
2020-03-09 13:42:32 +05:30
expect(response).to have_gitlab_http_status(:found)
2016-08-24 12:49:21 +05:30
end
2019-02-15 15:39:39 +05:30
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
2020-03-09 13:42:32 +05:30
expect(response).to have_gitlab_http_status(:ok)
2019-02-15 15:39:39 +05:30
end
2019-10-12 21:52:04 +05:30
context 'when importing a CI/CD project' do
it 'always prompts for an access token' do
allow(controller).to receive(:github_import_configured?).and_return(true)
get :new, params: { ci_cd_only: true }
expect(response).to render_template(:new)
end
end
2016-08-24 12:49:21 +05:30
end
2015-04-26 12:48:37 +05:30
describe "GET callback" do
it "updates access token" do
token = "asdasd12345"
2018-03-17 18:26:18 +05:30
allow_any_instance_of(Gitlab::LegacyGithubImport::Client)
2017-09-10 17:25:29 +05:30
.to receive(:get_token).and_return(token)
2018-03-17 18:26:18 +05:30
allow_any_instance_of(Gitlab::LegacyGithubImport::Client)
2017-09-10 17:25:29 +05:30
.to receive(:github_options).and_return({})
2015-09-11 14:41:01 +05:30
stub_omniauth_provider('github')
2015-04-26 12:48:37 +05:30
get :callback
2015-09-25 12:07:36 +05:30
expect(session[:github_access_token]).to eq(token)
2015-04-26 12:48:37 +05:30
expect(controller).to redirect_to(status_import_github_url)
end
end
2016-08-24 12:49:21 +05:30
describe "POST personal_access_token" do
2017-08-17 22:00:37 +05:30
it_behaves_like 'a GitHub-ish import controller: POST personal_access_token'
2016-08-24 12:49:21 +05:30
end
2015-04-26 12:48:37 +05:30
describe "GET status" do
2017-08-17 22:00:37 +05:30
it_behaves_like 'a GitHub-ish import controller: GET status'
2015-04-26 12:48:37 +05:30
end
describe "POST create" do
2017-08-17 22:00:37 +05:30
it_behaves_like 'a GitHub-ish import controller: POST create'
2020-03-09 13:42:32 +05:30
it_behaves_like 'project import rate limiter'
2015-04-26 12:48:37 +05:30
end
2019-07-07 11:18:12 +05:30
describe "GET realtime_changes" do
it_behaves_like 'a GitHub-ish import controller: GET realtime_changes'
end
2015-04-26 12:48:37 +05:30
end