2020-03-13 08:09:22 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-03 14:08:28 -04:00
|
|
|
RSpec.describe Projects::Import::JiraController do
|
2020-04-30 02:10:03 -04:00
|
|
|
include JiraServiceHelper
|
|
|
|
|
2020-03-13 08:09:22 -04:00
|
|
|
let_it_be(:user) { create(:user) }
|
|
|
|
let_it_be(:project) { create(:project) }
|
2020-04-14 08:09:26 -04:00
|
|
|
let_it_be(:jira_project_key) { 'Test' }
|
2020-03-13 08:09:22 -04:00
|
|
|
|
2020-06-08 14:08:27 -04:00
|
|
|
def ensure_correct_config
|
|
|
|
sign_in(user)
|
|
|
|
project.add_maintainer(user)
|
2021-06-18 11:10:16 -04:00
|
|
|
stub_jira_integration_test
|
2020-06-08 14:08:27 -04:00
|
|
|
end
|
2020-03-13 08:09:22 -04:00
|
|
|
|
2020-06-08 14:08:27 -04:00
|
|
|
shared_examples 'redirect with error' do |error|
|
|
|
|
it 'redirects to project issues path' do
|
|
|
|
subject
|
|
|
|
|
|
|
|
expect(response).to redirect_to(project_issues_path(project))
|
2020-03-13 08:09:22 -04:00
|
|
|
end
|
|
|
|
|
2020-06-08 14:08:27 -04:00
|
|
|
it 'renders a correct error' do
|
|
|
|
subject
|
2020-03-13 08:09:22 -04:00
|
|
|
|
2020-06-08 14:08:27 -04:00
|
|
|
expect(flash[:notice]).to eq(error)
|
2020-03-13 08:09:22 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-06-08 14:08:27 -04:00
|
|
|
shared_examples 'template with no message' do
|
|
|
|
it 'does not set any message' do
|
|
|
|
subject
|
2020-03-13 08:09:22 -04:00
|
|
|
|
2020-06-08 14:08:27 -04:00
|
|
|
expect(flash).to be_empty
|
|
|
|
end
|
2020-04-14 08:09:26 -04:00
|
|
|
|
2020-06-08 14:08:27 -04:00
|
|
|
it 'renders show template' do
|
|
|
|
subject
|
2020-04-14 08:09:26 -04:00
|
|
|
|
2020-06-08 14:08:27 -04:00
|
|
|
expect(response).to render_template(template)
|
|
|
|
end
|
|
|
|
end
|
2020-04-14 08:09:26 -04:00
|
|
|
|
2020-06-08 14:08:27 -04:00
|
|
|
shared_examples 'users without permissions' do
|
|
|
|
context 'with anonymous user' do
|
|
|
|
it 'redirects to new user page' do
|
|
|
|
subject
|
2020-04-14 08:09:26 -04:00
|
|
|
|
2020-06-08 14:08:27 -04:00
|
|
|
expect(response).to redirect_to(new_user_session_path)
|
2020-05-26 08:08:22 -04:00
|
|
|
end
|
2020-06-08 14:08:27 -04:00
|
|
|
end
|
2020-04-14 08:09:26 -04:00
|
|
|
|
2020-06-08 14:08:27 -04:00
|
|
|
context 'when loged user is a developer' do
|
|
|
|
before do
|
2021-06-18 11:10:16 -04:00
|
|
|
create(:jira_integration, project: project)
|
|
|
|
stub_jira_integration_test
|
2020-04-14 08:09:26 -04:00
|
|
|
|
2020-06-08 14:08:27 -04:00
|
|
|
sign_in(user)
|
|
|
|
project.add_developer(user)
|
2020-05-26 08:08:22 -04:00
|
|
|
end
|
2020-04-14 08:09:26 -04:00
|
|
|
|
2020-06-08 14:08:27 -04:00
|
|
|
it_behaves_like 'redirect with error', 'You do not have permissions to run the import.'
|
|
|
|
end
|
|
|
|
end
|
2020-03-13 08:09:22 -04:00
|
|
|
|
2020-06-08 14:08:27 -04:00
|
|
|
describe 'GET #show' do
|
|
|
|
let(:template) { 'show' }
|
2020-03-13 08:09:22 -04:00
|
|
|
|
2020-06-08 14:08:27 -04:00
|
|
|
subject { get :show, params: { namespace_id: project.namespace, project_id: project } }
|
2020-04-06 20:09:33 -04:00
|
|
|
|
2020-06-08 14:08:27 -04:00
|
|
|
it_behaves_like 'users without permissions'
|
2020-04-06 20:09:33 -04:00
|
|
|
|
2021-06-18 11:10:16 -04:00
|
|
|
context 'jira integration configuration' do
|
2020-06-08 14:08:27 -04:00
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
project.add_maintainer(user)
|
2020-05-26 08:08:22 -04:00
|
|
|
end
|
2020-03-13 08:09:22 -04:00
|
|
|
|
2020-06-08 14:08:27 -04:00
|
|
|
context 'when Jira service is not enabled for the project' do
|
|
|
|
it 'does not query Jira service' do
|
2021-06-18 11:10:16 -04:00
|
|
|
expect(project).not_to receive(:jira_integration)
|
2020-03-13 08:09:22 -04:00
|
|
|
end
|
|
|
|
|
2020-06-08 14:08:27 -04:00
|
|
|
it_behaves_like 'template with no message'
|
|
|
|
end
|
2020-03-13 08:09:22 -04:00
|
|
|
|
2020-06-08 14:08:27 -04:00
|
|
|
context 'when Jira service is not configured correctly for the project' do
|
2021-06-18 11:10:16 -04:00
|
|
|
let_it_be(:jira_integration) { create(:jira_integration, project: project) }
|
2020-03-13 08:09:22 -04:00
|
|
|
|
2020-06-08 14:08:27 -04:00
|
|
|
before do
|
|
|
|
WebMock.stub_request(:get, 'https://jira.example.com/rest/api/2/serverInfo')
|
|
|
|
.to_raise(JIRA::HTTPError.new(double(message: 'Some failure.')))
|
2020-03-13 08:09:22 -04:00
|
|
|
end
|
2020-06-08 14:08:27 -04:00
|
|
|
|
|
|
|
it_behaves_like 'template with no message'
|
2020-03-13 08:09:22 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|