diff options
Diffstat (limited to 'spec/requests/api/import_github_spec.rb')
-rw-r--r-- | spec/requests/api/import_github_spec.rb | 74 |
1 files changed, 28 insertions, 46 deletions
diff --git a/spec/requests/api/import_github_spec.rb b/spec/requests/api/import_github_spec.rb index 0d75bb94144..9b5ae72526c 100644 --- a/spec/requests/api/import_github_spec.rb +++ b/spec/requests/api/import_github_spec.rb @@ -174,72 +174,54 @@ RSpec.describe API::ImportGithub, feature_category: :importers do let_it_be(:user) { create(:user) } let(:params) { { personal_access_token: token } } - context 'when feature github_import_gists is enabled' do + context 'when gists import was started' do before do - stub_feature_flags(github_import_gists: true) + allow(Import::Github::GistsImportService) + .to receive(:new).with(user, client, access_params) + .and_return(double(execute: { status: :success })) end - context 'when gists import was started' do - before do - allow(Import::Github::GistsImportService) - .to receive(:new).with(user, client, access_params) - .and_return(double(execute: { status: :success })) - end - - it 'returns 202' do - post api('/import/github/gists', user), params: params + it 'returns 202' do + post api('/import/github/gists', user), params: params - expect(response).to have_gitlab_http_status(:accepted) - end + expect(response).to have_gitlab_http_status(:accepted) end + end - context 'when gists import is in progress' do - before do - allow(Import::Github::GistsImportService) - .to receive(:new).with(user, client, access_params) - .and_return(double(execute: { status: :error, message: 'Import already in progress', http_status: :unprocessable_entity })) - end - - it 'returns 422 error' do - post api('/import/github/gists', user), params: params - - expect(response).to have_gitlab_http_status(:unprocessable_entity) - expect(json_response['errors']).to eq('Import already in progress') - end + context 'when gists import is in progress' do + before do + allow(Import::Github::GistsImportService) + .to receive(:new).with(user, client, access_params) + .and_return(double(execute: { status: :error, message: 'Import already in progress', http_status: :unprocessable_entity })) end - context 'when unauthenticated user' do - it 'returns 403 error' do - post api('/import/github/gists'), params: params + it 'returns 422 error' do + post api('/import/github/gists', user), params: params - expect(response).to have_gitlab_http_status(:unauthorized) - end + expect(response).to have_gitlab_http_status(:unprocessable_entity) + expect(json_response['errors']).to eq('Import already in progress') end + end - context 'when rate limit reached' do - before do - allow(Import::Github::GistsImportService) - .to receive(:new).with(user, client, access_params) - .and_raise(Gitlab::GithubImport::RateLimitError) - end - - it 'returns 429 error' do - post api('/import/github/gists', user), params: params + context 'when unauthenticated user' do + it 'returns 403 error' do + post api('/import/github/gists'), params: params - expect(response).to have_gitlab_http_status(:too_many_requests) - end + expect(response).to have_gitlab_http_status(:unauthorized) end end - context 'when feature github_import_gists is disabled' do + context 'when rate limit reached' do before do - stub_feature_flags(github_import_gists: false) + allow(Import::Github::GistsImportService) + .to receive(:new).with(user, client, access_params) + .and_raise(Gitlab::GithubImport::RateLimitError) end - it 'returns 404 error' do + it 'returns 429 error' do post api('/import/github/gists', user), params: params - expect(response).to have_gitlab_http_status(:not_found) + expect(response).to have_gitlab_http_status(:too_many_requests) end end end |