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

95 lines
2.6 KiB
Ruby
Raw Normal View History

2019-09-04 21:01:54 +05:30
# frozen_string_literal: true
require 'spec_helper'
describe Import::PhabricatorController do
let(:current_user) { create(:user) }
before do
sign_in current_user
end
describe 'GET #new' do
subject { get :new }
context 'when the import source is not available' do
before do
stub_feature_flags(phabricator_import: true)
stub_application_setting(import_sources: [])
end
2020-03-13 15:44:24 +05:30
it { is_expected.to have_gitlab_http_status(:not_found) }
2019-09-04 21:01:54 +05:30
end
context 'when the feature is disabled' do
before do
stub_feature_flags(phabricator_import: false)
stub_application_setting(import_sources: ['phabricator'])
end
2020-03-13 15:44:24 +05:30
it { is_expected.to have_gitlab_http_status(:not_found) }
2019-09-04 21:01:54 +05:30
end
context 'when the import is available' do
before do
stub_feature_flags(phabricator_import: true)
stub_application_setting(import_sources: ['phabricator'])
end
2020-03-13 15:44:24 +05:30
it { is_expected.to have_gitlab_http_status(:ok) }
2019-09-04 21:01:54 +05:30
end
end
describe 'POST #create' do
subject(:post_create) { post :create, params: params }
context 'with valid params' do
let(:params) do
{ path: 'phab-import',
name: 'Phab import',
phabricator_server_url: 'https://phabricator.example.com',
api_token: 'hazaah',
namespace_id: current_user.namespace_id }
end
2019-12-26 22:10:19 +05:30
it 'creates a project to import', :sidekiq_might_not_need_inline do
2019-09-04 21:01:54 +05:30
expect_next_instance_of(Gitlab::PhabricatorImport::Importer) do |importer|
expect(importer).to receive(:execute)
end
expect { post_create }.to change { current_user.namespace.projects.reload.size }.from(0).to(1)
expect(current_user.namespace.projects.last).to be_import
end
end
context 'when an import param is missing' do
let(:params) do
{ path: 'phab-import',
name: 'Phab import',
phabricator_server_url: nil,
api_token: 'hazaah',
namespace_id: current_user.namespace_id }
end
it 'does not create the project' do
expect { post_create }.not_to change { current_user.namespace.projects.reload.size }
end
end
context 'when a project param is missing' do
let(:params) do
{ phabricator_server_url: 'https://phabricator.example.com',
api_token: 'hazaah',
namespace_id: current_user.namespace_id }
end
it 'does not create the project' do
expect { post_create }.not_to change { current_user.namespace.projects.reload.size }
end
end
2020-03-13 15:44:24 +05:30
it_behaves_like 'project import rate limiter'
2019-09-04 21:01:54 +05:30
end
end