Commit de5c202f authored by Sean McGivern's avatar Sean McGivern

Merge branch 'bw-map-jira-sorting' into 'master'

Maps the standard sort values to Jira sort values

See merge request gitlab-org/gitlab!36149
parents f5bece63 3fd3e8c1
......@@ -14,6 +14,7 @@ module Projects
@jira_service = project.jira_service
@page = params[:page].presence || 1
@params = params
@params = @params.reverse_merge(map_sort_values(@params.delete(:sort)))
end
def execute
......@@ -44,6 +45,15 @@ module Projects
end
end
# rubocop: enable CodeReuse/ServiceClass
def map_sort_values(sort)
case sort
when 'created_date'
{ sort: 'created', sort_direction: 'DESC' }
else
{ sort: ::Jira::JqlBuilderService::DEFAULT_SORT, sort_direction: ::Jira::JqlBuilderService::DEFAULT_SORT_DIRECTION }
end
end
end
end
end
......
......@@ -75,6 +75,30 @@ RSpec.describe Projects::Integrations::Jira::IssuesFinder do
expect(service.total_count).to eq 375
expect(issues.map(&:key)).to eq(%w[TEST-1 TEST-2])
end
context 'when sort by created_date' do
let(:params) { { sort: 'created_date' } }
it 'maps sort correctly' do
expect(::Jira::JqlBuilderService).to receive(:new)
.with(jira_service.project_key, { sort: 'created', sort_direction: 'DESC' })
.and_call_original
subject
end
end
context 'when sort by unknown_sort' do
let(:params) { { sort: 'unknown_sort' } }
it 'maps sort to default' do
expect(::Jira::JqlBuilderService).to receive(:new)
.with(jira_service.project_key, { sort: 'created', sort_direction: 'DESC' })
.and_call_original
subject
end
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