Commit e932b180 authored by Gabriel Mazetto's avatar Gabriel Mazetto

Merge branch '276893-add-fetching-available-issue-types-to-test' into 'master'

Fetch available issue types in Jira integration for vulnerabilities

See merge request gitlab-org/gitlab!47046
parents ce02c24c a9f9d1b1
......@@ -70,7 +70,7 @@ class Projects::ServicesController < Projects::ApplicationController
return { error: true, message: s_('Integrations|Connection failed. Please check your settings.'), service_response: result[:message].to_s, test_failed: true }
end
{}
result[:data].presence || {}
rescue Gitlab::HTTP::BlockedUrlError => e
{ error: true, message: s_('Integrations|Connection failed. Please check your settings.'), service_response: e.message, test_failed: true }
end
......
......@@ -7,5 +7,22 @@ module EE
prepended do
validates :project_key, presence: true, if: :issues_enabled
end
def issue_types
client
.Issuetype
.all
.reject { |issue_type| issue_type.subtask }
.map { |issue_type| { id: issue_type.id, name: issue_type.name, description: issue_type.description } }
end
def test(_)
super.then do |result|
next result unless result[:success]
next result unless project.try(:jira_vulnerabilities_integration_enabled?)
result.merge(data: { issuetypes: issue_types })
end
end
end
end
---
title: Fetch available issue types in Jira integration for vulnerabilities
merge_request: 47046
author:
type: added
......@@ -13,4 +13,56 @@ RSpec.describe JiraService do
expect(jira_service).to be_invalid
end
end
describe '#issue_types' do
subject(:issue_types) { jira_service.issue_types }
let(:client) { double(Issuetype: issue_type_jira_resource) }
let(:issue_type_jira_resource) { double(all: jira_issue_types) }
let(:jira_issue_types) { [double(subtask: true), double(subtask: false, id: '10001', name: 'Bug', description: 'Jira Bug')] }
before do
allow(jira_service.project).to receive(:jira_vulnerabilities_integration_enabled?).and_return(true)
allow(jira_service).to receive(:client).and_return(client)
end
it 'loads all issue types without subtask issue types' do
expect(issue_types).to eq([{ id: '10001', name: 'Bug', description: 'Jira Bug' }])
end
end
describe '#test' do
subject(:jira_test) { jira_service.test(nil) }
context 'when server is not responding' do
before do
allow(jira_service).to receive(:server_info).and_return(nil)
end
it { is_expected.to eq(success: false, result: nil) }
end
context 'when server is responding' do
before do
allow(jira_service).to receive(:server_info).and_return({ jira: true })
end
context 'when vulnerabilities integration is not enabled' do
before do
allow(jira_service.project).to receive(:jira_vulnerabilities_integration_enabled?).and_return(false)
end
it { is_expected.to eq(success: true, result: { jira: true }) }
end
context 'when vulnerabilities integration is enabled' do
before do
allow(jira_service.project).to receive(:jira_vulnerabilities_integration_enabled?).and_return(true)
allow(jira_service).to receive(:issue_types).and_return([{ id: '10001', name: 'Bug', description: 'Jira Bug' }])
end
it { is_expected.to eq(success: true, result: { jira: true }, data: { issuetypes: [{ id: '10001', name: 'Bug', description: 'Jira Bug' }] }) }
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