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