Commit 1ff0baec authored by Michael Kozono's avatar Michael Kozono

Merge branch 'add-jira-projects-validation' into 'master'

Show error when Jira did not return any projects

See merge request gitlab-org/gitlab!28752
parents 7207dcb1 4cb27763
...@@ -9,7 +9,13 @@ module Projects ...@@ -9,7 +9,13 @@ module Projects
def show def show
unless @project.import_state&.in_progress? unless @project.import_state&.in_progress?
jira_client = @project.jira_service.client 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 end
flash[:notice] = _("Import %{status}") % { status: @project.import_state.status } if @project.import_state.present? && !@project.import_state.none? flash[:notice] = _("Import %{status}") % { status: @project.import_state.status } if @project.import_state.present? && !@project.import_state.none?
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
%h3.page-title.d-flex.align-items-center %h3.page-title.d-flex.align-items-center
= sprite_icon('issues', size: 16, css_class: 'mr-1') = sprite_icon('issues', size: 16, css_class: 'mr-1')
= _('Import in progress') = _('Import in progress')
- else - elsif @jira_projects.present?
%h3.page-title.d-flex.align-items-center %h3.page-title.d-flex.align-items-center
= sprite_icon('issues', size: 16, css_class: 'mr-1') = sprite_icon('issues', size: 16, css_class: 'mr-1')
= _('Import issues from Jira') = _('Import issues from Jira')
......
...@@ -66,13 +66,29 @@ describe Projects::Import::JiraController do ...@@ -66,13 +66,29 @@ describe Projects::Import::JiraController do
context 'when running jira import first time' do context 'when running jira import first time' do
context 'get show' do context 'get show' do
it 'renders show template' do before do
allow(JIRA::Resource::Project).to receive(:all).and_return([]) allow(JIRA::Resource::Project).to receive(:all).and_return(jira_projects)
expect(project.import_state).to be_nil expect(project.import_state).to be_nil
get :show, params: { namespace_id: project.namespace.to_param, project_id: project } 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
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