| ... | @@ -103,93 +103,119 @@ describe Gitlab::Graphql::Connections::Keyset::Connection do |
... | @@ -103,93 +103,119 @@ describe Gitlab::Graphql::Connections::Keyset::Connection do |
|
|
end
|
|
end
|
|
|
end
|
|
end
|
|
|
|
|
|
|
|
context 'when multiple orders are defined' do
|
|
shared_examples 'nodes are in ascending order' do
|
|
|
let!(:project1) { create(:project, last_repository_check_at: 10.days.ago) } # Asc: project5 Desc: project3
|
|
|
|
|
let!(:project2) { create(:project, last_repository_check_at: nil) } # Asc: project1 Desc: project1
|
|
|
|
|
let!(:project3) { create(:project, last_repository_check_at: 5.days.ago) } # Asc: project3 Desc: project5
|
|
|
|
|
let!(:project4) { create(:project, last_repository_check_at: nil) } # Asc: project2 Desc: project2
|
|
|
|
|
let!(:project5) { create(:project, last_repository_check_at: 20.days.ago) } # Asc: project4 Desc: project4
|
|
|
|
|
|
|
|
|
|
context 'when ascending' do
|
|
|
|
|
let(:nodes) do
|
|
|
|
|
Project.order(Arel.sql('projects.last_repository_check_at IS NULL')).order(last_repository_check_at: :asc).order(id: :asc)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'when no cursor is passed' do
|
|
context 'when no cursor is passed' do
|
|
|
let(:arguments) { {} }
|
|
let(:arguments) { {} }
|
|
|
|
|
|
|
|
it 'returns projects in ascending order' do
|
|
it 'returns projects in ascending order' do
|
|
|
expect(subject.sliced_nodes).to eq([project5, project1, project3, project2, project4])
|
|
expect(subject.sliced_nodes).to eq(ascending_nodes)
|
|
|
end
|
|
end
|
|
|
end
|
|
end
|
|
|
|
|
|
|
|
context 'when before cursor value is NULL' do
|
|
context 'when before cursor value is not NULL' do
|
|
|
let(:arguments) { { before: encoded_cursor(project4) } }
|
|
let(:arguments) { { before: encoded_cursor(ascending_nodes[2]) } }
|
|
|
|
|
|
|
|
it 'returns all projects before the cursor' do
|
|
it 'returns all projects before the cursor' do
|
|
|
expect(subject.sliced_nodes).to eq([project5, project1, project3, project2])
|
|
expect(subject.sliced_nodes).to eq(ascending_nodes.first(2))
|
|
|
end
|
|
end
|
|
|
end
|
|
end
|
|
|
|
|
|
|
|
context 'when before cursor value is not NULL' do
|
|
context 'when after cursor value is not NULL' do
|
|
|
let(:arguments) { { before: encoded_cursor(project3) } }
|
|
let(:arguments) { { after: encoded_cursor(ascending_nodes[1]) } }
|
|
|
|
|
|
|
|
it 'returns all projects before the cursor' do
|
|
it 'returns all projects after the cursor' do
|
|
|
expect(subject.sliced_nodes).to eq([project5, project1])
|
|
expect(subject.sliced_nodes).to eq(ascending_nodes.last(3))
|
|
|
end
|
|
end
|
|
|
end
|
|
end
|
|
|
|
|
|
|
|
context 'when after cursor value is NULL' do
|
|
context 'when before and after cursor' do
|
|
|
let(:arguments) { { after: encoded_cursor(project2) } }
|
|
let(:arguments) { { before: encoded_cursor(ascending_nodes.last), after: encoded_cursor(ascending_nodes.first) } }
|
|
|
|
|
|
|
|
it 'returns all projects after the cursor' do
|
|
it 'returns all projects after the cursor' do
|
|
|
expect(subject.sliced_nodes).to eq([project4])
|
|
expect(subject.sliced_nodes).to eq(ascending_nodes[1..3])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples 'nodes are in descending order' do
|
|
|
|
context 'when no cursor is passed' do
|
|
|
|
let(:arguments) { {} }
|
|
|
|
|
|
|
|
it 'only returns projects in descending order' do
|
|
|
|
expect(subject.sliced_nodes).to eq(descending_nodes)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when before cursor value is not NULL' do
|
|
|
|
let(:arguments) { { before: encoded_cursor(descending_nodes[2]) } }
|
|
|
|
|
|
|
|
it 'returns all projects before the cursor' do
|
|
|
|
expect(subject.sliced_nodes).to eq(descending_nodes.first(2))
|
|
|
end
|
|
end
|
|
|
end
|
|
end
|
|
|
|
|
|
|
|
context 'when after cursor value is not NULL' do
|
|
context 'when after cursor value is not NULL' do
|
|
|
let(:arguments) { { after: encoded_cursor(project1) } }
|
|
let(:arguments) { { after: encoded_cursor(descending_nodes[1]) } }
|
|
|
|
|
|
|
|
it 'returns all projects after the cursor' do
|
|
it 'returns all projects after the cursor' do
|
|
|
expect(subject.sliced_nodes).to eq([project3, project2, project4])
|
|
expect(subject.sliced_nodes).to eq(descending_nodes.last(3))
|
|
|
end
|
|
end
|
|
|
end
|
|
end
|
|
|
|
|
|
|
|
context 'when before and after cursor' do
|
|
context 'when before and after cursor' do
|
|
|
let(:arguments) { { before: encoded_cursor(project4), after: encoded_cursor(project5) } }
|
|
let(:arguments) { { before: encoded_cursor(descending_nodes.last), after: encoded_cursor(descending_nodes.first) } }
|
|
|
|
|
|
|
|
it 'returns all projects after the cursor' do
|
|
it 'returns all projects after the cursor' do
|
|
|
expect(subject.sliced_nodes).to eq([project1, project3, project2])
|
|
expect(subject.sliced_nodes).to eq(descending_nodes[1..3])
|
|
|
end
|
|
end
|
|
|
end
|
|
end
|
|
|
end
|
|
end
|
|
|
|
|
|
|
|
context 'when descending' do
|
|
context 'when multiple orders with nil values are defined' do
|
|
|
|
let!(:project1) { create(:project, last_repository_check_at: 10.days.ago) } # Asc: project5 Desc: project3
|
|
|
|
let!(:project2) { create(:project, last_repository_check_at: nil) } # Asc: project1 Desc: project1
|
|
|
|
let!(:project3) { create(:project, last_repository_check_at: 5.days.ago) } # Asc: project3 Desc: project5
|
|
|
|
let!(:project4) { create(:project, last_repository_check_at: nil) } # Asc: project2 Desc: project2
|
|
|
|
let!(:project5) { create(:project, last_repository_check_at: 20.days.ago) } # Asc: project4 Desc: project4
|
|
|
|
|
|
|
|
context 'when ascending' do
|
|
|
let(:nodes) do
|
|
let(:nodes) do
|
|
|
Project.order(Arel.sql('projects.last_repository_check_at IS NULL')).order(last_repository_check_at: :desc).order(id: :asc)
|
|
Project.order(Arel.sql('projects.last_repository_check_at IS NULL')).order(last_repository_check_at: :asc).order(id: :asc)
|
|
|
end
|
|
end
|
|
|
|
let(:ascending_nodes) { [project5, project1, project3, project2, project4] }
|
|
|
|
|
|
|
|
context 'when no cursor is passed' do
|
|
it_behaves_like 'nodes are in ascending order'
|
|
|
let(:arguments) { {} }
|
|
|
|
|
|
|
|
|
|
it 'only returns projects in descending order' do
|
|
|
|
|
expect(subject.sliced_nodes).to eq([project3, project1, project5, project2, project4])
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'when before cursor value is NULL' do
|
|
context 'when before cursor value is NULL' do
|
|
|
let(:arguments) { { before: encoded_cursor(project4) } }
|
|
let(:arguments) { { before: encoded_cursor(project4) } }
|
|
|
|
|
|
|
|
it 'returns all projects before the cursor' do
|
|
it 'returns all projects before the cursor' do
|
|
|
expect(subject.sliced_nodes).to eq([project3, project1, project5, project2])
|
|
expect(subject.sliced_nodes).to eq([project5, project1, project3, project2])
|
|
|
end
|
|
end
|
|
|
end
|
|
end
|
|
|
|
|
|
|
|
context 'when before cursor value is not NULL' do
|
|
context 'when after cursor value is NULL' do
|
|
|
let(:arguments) { { before: encoded_cursor(project5) } }
|
|
let(:arguments) { { after: encoded_cursor(project2) } }
|
|
|
|
|
|
|
|
it 'returns all projects after the cursor' do
|
|
|
|
expect(subject.sliced_nodes).to eq([project4])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when descending' do
|
|
|
|
let(:nodes) do
|
|
|
|
Project.order(Arel.sql('projects.last_repository_check_at IS NULL')).order(last_repository_check_at: :desc).order(id: :asc)
|
|
|
|
end
|
|
|
|
let(:descending_nodes) { [project3, project1, project5, project2, project4] }
|
|
|
|
|
|
|
|
it_behaves_like 'nodes are in descending order'
|
|
|
|
|
|
|
|
context 'when before cursor value is NULL' do
|
|
|
|
let(:arguments) { { before: encoded_cursor(project4) } }
|
|
|
|
|
|
|
|
it 'returns all projects before the cursor' do
|
|
it 'returns all projects before the cursor' do
|
|
|
expect(subject.sliced_nodes).to eq([project3, project1])
|
|
expect(subject.sliced_nodes).to eq([project3, project1, project5, project2])
|
|
|
end
|
|
end
|
|
|
end
|
|
end
|
|
|
|
|
|
| ... | @@ -200,22 +226,32 @@ describe Gitlab::Graphql::Connections::Keyset::Connection do |
... | @@ -200,22 +226,32 @@ describe Gitlab::Graphql::Connections::Keyset::Connection do |
|
|
expect(subject.sliced_nodes).to eq([project4])
|
|
expect(subject.sliced_nodes).to eq([project4])
|
|
|
end
|
|
end
|
|
|
end
|
|
end
|
|
|
|
|
|
|
|
context 'when after cursor value is not NULL' do
|
|
|
|
|
let(:arguments) { { after: encoded_cursor(project1) } }
|
|
|
|
|
|
|
|
|
|
it 'returns all projects after the cursor' do
|
|
|
|
|
expect(subject.sliced_nodes).to eq([project5, project2, project4])
|
|
|
|
|
end
|
|
end
|
|
|
end
|
|
end
|
|
|
|
|
|
|
|
context 'when before and after cursor' do
|
|
context 'when ordering uses LOWER' do
|
|
|
let(:arguments) { { before: encoded_cursor(project4), after: encoded_cursor(project3) } }
|
|
let!(:project1) { create(:project, name: 'A') } # Asc: project1 Desc: project4
|
|
|
|
let!(:project2) { create(:project, name: 'c') } # Asc: project5 Desc: project2
|
|
|
|
let!(:project3) { create(:project, name: 'b') } # Asc: project3 Desc: project3
|
|
|
|
let!(:project4) { create(:project, name: 'd') } # Asc: project2 Desc: project5
|
|
|
|
let!(:project5) { create(:project, name: 'a') } # Asc: project4 Desc: project1
|
|
|
|
|
|
|
|
it 'returns all projects after the cursor' do
|
|
context 'when ascending' do
|
|
|
expect(subject.sliced_nodes).to eq([project1, project5, project2])
|
|
let(:nodes) do
|
|
|
|
Project.order(Arel::Table.new(:projects)['name'].lower.asc).order(id: :asc)
|
|
|
end
|
|
end
|
|
|
|
let(:ascending_nodes) { [project1, project5, project3, project2, project4] }
|
|
|
|
|
|
|
|
it_behaves_like 'nodes are in ascending order'
|
|
|
end
|
|
end
|
|
|
|
|
|
|
|
context 'when descending' do
|
|
|
|
let(:nodes) do
|
|
|
|
Project.order(Arel::Table.new(:projects)['name'].lower.desc).order(id: :desc)
|
|
|
|
end
|
|
|
|
let(:descending_nodes) { [project4, project2, project3, project5, project1] }
|
|
|
|
|
|
|
|
it_behaves_like 'nodes are in descending order'
|
|
|
end
|
|
end
|
|
|
end
|
|
end
|
|
|
|
|
|
| ... | |
... | |
| ... | | ... | |