debian-mirror-gitlab/spec/controllers/projects/import/jira_controller_spec.rb

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

102 lines
2.4 KiB
Ruby
Raw Normal View History

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