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
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' } }
context 'when sorting' do
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
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_date' } }
let(:expected_sort_values) { { sort: 'created', sort_direction: 'DESC' } }
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
context 'when sort by unknown_sort' do
let(:params) { { sort: 'unknown_sort' } }
it_behaves_like 'maps sort values' do
let(:params) { { sort: 'created_asc' } }
let(:expected_sort_values) { { sort: 'created', sort_direction: 'ASC' } }
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: 'updated_desc' } }
let(:expected_sort_values) { { sort: 'updated', sort_direction: 'DESC' } }
end
subject
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
......
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