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/group_export_spec.rb')
-rw-r--r--spec/requests/api/group_export_spec.rb120
1 files changed, 103 insertions, 17 deletions
diff --git a/spec/requests/api/group_export_spec.rb b/spec/requests/api/group_export_spec.rb
index 9dd5fe6f7c4..b4add2494b0 100644
--- a/spec/requests/api/group_export_spec.rb
+++ b/spec/requests/api/group_export_spec.rb
@@ -168,8 +168,9 @@ RSpec.describe API::GroupExport, feature_category: :importers do
end
describe 'relations export' do
+ let(:relation) { 'labels' }
let(:path) { "/groups/#{group.id}/export_relations" }
- let(:download_path) { "/groups/#{group.id}/export_relations/download?relation=labels" }
+ let(:download_path) { "/groups/#{group.id}/export_relations/download?relation=#{relation}" }
let(:status_path) { "/groups/#{group.id}/export_relations/status" }
before do
@@ -196,46 +197,131 @@ RSpec.describe API::GroupExport, feature_category: :importers do
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: group, 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 /groups/:id/export_relations/download' do
- let(:export) { create(:bulk_import_export, group: group, relation: 'labels') }
- let(:upload) { create(:bulk_import_export_upload, export: export) }
+ context 'when export request is not batched' do
+ let(:export) { create(:bulk_import_export, group: group, relation: 'labels') }
+ let(:upload) { create(:bulk_import_export_upload, export: export) }
+
+ context 'when export file exists' do
+ it 'downloads exported group 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)
+ end
+ end
+
+ context 'when export_file.file does not exist' do
+ it 'returns 404' do
+ allow(export).to receive(:upload).and_return(nil)
+
+ get api(download_path, user)
+
+ expect(response).to have_gitlab_http_status(:not_found)
+ expect(json_response['message']).to eq('Export file not found')
+ end
+ end
+
+ context 'when export is batched' do
+ let(:relation) { 'milestones' }
+
+ let_it_be(:export) { create(:bulk_import_export, :batched, group: group, relation: 'milestones') }
+
+ 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 file exists' do
- it 'downloads exported group archive' do
+ context 'when export request is batched' do
+ let(:export) { create(:bulk_import_export, :batched, group: group, 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 export_file.file does not exist' do
- it 'returns 404' do
- allow(export).to receive(:upload).and_return(nil)
+ context 'when request is to download not batched export' do
+ it 'returns 400' do
+ get api(download_path, user)
- 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
- expect(response).to have_gitlab_http_status(:not_found)
- expect(json_response['message']).to eq('404 Not found')
+ context 'when batch cannot be found' do
+ it 'returns 404' do
+ get api(download_path, user), params: { batched: true, batch_number: 0 }
+
+ 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(json_response['message']).to eq('Batch file not found')
+ end
end
end
end
describe 'GET /groups/:id/export_relations/status' do
- it 'returns a list of relation export statuses' do
- create(:bulk_import_export, :started, group: group, relation: 'labels')
- create(:bulk_import_export, :finished, group: group, relation: 'milestones')
- create(:bulk_import_export, :failed, group: group, relation: 'badges')
+ let_it_be(:started_export) { create(:bulk_import_export, :started, group: group, relation: 'labels') }
+ let_it_be(:finished_export) { create(:bulk_import_export, :finished, group: group, relation: 'milestones') }
+ let_it_be(:failed_export) { create(:bulk_import_export, :failed, group: group, relation: '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', '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 'when bulk import is disabled' do