Commit 382ac490 authored by Jarka Košanová's avatar Jarka Košanová

Fix parsing Jira get labels response

parent 78b68298
......@@ -39,7 +39,7 @@ module Gitlab
def process_jira_page(start_at)
request = "/rest/api/2/label?maxResults=#{MAX_LABELS}&startAt=#{start_at}"
response = JSON.parse(client.get(request))
response = client.get(request)
return true if response['values'].blank?
return true unless response.key?('isLast')
......
......@@ -8,7 +8,9 @@ describe Gitlab::JiraImport::LabelsImporter do
let_it_be(:project) { create(:project, group: group) }
let_it_be(:jira_service) { create(:jira_service, project: project) }
subject { described_class.new(project).execute }
let(:importer) { described_class.new(project) }
subject { importer.execute }
before do
stub_feature_flags(jira_issue_import: true)
......@@ -35,14 +37,13 @@ describe Gitlab::JiraImport::LabelsImporter do
let(:jira_labels_1) { { "maxResults" => 2, "startAt" => 0, "total" => 3, "isLast" => false, "values" => %w(backend bug) } }
let(:jira_labels_2) { { "maxResults" => 2, "startAt" => 2, "total" => 3, "isLast" => true, "values" => %w(feature) } }
context 'when labels are returned from jira' do
before do
WebMock.stub_request(:get, 'https://jira.example.com/rest/api/2/label?maxResults=2&startAt=0')
.to_return(body: jira_labels_1.to_json )
WebMock.stub_request(:get, 'https://jira.example.com/rest/api/2/label?maxResults=2&startAt=2')
.to_return(body: jira_labels_2.to_json )
client = double
expect(importer).to receive(:client).twice.and_return(client)
allow(client).to receive(:get).twice.and_return(jira_labels_1, jira_labels_2)
end
context 'when labels are returned from jira' do
it 'caches import label' do
expect(Gitlab::Cache::Import::Caching.read(Gitlab::JiraImport.import_label_cache_key(project.id))).to be nil
......@@ -71,8 +72,9 @@ describe Gitlab::JiraImport::LabelsImporter do
let(:jira_labels) { { "maxResults" => 2, "startAt" => 0, "total" => 3, "values" => [] } }
before do
WebMock.stub_request(:get, 'https://jira.example.com/rest/api/2/label?maxResults=2&startAt=0')
.to_return(body: jira_labels.to_json )
client = double
expect(importer).to receive(:client).and_return(client)
allow(client).to receive(:get).and_return(jira_labels)
end
context 'when the labels field is empty' do
......
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