diff --git a/ee/app/controllers/projects/integrations/zentao/issues_controller.rb b/ee/app/controllers/projects/integrations/zentao/issues_controller.rb index c751652f7f50bb0a278f3d2dd1bfef1c62366c3d..dc1927eeb8646382b603468091cac1431247cb8f 100644 --- a/ee/app/controllers/projects/integrations/zentao/issues_controller.rb +++ b/ee/app/controllers/projects/integrations/zentao/issues_controller.rb @@ -59,8 +59,15 @@ def check_feature_enabled! def render_error(exception) log_exception(exception) - render json: { errors: [s_('ZentaoIntegration|An error occurred while requesting data from the ZenTao service.')] }, - status: :bad_request + respond_to do |format| + format.html do + render action_name + end + format.json do + render json: { errors: [s_('ZentaoIntegration|An error occurred while requesting data from the ZenTao service.')] }, + status: :bad_request + end + end end end end diff --git a/ee/app/views/projects/integrations/zentao/issues/show.html.haml b/ee/app/views/projects/integrations/zentao/issues/show.html.haml index 7cf23a924bbbe87b1b6d45df13c2cea5d9351dec..3882ff7055c7741e2c7f52dfef1b62d2be5672e6 100644 --- a/ee/app/views/projects/integrations/zentao/issues/show.html.haml +++ b/ee/app/views/projects/integrations/zentao/issues/show.html.haml @@ -1,5 +1,6 @@ - add_to_breadcrumbs s_('ZentaoIntegration|ZenTao issues'), project_integrations_zentao_issues_path(@project) -- breadcrumb_title zentao_issue_breadcrumb_link(@issue_json) -- page_title html_escape(@issue_json[:title]) +- if @issue_json.present? + - breadcrumb_title zentao_issue_breadcrumb_link(@issue_json) + - page_title html_escape(@issue_json[:title]) .js-zentao-issues-show-app{ data: zentao_issues_show_data } diff --git a/ee/spec/controllers/projects/integrations/zentao/issues_controller_spec.rb b/ee/spec/controllers/projects/integrations/zentao/issues_controller_spec.rb index f60bd94ee8c15332f31789c9c0690be64922eb81..95042e77ed6d4fb1764e04b813d1d0c130631f4b 100644 --- a/ee/spec/controllers/projects/integrations/zentao/issues_controller_spec.rb +++ b/ee/spec/controllers/projects/integrations/zentao/issues_controller_spec.rb @@ -94,18 +94,42 @@ end end - it 'renders `show` template' do - get :show, params: { namespace_id: project.namespace, project_id: project, id: 'story-1' } + context 'with valid request' do + it 'renders `show` template successfully' do + get :show, params: { namespace_id: project.namespace, project_id: project, id: 'story-1' } + + expect(assigns(:issue_json)).to eq(issue_json) + expect(response).to have_gitlab_http_status(:ok) + expect(response).to render_template(:show) + end - expect(assigns(:issue_json)).to eq(issue_json) - expect(response).to have_gitlab_http_status(:ok) - expect(response).to render_template(:show) + it 'returns JSON response successfully' do + get :show, params: { namespace_id: project.namespace, project_id: project, id: 'story-1', format: :json } + + expect(json_response).to eq(issue_json) + end end - it 'returns JSON response' do - get :show, params: { namespace_id: project.namespace, project_id: project, id: 'story-1', format: :json } + context 'with bad request' do + before do + allow_next_instance_of(Integrations::ZentaoSerializers::IssueDetailSerializer) do |serializer| + allow(serializer).to receive(:represent).and_raise(::Gitlab::Zentao::Client::Error) + end + end + it 'renders `show` template successfully' do + get :show, params: { namespace_id: project.namespace, project_id: project, id: 'story-1' } + + expect(assigns(:issue_json)).to be_nil + expect(response).to have_gitlab_http_status(:ok) + expect(response).to render_template(:show) + end + + it 'returns JSON response with error messages' do + get :show, params: { namespace_id: project.namespace, project_id: project, id: 'story-1', format: :json } - expect(json_response).to eq(issue_json) + expect(response).to have_gitlab_http_status(:bad_request) + expect(json_response['errors']).to be_present + end end context 'when the JSON fetched from ZenTao contains HTML' do