Commit 3fd3e8c1 authored by Brett Walker's avatar Brett Walker

Maps the standard sort values to Jira sort values

for use in JqlBuilderService
parent c75c0662
...@@ -14,6 +14,7 @@ module Projects ...@@ -14,6 +14,7 @@ module Projects
@jira_service = project.jira_service @jira_service = project.jira_service
@page = params[:page].presence || 1 @page = params[:page].presence || 1
@params = params @params = params
@params = @params.reverse_merge(map_sort_values(@params.delete(:sort)))
end end
def execute def execute
...@@ -44,6 +45,15 @@ module Projects ...@@ -44,6 +45,15 @@ module Projects
end end
end end
# rubocop: enable CodeReuse/ServiceClass # 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 end
end end
......
...@@ -75,6 +75,30 @@ RSpec.describe Projects::Integrations::Jira::IssuesFinder do ...@@ -75,6 +75,30 @@ RSpec.describe Projects::Integrations::Jira::IssuesFinder do
expect(service.total_count).to eq 375 expect(service.total_count).to eq 375
expect(issues.map(&:key)).to eq(%w[TEST-1 TEST-2]) expect(issues.map(&:key)).to eq(%w[TEST-1 TEST-2])
end 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 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