Commit b541af36 authored by Mayra Cabrera's avatar Mayra Cabrera

Merge branch 'bw-jira-finder-sorts' into 'master'

Add additional sort values for Jira issue finder

See merge request gitlab-org/gitlab!36364
parents a18f949c f867d80c
...@@ -55,8 +55,14 @@ module Projects ...@@ -55,8 +55,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
it 'maps sort correctly' do
expect(::Jira::JqlBuilderService).to receive(:new) 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 .and_call_original
subject subject
end 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_date' } }
let(:expected_sort_values) { { sort: 'created', sort_direction: 'DESC' } }
end
it 'maps sort to default' do it_behaves_like 'maps sort values' do
expect(::Jira::JqlBuilderService).to receive(:new) let(:params) { { sort: 'created_desc' } }
.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_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 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