Commit f867d80c authored by Brett Walker's avatar Brett Walker

Add additional sort values for jira issue finder

that will get supplied by the frontend
parent 663a98f6
......@@ -48,8 +48,14 @@ module Projects
def map_sort_values(sort)
case sort
when 'created_date'
when 'created_date', 'created_desc'
{ sort: 'created', sort_direction: 'DESC' }
when 'created_asc'
{ sort: 'created', sort_direction: 'ASC' }
when 'updated_desc'
{ sort: 'updated', sort_direction: 'DESC' }
when 'updated_asc'
{ sort: 'updated', sort_direction: 'ASC' }
else
{ sort: ::Jira::JqlBuilderService::DEFAULT_SORT, sort_direction: ::Jira::JqlBuilderService::DEFAULT_SORT_DIRECTION }
end
......
......@@ -76,27 +76,45 @@ RSpec.describe Projects::Integrations::Jira::IssuesFinder do
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
context 'when sorting' do
shared_examples 'maps sort values' do
it do
expect(::Jira::JqlBuilderService).to receive(:new)
.with(jira_service.project_key, { sort: 'created', sort_direction: 'DESC' })
.with(jira_service.project_key, expected_sort_values)
.and_call_original
subject
end
end
context 'when sort by unknown_sort' do
let(:params) { { sort: 'unknown_sort' } }
it_behaves_like 'maps sort values' do
let(:params) { { sort: 'created_date' } }
let(:expected_sort_values) { { sort: 'created', sort_direction: 'DESC' } }
end
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
it_behaves_like 'maps sort values' do
let(:params) { { sort: 'created_desc' } }
let(:expected_sort_values) { { sort: 'created', sort_direction: 'DESC' } }
end
subject
it_behaves_like 'maps sort values' do
let(:params) { { sort: 'created_asc' } }
let(:expected_sort_values) { { sort: 'created', sort_direction: 'ASC' } }
end
it_behaves_like 'maps sort values' do
let(:params) { { sort: 'updated_desc' } }
let(:expected_sort_values) { { sort: 'updated', sort_direction: 'DESC' } }
end
it_behaves_like 'maps sort values' do
let(:params) { { sort: 'updated_asc' } }
let(:expected_sort_values) { { sort: 'updated', sort_direction: 'ASC' } }
end
it_behaves_like 'maps sort values' do
let(:params) { { sort: 'unknown_sort' } }
let(:expected_sort_values) { { sort: 'created', sort_direction: 'DESC' } }
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