Commit 36eca577 authored by Jarka Košanová's avatar Jarka Košanová

Check if jira project key has been provided

parent 345156aa
......@@ -22,8 +22,14 @@ module Projects
end
def import
response = ::JiraImport::StartImportService.new(current_user, @project, jira_import_params[:jira_project_key]).execute
flash[:notice] = response.message if response.message.present?
jira_project_key = jira_import_params[:jira_project_key]
if jira_project_key.present?
response = ::JiraImport::StartImportService.new(current_user, @project, jira_project_key).execute
flash[:notice] = response.message if response.message.present?
else
flash[:alert] = 'No jira project key has been provided.'
end
redirect_to project_import_jira_path(@project)
end
......
......@@ -93,18 +93,29 @@ describe Projects::Import::JiraController do
end
context 'post import' do
it 'creates import state' do
expect(project.import_state).to be_nil
context 'when jira project key is empty' do
it 'redirects back to show with an error' do
post :import, params: { namespace_id: project.namespace, project_id: project, jira_project_key: '' }
post :import, params: { namespace_id: project.namespace, project_id: project, jira_project_key: 'Test' }
expect(response).to redirect_to(project_import_jira_path(project))
expect(flash[:alert]).to eq('No jira project key has been provided.')
end
end
project.reload
context 'when everything is ok' do
it 'creates import state' do
expect(project.import_state).to be_nil
jira_project = project.import_data.data.dig('jira', 'projects').first
expect(project.import_type).to eq 'jira'
expect(project.import_state.status).to eq 'scheduled'
expect(jira_project['key']).to eq 'Test'
expect(response).to redirect_to(project_import_jira_path(project))
post :import, params: { namespace_id: project.namespace, project_id: project, jira_project_key: 'Test' }
project.reload
jira_project = project.import_data.data.dig('jira', 'projects').first
expect(project.import_type).to eq 'jira'
expect(project.import_state.status).to eq 'scheduled'
expect(jira_project['key']).to eq 'Test'
expect(response).to redirect_to(project_import_jira_path(project))
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