summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJarka Kadlecova <jarka@gitlab.com>2017-07-26 09:57:56 +0200
committerJarka Kadlecova <jarka@gitlab.com>2017-07-27 07:51:36 +0200
commitaa2b3ff1e4c8bb725a96ed55906d142300ccf017 (patch)
tree5e834e50277c1c12a18e5dd1523eb8d93259d4de
parentf2da36f19661353cd1bd6788fbdf1a65e2d70f8d (diff)
downloadgitlab-ce-32483-jira-error.tar.gz
Display specific error message when JIRA test fails32483-jira-error
-rw-r--r--app/assets/javascripts/integrations/integration_settings_form.js2
-rw-r--r--app/models/project_services/jira_service.rb8
-rw-r--r--changelogs/unreleased/32483-jira-error.yml4
-rw-r--r--spec/features/projects/services/jira_service_spec.rb2
-rw-r--r--spec/javascripts/integrations/integration_settings_form_spec.js4
-rw-r--r--spec/models/project_services/jira_service_spec.rb31
6 files changed, 38 insertions, 13 deletions
diff --git a/app/assets/javascripts/integrations/integration_settings_form.js b/app/assets/javascripts/integrations/integration_settings_form.js
index ddd3a6aab99..cf1e6a14725 100644
--- a/app/assets/javascripts/integrations/integration_settings_form.js
+++ b/app/assets/javascripts/integrations/integration_settings_form.js
@@ -102,7 +102,7 @@ export default class IntegrationSettingsForm {
})
.done((res) => {
if (res.error) {
- new Flash(res.message, null, null, {
+ new Flash(`${res.message} ${res.service_response}`, null, null, {
title: 'Save anyway',
clickHandler: (e) => {
e.preventDefault();
diff --git a/app/models/project_services/jira_service.rb b/app/models/project_services/jira_service.rb
index 37f2c96a22f..2aa19443198 100644
--- a/app/models/project_services/jira_service.rb
+++ b/app/models/project_services/jira_service.rb
@@ -160,7 +160,10 @@ class JiraService < IssueTrackerService
def test(_)
result = test_settings
- { success: result.present?, result: result }
+ success = result.present?
+ result = @error if @error && !success
+
+ { success: success, result: result }
end
# JIRA does not need test data.
@@ -288,7 +291,8 @@ class JiraService < IssueTrackerService
yield
rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, Errno::ECONNREFUSED, URI::InvalidURIError, JIRA::HTTPError, OpenSSL::SSL::SSLError => e
- Rails.logger.info "#{self.class.name} Send message ERROR: #{client_url} - #{e.message}"
+ @error = e.message
+ Rails.logger.info "#{self.class.name} Send message ERROR: #{client_url} - #{@error}"
nil
end
diff --git a/changelogs/unreleased/32483-jira-error.yml b/changelogs/unreleased/32483-jira-error.yml
new file mode 100644
index 00000000000..1c530ca5e0f
--- /dev/null
+++ b/changelogs/unreleased/32483-jira-error.yml
@@ -0,0 +1,4 @@
+---
+title: Display specific error message when JIRA test fails
+merge_request:
+author:
diff --git a/spec/features/projects/services/jira_service_spec.rb b/spec/features/projects/services/jira_service_spec.rb
index b71eec0ecfd..28870261596 100644
--- a/spec/features/projects/services/jira_service_spec.rb
+++ b/spec/features/projects/services/jira_service_spec.rb
@@ -62,7 +62,7 @@ feature 'Setup Jira service', :feature, :js do
click_button('Test settings and save changes')
wait_for_requests
- expect(find('.flash-container-page')).to have_content 'Test failed.'
+ expect(find('.flash-container-page')).to have_content 'Test failed. message'
expect(find('.flash-container-page')).to have_content 'Save anyway'
find('.flash-alert .flash-action').trigger('click')
diff --git a/spec/javascripts/integrations/integration_settings_form_spec.js b/spec/javascripts/integrations/integration_settings_form_spec.js
index 45909d4e70e..3daeb91b1e2 100644
--- a/spec/javascripts/integrations/integration_settings_form_spec.js
+++ b/spec/javascripts/integrations/integration_settings_form_spec.js
@@ -135,10 +135,10 @@ describe('IntegrationSettingsForm', () => {
integrationSettingsForm.testSettings(formData);
- deferred.resolve({ error: true, message: errorMessage });
+ deferred.resolve({ error: true, message: errorMessage, service_response: 'some error' });
const $flashContainer = $('.flash-container');
- expect($flashContainer.find('.flash-text').text()).toEqual(errorMessage);
+ expect($flashContainer.find('.flash-text').text()).toEqual('Test failed. some error');
expect($flashContainer.find('.flash-action')).toBeDefined();
expect($flashContainer.find('.flash-action').text()).toEqual('Save anyway');
});
diff --git a/spec/models/project_services/jira_service_spec.rb b/spec/models/project_services/jira_service_spec.rb
index d7d09808a98..ded8e709c38 100644
--- a/spec/models/project_services/jira_service_spec.rb
+++ b/spec/models/project_services/jira_service_spec.rb
@@ -197,21 +197,38 @@ describe JiraService, models: true do
)
end
- def test_settings(api_url)
+ def test_settings(api_url = nil)
+ api_url ||= 'jira.example.com'
test_url = "http://#{api_url}/rest/api/2/serverInfo"
WebMock.stub_request(:get, test_url).with(basic_auth: %w(jira_username jira_password)).to_return(body: { url: 'http://url' }.to_json )
- jira_service.test_settings
+ jira_service.test(nil)
end
- it 'tries to get JIRA project with URL when API URL not set' do
- test_settings('jira.example.com')
+ context 'when the test succeeds' do
+ it 'tries to get JIRA project with URL when API URL not set' do
+ test_settings('jira.example.com')
+ end
+
+ it 'returns correct result' do
+ expect(test_settings).to eq( { success: true, result: { 'url' => 'http://url' } })
+ end
+
+ it 'tries to get JIRA project with API URL if set' do
+ jira_service.update(api_url: 'http://jira.api.com')
+ test_settings('jira.api.com')
+ end
end
- it 'tries to get JIRA project with API URL if set' do
- jira_service.update(api_url: 'http://jira.api.com')
- test_settings('jira.api.com')
+ context 'when the test fails' do
+ it 'returns result with the error' do
+ test_url = 'http://jira.example.com/rest/api/2/serverInfo'
+ WebMock.stub_request(:get, test_url).with(basic_auth: %w(jira_username jira_password))
+ .to_raise(JIRA::HTTPError.new(double(message: 'Some specific failure.')))
+
+ expect(jira_service.test(nil)).to eq( { success: false, result: 'Some specific failure.' })
+ end
end
end