Commit 4cb27763 authored by Jarka Košanová's avatar Jarka Košanová Committed by Michael Kozono

Show error when Jira did not return any projects

parent 5617531d
......@@ -9,7 +9,13 @@ module Projects
def show
unless @project.import_state&.in_progress?
jira_client = @project.jira_service.client
@jira_projects = jira_client.Project.all.map { |p| ["#{p.name} (#{p.key})", p.key] }
jira_projects = jira_client.Project.all
if jira_projects.present?
@jira_projects = jira_projects.map { |p| ["#{p.name} (#{p.key})", p.key] }
else
flash[:alert] = 'No projects have been returned from Jira. Please check your Jira configuration.'
end
end
flash[:notice] = _("Import %{status}") % { status: @project.import_state.status } if @project.import_state.present? && !@project.import_state.none?
......
......@@ -9,7 +9,7 @@
%h3.page-title.d-flex.align-items-center
= sprite_icon('issues', size: 16, css_class: 'mr-1')
= _('Import in progress')
- else
- elsif @jira_projects.present?
%h3.page-title.d-flex.align-items-center
= sprite_icon('issues', size: 16, css_class: 'mr-1')
= _('Import issues from Jira')
......
......@@ -66,13 +66,29 @@ describe Projects::Import::JiraController do
context 'when running jira import first time' do
context 'get show' do
it 'renders show template' do
allow(JIRA::Resource::Project).to receive(:all).and_return([])
before do
allow(JIRA::Resource::Project).to receive(:all).and_return(jira_projects)
expect(project.import_state).to be_nil
get :show, params: { namespace_id: project.namespace.to_param, project_id: project }
end
context 'when no projects have been retrieved from Jira' do
let(:jira_projects) { [] }
it 'render an error message' do
expect(flash[:alert]).to eq('No projects have been returned from Jira. Please check your Jira configuration.')
expect(response).to render_template(:show)
end
end
context 'when everything is ok' do
let(:jira_projects) { [double(name: 'FOO project', key: 'FOO')] }
expect(response).to render_template :show
it 'renders show template' do
expect(response).to render_template(:show)
end
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment