diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-10-20 12:40:42 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-10-20 12:40:42 +0300 |
commit | ee664acb356f8123f4f6b00b73c1e1cf0866c7fb (patch) | |
tree | f8479f94a28f66654c6a4f6fb99bad6b4e86a40e /spec/requests/import | |
parent | 62f7d5c5b69180e82ae8196b7b429eeffc8e7b4f (diff) |
Add latest changes from gitlab-org/gitlab@15-5-stable-eev15.5.0-rc42
Diffstat (limited to 'spec/requests/import')
-rw-r--r-- | spec/requests/import/github_groups_controller_spec.rb | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/spec/requests/import/github_groups_controller_spec.rb b/spec/requests/import/github_groups_controller_spec.rb new file mode 100644 index 00000000000..544cbf88cd2 --- /dev/null +++ b/spec/requests/import/github_groups_controller_spec.rb @@ -0,0 +1,69 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Import::GithubGroupsController do + describe 'GET status' do + subject(:status) { get '/import/github_group/status', params: params, headers: headers } + + let_it_be(:user) { create(:user) } + let(:headers) { { 'Accept' => 'application/json' } } + let(:params) { {} } + + before do + login_as(user) + end + + context 'when OAuth config is missing' do + before do + allow(Gitlab::Auth::OAuth::Provider).to receive(:config_for).with('github').and_return(nil) + end + + it 'returns missing config error' do + status + + expect(json_response['errors']).to eq('Missing OAuth configuration for GitHub.') + end + end + + context 'when OAuth config present' do + let(:github_access_token) { 'asdasd12345' } + + before do + post '/import/github/personal_access_token', params: { personal_access_token: github_access_token } + end + + it 'fetches organizations' do + expect_next_instance_of(Octokit::Client) do |client| + expect(client).to receive(:organizations).and_return([].to_enum) + end + + status + end + + context 'with pagination' do + context 'when no page is specified' do + it 'requests first page' do + expect_next_instance_of(Octokit::Client) do |client| + expect(client).to receive(:organizations).with(nil, { page: 1, per_page: 25 }).and_return([].to_enum) + end + + status + end + end + + context 'when page is specified' do + let(:params) { { page: 2 } } + + it 'responds with organizations with specified page' do + expect_next_instance_of(Octokit::Client) do |client| + expect(client).to receive(:organizations).with(nil, { page: 2, per_page: 25 }).and_return([].to_enum) + end + + status + end + end + end + end + end +end |