Commit 61fb75f7 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Merge branch 'bw-lower-query-specs' into 'master'

Added specs for Keyset connenction using LOWER

See merge request gitlab-org/gitlab!24711
parents 37fc518c 302c1f5f
...@@ -103,7 +103,75 @@ describe Gitlab::Graphql::Connections::Keyset::Connection do ...@@ -103,7 +103,75 @@ 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
context 'when no cursor is passed' do
let(:arguments) { {} }
it 'returns projects in ascending order' do
expect(subject.sliced_nodes).to eq(ascending_nodes)
end
end
context 'when before cursor value is not NULL' do
let(:arguments) { { before: encoded_cursor(ascending_nodes[2]) } }
it 'returns all projects before the cursor' do
expect(subject.sliced_nodes).to eq(ascending_nodes.first(2))
end
end
context 'when after cursor value is not NULL' do
let(:arguments) { { after: encoded_cursor(ascending_nodes[1]) } }
it 'returns all projects after the cursor' do
expect(subject.sliced_nodes).to eq(ascending_nodes.last(3))
end
end
context 'when before and after cursor' do
let(:arguments) { { before: encoded_cursor(ascending_nodes.last), after: encoded_cursor(ascending_nodes.first) } }
it 'returns all projects after the cursor' do
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
context 'when after cursor value is not NULL' do
let(:arguments) { { after: encoded_cursor(descending_nodes[1]) } }
it 'returns all projects after the cursor' do
expect(subject.sliced_nodes).to eq(descending_nodes.last(3))
end
end
context 'when before and after cursor' do
let(:arguments) { { before: encoded_cursor(descending_nodes.last), after: encoded_cursor(descending_nodes.first) } }
it 'returns all projects after the cursor' do
expect(subject.sliced_nodes).to eq(descending_nodes[1..3])
end
end
end
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!(: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!(: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!(:project3) { create(:project, last_repository_check_at: 5.days.ago) } # Asc: project3 Desc: project5
...@@ -114,14 +182,9 @@ describe Gitlab::Graphql::Connections::Keyset::Connection do ...@@ -114,14 +182,9 @@ describe Gitlab::Graphql::Connections::Keyset::Connection do
let(:nodes) do let(:nodes) do
Project.order(Arel.sql('projects.last_repository_check_at IS NULL')).order(last_repository_check_at: :asc).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 'returns projects in ascending order' do
expect(subject.sliced_nodes).to eq([project5, project1, project3, 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) } }
...@@ -131,14 +194,6 @@ describe Gitlab::Graphql::Connections::Keyset::Connection do ...@@ -131,14 +194,6 @@ describe Gitlab::Graphql::Connections::Keyset::Connection do
end end
end end
context 'when before cursor value is not NULL' do
let(:arguments) { { before: encoded_cursor(project3) } }
it 'returns all projects before the cursor' do
expect(subject.sliced_nodes).to eq([project5, project1])
end
end
context 'when after cursor value is NULL' do context 'when after cursor value is NULL' do
let(:arguments) { { after: encoded_cursor(project2) } } let(:arguments) { { after: encoded_cursor(project2) } }
...@@ -146,36 +201,15 @@ describe Gitlab::Graphql::Connections::Keyset::Connection do ...@@ -146,36 +201,15 @@ 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([project3, project2, project4])
end
end
context 'when before and after cursor' do
let(:arguments) { { before: encoded_cursor(project4), after: encoded_cursor(project5) } }
it 'returns all projects after the cursor' do
expect(subject.sliced_nodes).to eq([project1, project3, project2])
end
end
end end
context 'when descending' do context 'when descending' 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: :desc).order(id: :asc)
end end
let(:descending_nodes) { [project3, project1, project5, project2, project4] }
context 'when no cursor is passed' do it_behaves_like 'nodes are in descending 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) } }
...@@ -185,14 +219,6 @@ describe Gitlab::Graphql::Connections::Keyset::Connection do ...@@ -185,14 +219,6 @@ describe Gitlab::Graphql::Connections::Keyset::Connection do
end end
end end
context 'when before cursor value is not NULL' do
let(:arguments) { { before: encoded_cursor(project5) } }
it 'returns all projects before the cursor' do
expect(subject.sliced_nodes).to eq([project3, project1])
end
end
context 'when after cursor value is NULL' do context 'when after cursor value is NULL' do
let(:arguments) { { after: encoded_cursor(project2) } } let(:arguments) { { after: encoded_cursor(project2) } }
...@@ -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
end
end
context 'when after cursor value is not NULL' do context 'when ordering uses LOWER' do
let(:arguments) { { after: encoded_cursor(project1) } } 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([project5, project2, project4]) let(:nodes) do
end Project.order(Arel::Table.new(:projects)['name'].lower.asc).order(id: :asc)
end end
let(:ascending_nodes) { [project1, project5, project3, project2, project4] }
context 'when before and after cursor' do it_behaves_like 'nodes are in ascending order'
let(:arguments) { { before: encoded_cursor(project4), after: encoded_cursor(project3) } } end
it 'returns all projects after the cursor' do context 'when descending' do
expect(subject.sliced_nodes).to eq([project1, project5, project2]) let(:nodes) do
end Project.order(Arel::Table.new(:projects)['name'].lower.desc).order(id: :desc)
end end
let(:descending_nodes) { [project4, project2, project3, project5, project1] }
it_behaves_like 'nodes are in descending order'
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