debian-mirror-gitlab/spec/requests/import/github_groups_controller_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

72 lines
2 KiB
Ruby
Raw Permalink Normal View History

2022-11-25 23:54:43 +05:30
# frozen_string_literal: true
require 'spec_helper'
2023-03-04 22:38:38 +05:30
RSpec.describe Import::GithubGroupsController, feature_category: :importers do
2022-11-25 23:54:43 +05:30
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
2023-07-09 08:55:56 +05:30
stub_application_setting(import_sources: ['github'])
2022-11-25 23:54:43 +05:30
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