debian-mirror-gitlab/spec/controllers/import/manifest_controller_spec.rb

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

100 lines
2.9 KiB
Ruby
Raw Normal View History

2020-10-24 23:57:45 +05:30
# frozen_string_literal: true
require 'spec_helper'
2023-05-27 22:25:52 +05:30
RSpec.describe Import::ManifestController, :clean_gitlab_redis_shared_state, feature_category: :importers do
2020-10-24 23:57:45 +05:30
include ImportSpecHelper
let_it_be(:user) { create(:user) }
2022-10-11 01:57:18 +05:30
let_it_be(:group) { create(:group) }
2020-10-24 23:57:45 +05:30
before(:all) do
group.add_maintainer(user)
end
before do
2023-07-09 08:55:56 +05:30
stub_application_setting(import_sources: ['manifest'])
2020-10-24 23:57:45 +05:30
sign_in(user)
end
2021-01-03 14:25:43 +05:30
describe 'POST upload' do
context 'with a valid manifest' do
it 'saves the manifest and redirects to the status page', :aggregate_failures do
post :upload, params: {
group_id: group.id,
manifest: fixture_file_upload('spec/fixtures/aosp_manifest.xml')
}
metadata = Gitlab::ManifestImport::Metadata.new(user)
expect(metadata.group_id).to eq(group.id)
expect(metadata.repositories.size).to eq(660)
expect(metadata.repositories.first).to include(name: 'platform/build', path: 'build/make')
expect(response).to redirect_to(status_import_manifest_path)
end
end
context 'with an invalid manifest' do
it 'displays an error' do
post :upload, params: {
group_id: group.id,
manifest: fixture_file_upload('spec/fixtures/invalid_manifest.xml')
}
expect(assigns(:errors)).to be_present
end
end
2023-05-27 22:25:52 +05:30
context 'when the user cannot import projects in the group' do
2021-01-03 14:25:43 +05:30
it 'displays an error' do
sign_in(create(:user))
post :upload, params: {
group_id: group.id,
manifest: fixture_file_upload('spec/fixtures/aosp_manifest.xml')
}
expect(assigns(:errors)).to be_present
end
end
2020-10-24 23:57:45 +05:30
end
describe 'GET status' do
2021-01-03 14:25:43 +05:30
let(:repo1) { { id: 'test1', url: 'http://demo.host/test1' } }
let(:repo2) { { id: 'test2', url: 'http://demo.host/test2' } }
2020-10-24 23:57:45 +05:30
let(:repos) { [repo1, repo2] }
2021-01-03 14:25:43 +05:30
shared_examples 'status action' do
it "returns variables for json request" do
project = create(:project, import_type: 'manifest', creator_id: user.id)
2020-10-24 23:57:45 +05:30
2021-01-03 14:25:43 +05:30
get :status, format: :json
2020-10-24 23:57:45 +05:30
2021-01-03 14:25:43 +05:30
expect(response).to have_gitlab_http_status(:ok)
expect(json_response.dig("imported_projects", 0, "id")).to eq(project.id)
expect(json_response.dig("provider_repos", 0, "id")).to eq(repo1[:id])
expect(json_response.dig("provider_repos", 1, "id")).to eq(repo2[:id])
end
2020-10-24 23:57:45 +05:30
end
2021-01-03 14:25:43 +05:30
context 'when the data is stored via Gitlab::ManifestImport::Metadata' do
before do
Gitlab::ManifestImport::Metadata.new(user).save(repos, group.id)
end
include_examples 'status action'
end
2020-10-24 23:57:45 +05:30
2021-01-03 14:25:43 +05:30
context 'when the data is stored in the user session' do
before do
session[:manifest_import_repositories] = repos
session[:manifest_import_group_id] = group.id
end
2020-10-24 23:57:45 +05:30
2021-01-03 14:25:43 +05:30
include_examples 'status action'
2020-10-24 23:57:45 +05:30
end
end
end