Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/requests/api/project_export_spec.rb')
-rw-r--r--spec/requests/api/project_export_spec.rb124
1 files changed, 104 insertions, 20 deletions
diff --git a/spec/requests/api/project_export_spec.rb b/spec/requests/api/project_export_spec.rb
index 434936c0ee7..3603a71151e 100644
--- a/spec/requests/api/project_export_spec.rb
+++ b/spec/requests/api/project_export_spec.rb
@@ -567,54 +567,138 @@ RSpec.describe API::ProjectExport, :aggregate_failures, :clean_gitlab_redis_cach
expect(response).to have_gitlab_http_status(:error)
end
end
+
+ context 'when request is to export in batches' do
+ it 'accepts the request' do
+ expect(BulkImports::ExportService)
+ .to receive(:new)
+ .with(portable: project, user: user, batched: true)
+ .and_call_original
+
+ post api(path, user), params: { batched: true }
+
+ expect(response).to have_gitlab_http_status(:accepted)
+ end
+ end
end
describe 'GET /projects/:id/export_relations/download' do
- let_it_be(:export) { create(:bulk_import_export, project: project, relation: 'labels') }
- let_it_be(:upload) { create(:bulk_import_export_upload, export: export) }
+ context 'when export request is not batched' do
+ let_it_be(:export) { create(:bulk_import_export, project: project, relation: 'labels') }
+ let_it_be(:upload) { create(:bulk_import_export_upload, export: export) }
+
+ context 'when export file exists' do
+ it 'downloads exported project relation archive' do
+ upload.update!(export_file: fixture_file_upload('spec/fixtures/bulk_imports/gz/labels.ndjson.gz'))
+
+ get api(download_path, user)
+
+ expect(response).to have_gitlab_http_status(:ok)
+ expect(response.header['Content-Disposition']).to eq("attachment; filename=\"labels.ndjson.gz\"; filename*=UTF-8''labels.ndjson.gz")
+ end
+ end
+
+ context 'when relation is not portable' do
+ let(:relation) { ::BulkImports::FileTransfer::ProjectConfig.new(project).skipped_relations.first }
+
+ it_behaves_like '400 response' do
+ subject(:request) { get api(download_path, user) }
+ end
+ end
+
+ context 'when export file does not exist' do
+ it 'returns 404' do
+ allow(upload).to receive(:export_file).and_return(nil)
+
+ get api(download_path, user)
+
+ expect(response).to have_gitlab_http_status(:not_found)
+ end
+ end
+
+ context 'when export is batched' do
+ let(:relation) { 'issues' }
+
+ let_it_be(:export) { create(:bulk_import_export, :batched, project: project, relation: 'issues') }
- context 'when export file exists' do
- it 'downloads exported project relation archive' do
+ it 'returns 400' do
+ export.update!(batched: true)
+
+ get api(download_path, user)
+
+ expect(response).to have_gitlab_http_status(:bad_request)
+ expect(json_response['message']).to eq('Export is batched')
+ end
+ end
+ end
+
+ context 'when export request is batched' do
+ let(:export) { create(:bulk_import_export, :batched, project: project, relation: 'labels') }
+ let(:upload) { create(:bulk_import_export_upload) }
+ let!(:batch) { create(:bulk_import_export_batch, export: export, upload: upload) }
+
+ it 'downloads exported batch' do
upload.update!(export_file: fixture_file_upload('spec/fixtures/bulk_imports/gz/labels.ndjson.gz'))
- get api(download_path, user)
+ get api(download_path, user), params: { batched: true, batch_number: batch.batch_number }
expect(response).to have_gitlab_http_status(:ok)
expect(response.header['Content-Disposition']).to eq("attachment; filename=\"labels.ndjson.gz\"; filename*=UTF-8''labels.ndjson.gz")
end
- end
- context 'when relation is not portable' do
- let(:relation) { ::BulkImports::FileTransfer::ProjectConfig.new(project).skipped_relations.first }
+ context 'when request is to download not batched export' do
+ it 'returns 400' do
+ get api(download_path, user)
- it_behaves_like '400 response' do
- subject(:request) { get api(download_path, user) }
+ expect(response).to have_gitlab_http_status(:bad_request)
+ expect(json_response['message']).to eq('Export is batched')
+ end
end
- end
- context 'when export file does not exist' do
- it 'returns 404' do
- allow(upload).to receive(:export_file).and_return(nil)
+ context 'when batch cannot be found' do
+ it 'returns 404' do
+ get api(download_path, user), params: { batched: true, batch_number: 0 }
- get api(download_path, user)
+ expect(response).to have_gitlab_http_status(:not_found)
+ expect(json_response['message']).to eq('Batch not found')
+ end
+ end
+
+ context 'when batch file cannot be found' do
+ it 'returns 404' do
+ batch.upload.destroy!
+
+ get api(download_path, user), params: { batched: true, batch_number: batch.batch_number }
- expect(response).to have_gitlab_http_status(:not_found)
+ expect(response).to have_gitlab_http_status(:not_found)
+ expect(json_response['message']).to eq('Batch file not found')
+ end
end
end
end
describe 'GET /projects/:id/export_relations/status' do
- it 'returns a list of relation export statuses' do
- create(:bulk_import_export, :started, project: project, relation: 'labels')
- create(:bulk_import_export, :finished, project: project, relation: 'milestones')
- create(:bulk_import_export, :failed, project: project, relation: 'project_badges')
+ let_it_be(:started_export) { create(:bulk_import_export, :started, project: project, relation: 'labels') }
+ let_it_be(:finished_export) { create(:bulk_import_export, :finished, project: project, relation: 'milestones') }
+ let_it_be(:failed_export) { create(:bulk_import_export, :failed, project: project, relation: 'project_badges') }
+ it 'returns a list of relation export statuses' do
get api(status_path, user)
expect(response).to have_gitlab_http_status(:ok)
expect(json_response.pluck('relation')).to contain_exactly('labels', 'milestones', 'project_badges')
expect(json_response.pluck('status')).to contain_exactly(-1, 0, 1)
end
+
+ context 'when relation is specified' do
+ it 'return a single relation export status' do
+ get api(status_path, user), params: { relation: 'labels' }
+
+ expect(response).to have_gitlab_http_status(:ok)
+ expect(json_response['relation']).to eq('labels')
+ expect(json_response['status']).to eq(0)
+ end
+ end
end
context 'with bulk_import is disabled' do