diff options
Diffstat (limited to 'spec/models/project_services/jira_service_spec.rb')
-rw-r--r-- | spec/models/project_services/jira_service_spec.rb | 41 |
1 files changed, 29 insertions, 12 deletions
diff --git a/spec/models/project_services/jira_service_spec.rb b/spec/models/project_services/jira_service_spec.rb index d7d09808a98..8f34b44930e 100644 --- a/spec/models/project_services/jira_service_spec.rb +++ b/spec/models/project_services/jira_service_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe JiraService, models: true do +describe JiraService do include Gitlab::Routing describe "Associations" do @@ -78,7 +78,7 @@ describe JiraService, models: true do let(:merge_request) { create(:merge_request) } before do - @jira_service = JiraService.new + @jira_service = described_class.new allow(@jira_service).to receive_messages( project_id: project.id, project: project, @@ -167,7 +167,7 @@ describe JiraService, models: true do stub_config_setting(relative_url_root: '/gitlab') stub_config_setting(url: Settings.send(:build_gitlab_url)) - allow(JiraService).to receive(:default_url_options) do + allow(described_class).to receive(:default_url_options) do { script_name: '/gitlab' } end @@ -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 @@ -220,7 +237,7 @@ describe JiraService, models: true do context "when a password was previously set" do before do - @jira_service = JiraService.create!( + @jira_service = described_class.create!( project: project, properties: { url: 'http://jira.example.com/web', @@ -301,7 +318,7 @@ describe JiraService, models: true do context 'when no password was previously set' do before do - @jira_service = JiraService.create( + @jira_service = described_class.create( project: project, properties: { url: 'http://jira.example.com/rest/api/2', |