Commit b20122cb authored by Markus Koller's avatar Markus Koller

Merge branch '244354_fix-jira-issue-list-with-subpath' into 'master'

Fix subpath in jira issue list feature

See merge request gitlab-org/gitlab!49623
parents 29bccc1f 8ede8b05
......@@ -18,14 +18,19 @@ module Jira
request
end
# We have to add the context_path here because the Jira client is not taking it into account
def base_api_url
"/rest/api/#{api_version}"
"#{context_path}/rest/api/#{api_version}"
end
private
attr_reader :jira_service, :project
def context_path
client.options[:context_path].to_s
end
# override this method in the specific request class implementation if a differnt API version is required
def api_version
JIRA_API_VERSION
......
---
title: Fix Jira issue list API calls when Jira server runs relative to a context path
merge_request: 49623
author:
type: fixed
......@@ -3,6 +3,8 @@
require 'spec_helper'
RSpec.describe Jira::Requests::Issues::ListService do
include AfterNextHelpers
let(:jira_service) { create(:jira_service) }
let(:params) { {} }
......@@ -33,15 +35,18 @@ RSpec.describe Jira::Requests::Issues::ListService do
context 'with jira_service' do
context 'when validations and params are ok' do
let(:client) { double(options: { site: 'https://jira.example.com' }) }
let(:jira_service) { create(:jira_service, url: 'https://jira.example.com') }
let(:response_body) { '' }
let(:response_headers) { { 'content-type' => 'application/json' } }
let(:expected_url_pattern) { /.*jira.example.com\/rest\/api\/2\/search.*/ }
before do
expect(service).to receive(:client).at_least(:once).and_return(client)
stub_request(:get, expected_url_pattern).to_return(status: 200, body: response_body, headers: response_headers)
end
context 'when the request to Jira returns an error' do
before do
expect(client).to receive(:get).and_raise(Timeout::Error)
expect_next(JIRA::Client).to receive(:get).and_raise(Timeout::Error)
end
it 'returns an error response' do
......@@ -50,10 +55,17 @@ RSpec.describe Jira::Requests::Issues::ListService do
end
end
context 'when the request does not return any values' do
before do
expect(client).to receive(:get).and_return([])
context 'when jira runs on a subpath' do
let(:jira_service) { create(:jira_service, url: 'http://jira.example.com/jira') }
let(:expected_url_pattern) { /.*jira.example.com\/jira\/rest\/api\/2\/search.*/ }
it 'takes the subpath into account' do
expect(subject.success?).to be_truthy
end
end
context 'when the request does not return any values' do
let(:response_body) { [].to_json }
it 'returns a payload with no issues' do
payload = subject.payload
......@@ -65,14 +77,12 @@ RSpec.describe Jira::Requests::Issues::ListService do
end
context 'when the request returns values' do
before do
expect(client).to receive(:get).and_return(
let(:response_body) do
{
"total" => 375,
"startAt" => 0,
"issues" => [{ "key" => 'TST-1' }, { "key" => 'TST-2' }]
}
)
total: 375,
startAt: 0,
issues: [{ key: 'TST-1' }, { key: 'TST-2' }]
}.to_json
end
it 'returns a payload with jira issues' do
......@@ -88,7 +98,7 @@ RSpec.describe Jira::Requests::Issues::ListService do
let(:params) { { page: 3, per_page: 20 } }
it 'honors page and per_page' do
expect(client).to receive(:get).with(include('startAt=40&maxResults=20')).and_return([])
expect_next(JIRA::Client).to receive(:get).with(include('startAt=40&maxResults=20')).and_return([])
subject
end
......@@ -98,14 +108,14 @@ RSpec.describe Jira::Requests::Issues::ListService do
let(:params) { {} }
it 'uses the default options' do
expect(client).to receive(:get).with(include('startAt=0&maxResults=100'))
expect_next(JIRA::Client).to receive(:get).with(include('startAt=0&maxResults=100'))
subject
end
end
it 'requests for default fields' do
expect(client).to receive(:get).with(include("fields=#{described_class::DEFAULT_FIELDS}")).and_return([])
expect_next(JIRA::Client).to receive(:get).with(include("fields=#{described_class::DEFAULT_FIELDS}")).and_return([])
subject
end
......
......@@ -3,6 +3,8 @@
require 'spec_helper'
RSpec.describe Jira::Requests::Projects::ListService do
include AfterNextHelpers
let(:jira_service) { create(:jira_service) }
let(:params) { {} }
......@@ -33,15 +35,17 @@ RSpec.describe Jira::Requests::Projects::ListService do
context 'with jira_service' do
context 'when validations and params are ok' do
let(:client) { double(options: { site: 'https://jira.example.com' }) }
let(:response_headers) { { 'content-type' => 'application/json' } }
let(:response_body) { [].to_json }
let(:expected_url_pattern) { /.*jira.example.com\/rest\/api\/2\/project/ }
before do
expect(service).to receive(:client).at_least(:once).and_return(client)
stub_request(:get, expected_url_pattern).to_return(status: 200, body: response_body, headers: response_headers)
end
context 'when the request to Jira returns an error' do
before do
expect(client).to receive(:get).and_raise(Timeout::Error)
expect_next(JIRA::Client).to receive(:get).and_raise(Timeout::Error)
end
it 'returns an error response' do
......@@ -54,10 +58,17 @@ RSpec.describe Jira::Requests::Projects::ListService do
end
end
context 'when the request does not return any values' do
before do
expect(client).to receive(:get).and_return([])
context 'when jira runs on a subpath' do
let(:jira_service) { create(:jira_service, url: 'http://jira.example.com/jira') }
let(:expected_url_pattern) { /.*jira.example.com\/jira\/rest\/api\/2\/project/ }
it 'takes the subpath into account' do
expect(subject.success?).to be_truthy
end
end
context 'when the request does not return any values' do
let(:response_body) { [].to_json }
it 'returns a paylod with no projects returned' do
payload = subject.payload
......@@ -69,9 +80,7 @@ RSpec.describe Jira::Requests::Projects::ListService do
end
context 'when the request returns values' do
before do
expect(client).to receive(:get).and_return([{ 'key' => 'pr1', 'name' => 'First Project' }, { 'key' => 'pr2', 'name' => 'Second Project' }])
end
let(:response_body) { [{ 'key' => 'pr1', 'name' => 'First Project' }, { 'key' => 'pr2', 'name' => 'Second Project' }].to_json }
it 'returns a paylod with Jira projects' do
payload = subject.payload
......
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