Commit ebfe78ca authored by Etienne Baqué's avatar Etienne Baqué

Merge branch 'philipcunningham-cleanup-technical-debt-295160' into 'master'

Rename let binding in GraphQL shared_example

See merge request gitlab-org/gitlab!71166
parents 314a36ab 5d23a8a2
...@@ -340,7 +340,7 @@ describe 'sorting and pagination' do ...@@ -340,7 +340,7 @@ describe 'sorting and pagination' do
it_behaves_like 'sorted paginated query' do it_behaves_like 'sorted paginated query' do
let(:sort_param) { :WEIGHT_ASC } let(:sort_param) { :WEIGHT_ASC }
let(:first_param) { 2 } let(:first_param) { 2 }
let(:expected_results) { ordered_issues.map(&:iid) } let(:all_records) { ordered_issues.map(&:iid) }
end end
end end
end end
......
...@@ -92,7 +92,7 @@ RSpec.describe 'get board lists' do ...@@ -92,7 +92,7 @@ RSpec.describe 'get board lists' do
it_behaves_like 'sorted paginated query' do it_behaves_like 'sorted paginated query' do
let(:sort_param) { } let(:sort_param) { }
let(:first_param) { 2 } let(:first_param) { 2 }
let(:expected_results) { lists.map { |list| global_id_of(list) } } let(:all_records) { lists.map { |list| global_id_of(list) } }
end end
end end
end end
......
...@@ -43,7 +43,7 @@ RSpec.describe 'get list of epics for an epic board list' do ...@@ -43,7 +43,7 @@ RSpec.describe 'get list of epics for an epic board list' do
describe 'sorting and pagination' do describe 'sorting and pagination' do
let(:epic_fields) { all_graphql_fields_for('epics'.classify) } let(:epic_fields) { all_graphql_fields_for('epics'.classify) }
let(:expected_results) { [epic2.to_global_id.to_s, epic1.to_global_id.to_s, epic3.to_global_id.to_s] } let(:all_records) { [epic2.to_global_id.to_s, epic1.to_global_id.to_s, epic3.to_global_id.to_s] }
def pagination_results_data(nodes) def pagination_results_data(nodes)
nodes.map { |list| list['id'] } nodes.map { |list| list['id'] }
......
...@@ -36,7 +36,7 @@ RSpec.describe 'get list of epic boards' do ...@@ -36,7 +36,7 @@ RSpec.describe 'get list of epic boards' do
describe 'sorting and pagination' do describe 'sorting and pagination' do
let(:data_path) { [:group, :epicBoards] } let(:data_path) { [:group, :epicBoards] }
let(:expected_results) { [board2.to_global_id.to_s, board3.to_global_id.to_s, board1.to_global_id.to_s] } let(:all_records) { [board2.to_global_id.to_s, board3.to_global_id.to_s, board1.to_global_id.to_s] }
def pagination_results_data(nodes) def pagination_results_data(nodes)
nodes.map { |board| board['id'] } nodes.map { |board| board['id'] }
......
...@@ -41,7 +41,7 @@ RSpec.describe 'get list of epic boards' do ...@@ -41,7 +41,7 @@ RSpec.describe 'get list of epic boards' do
describe 'sorting and pagination' do describe 'sorting and pagination' do
let(:data_path) { [:group, :epicBoard, :lists] } let(:data_path) { [:group, :epicBoard, :lists] }
let(:expected_results) { [list3.to_global_id.to_s, list1.to_global_id.to_s, list2.to_global_id.to_s] } let(:all_records) { [list3.to_global_id.to_s, list1.to_global_id.to_s, list2.to_global_id.to_s] }
def pagination_results_data(nodes) def pagination_results_data(nodes)
nodes.map { |list| list['id'] } nodes.map { |list| list['id'] }
......
...@@ -89,7 +89,7 @@ RSpec.describe 'Getting issues for an epic' do ...@@ -89,7 +89,7 @@ RSpec.describe 'Getting issues for an epic' do
let(:current_user) { user } let(:current_user) { user }
let(:sort_param) { } let(:sort_param) { }
let(:first_param) { 1 } let(:first_param) { 1 }
let(:expected_results) { [issue, confidential_issue].map { |i| global_id_of(i) } } let(:all_records) { [issue, confidential_issue].map { |i| global_id_of(i) } }
end end
end end
end end
......
...@@ -99,7 +99,7 @@ RSpec.describe 'Epics through GroupQuery' do ...@@ -99,7 +99,7 @@ RSpec.describe 'Epics through GroupQuery' do
it_behaves_like 'sorted paginated query', is_reversible: true do it_behaves_like 'sorted paginated query', is_reversible: true do
let(:sort_param) { :start_date_asc } let(:sort_param) { :start_date_asc }
let(:first_param) { 2 } let(:first_param) { 2 }
let(:expected_results) { global_ids(epic4, epic3, epic2, epic) } let(:all_records) { global_ids(epic4, epic3, epic2, epic) }
end end
end end
...@@ -107,7 +107,7 @@ RSpec.describe 'Epics through GroupQuery' do ...@@ -107,7 +107,7 @@ RSpec.describe 'Epics through GroupQuery' do
it_behaves_like 'sorted paginated query', is_reversible: true do it_behaves_like 'sorted paginated query', is_reversible: true do
let(:sort_param) { :start_date_desc } let(:sort_param) { :start_date_desc }
let(:first_param) { 2 } let(:first_param) { 2 }
let(:expected_results) { global_ids(epic, epic2, epic3, epic4) } let(:all_records) { global_ids(epic, epic2, epic3, epic4) }
end end
end end
...@@ -115,7 +115,7 @@ RSpec.describe 'Epics through GroupQuery' do ...@@ -115,7 +115,7 @@ RSpec.describe 'Epics through GroupQuery' do
it_behaves_like 'sorted paginated query', is_reversible: true do it_behaves_like 'sorted paginated query', is_reversible: true do
let(:sort_param) { :end_date_asc } let(:sort_param) { :end_date_asc }
let(:first_param) { 2 } let(:first_param) { 2 }
let(:expected_results) { global_ids(epic3, epic4, epic, epic2) } let(:all_records) { global_ids(epic3, epic4, epic, epic2) }
end end
end end
...@@ -123,7 +123,7 @@ RSpec.describe 'Epics through GroupQuery' do ...@@ -123,7 +123,7 @@ RSpec.describe 'Epics through GroupQuery' do
it_behaves_like 'sorted paginated query', is_reversible: true do it_behaves_like 'sorted paginated query', is_reversible: true do
let(:sort_param) { :end_date_desc } let(:sort_param) { :end_date_desc }
let(:first_param) { 2 } let(:first_param) { 2 }
let(:expected_results) { global_ids(epic2, epic, epic4, epic3) } let(:all_records) { global_ids(epic2, epic, epic4, epic3) }
end end
end end
end end
......
...@@ -367,7 +367,7 @@ RSpec.describe 'getting group information' do ...@@ -367,7 +367,7 @@ RSpec.describe 'getting group information' do
let(:node_path) { ['averageCoverage'] } let(:node_path) { ['averageCoverage'] }
let(:sort_param) { } let(:sort_param) { }
let(:first_param) { 2 } let(:first_param) { 2 }
let(:expected_results) { [cov_1, cov_2, cov_3, cov_4, cov_5].reverse.map(&:coverage) } let(:all_records) { [cov_1, cov_2, cov_3, cov_4, cov_5].reverse.map(&:coverage) }
end end
end end
end end
......
...@@ -39,7 +39,7 @@ RSpec.describe 'Namespace.projects' do ...@@ -39,7 +39,7 @@ RSpec.describe 'Namespace.projects' do
let(:node_path) { %w[name] } let(:node_path) { %w[name] }
let(:sort_param) { :STORAGE } let(:sort_param) { :STORAGE }
let(:first_param) { 2 } let(:first_param) { 2 }
let(:expected_results) { [project_4, project_2, project_3].map(&:name) } let(:all_records) { [project_4, project_2, project_3].map(&:name) }
end end
end end
end end
......
...@@ -69,7 +69,7 @@ RSpec.describe 'Query.project(fullPath).dastProfiles' do ...@@ -69,7 +69,7 @@ RSpec.describe 'Query.project(fullPath).dastProfiles' do
let(:sort_param) { nil } let(:sort_param) { nil }
let(:first_param) { 3 } let(:first_param) { 3 }
let(:expected_results) do let(:all_records) do
[dast_profile4, dast_profile3, dast_profile2, dast_profile1].map { |validation| global_id_of(validation)} [dast_profile4, dast_profile3, dast_profile2, dast_profile1].map { |validation| global_id_of(validation)}
end end
end end
......
...@@ -71,7 +71,7 @@ RSpec.describe 'Query.project(fullPath).dastSiteValidations' do ...@@ -71,7 +71,7 @@ RSpec.describe 'Query.project(fullPath).dastSiteValidations' do
let(:sort_param) { nil } let(:sort_param) { nil }
let(:first_param) { 3 } let(:first_param) { 3 }
let(:expected_results) do let(:all_records) do
[ [
dast_site_validation4, dast_site_validation4,
dast_site_validation3, dast_site_validation3,
......
...@@ -29,7 +29,7 @@ RSpec.describe 'getting an issue list for a project' do ...@@ -29,7 +29,7 @@ RSpec.describe 'getting an issue list for a project' do
let(:node_path) { %w[iid] } let(:node_path) { %w[iid] }
let(:sort_param) { :WEIGHT_ASC } let(:sort_param) { :WEIGHT_ASC }
let(:first_param) { 2 } let(:first_param) { 2 }
let(:expected_results) { [weight_issue3, weight_issue5, weight_issue1, weight_issue4, weight_issue2].map { |i| i.iid.to_s } } let(:all_records) { [weight_issue3, weight_issue5, weight_issue1, weight_issue4, weight_issue2].map { |i| i.iid.to_s } }
end end
end end
...@@ -38,7 +38,7 @@ RSpec.describe 'getting an issue list for a project' do ...@@ -38,7 +38,7 @@ RSpec.describe 'getting an issue list for a project' do
let(:node_path) { %w[iid] } let(:node_path) { %w[iid] }
let(:sort_param) { :WEIGHT_DESC } let(:sort_param) { :WEIGHT_DESC }
let(:first_param) { 2 } let(:first_param) { 2 }
let(:expected_results) { [weight_issue1, weight_issue5, weight_issue3, weight_issue4, weight_issue2].map { |i| i.iid.to_s } } let(:all_records) { [weight_issue1, weight_issue5, weight_issue3, weight_issue4, weight_issue2].map { |i| i.iid.to_s } }
end end
end end
end end
......
...@@ -208,7 +208,7 @@ RSpec.describe 'getting a requirement list for a project' do ...@@ -208,7 +208,7 @@ RSpec.describe 'getting a requirement list for a project' do
it_behaves_like 'sorted paginated query' do it_behaves_like 'sorted paginated query' do
let(:sort_param) { :CREATED_ASC } let(:sort_param) { :CREATED_ASC }
let(:first_param) { 2 } let(:first_param) { 2 }
let(:expected_results) { [requirement4.iid, requirement3.iid, requirement5.iid, requirement1.iid, requirement2.iid] } let(:all_records) { [requirement4.iid, requirement3.iid, requirement5.iid, requirement1.iid, requirement2.iid] }
end end
end end
...@@ -216,7 +216,7 @@ RSpec.describe 'getting a requirement list for a project' do ...@@ -216,7 +216,7 @@ RSpec.describe 'getting a requirement list for a project' do
it_behaves_like 'sorted paginated query' do it_behaves_like 'sorted paginated query' do
let(:sort_param) { :CREATED_DESC } let(:sort_param) { :CREATED_DESC }
let(:first_param) { 2 } let(:first_param) { 2 }
let(:expected_results) { [requirement2.iid, requirement1.iid, requirement5.iid, requirement3.iid, requirement4.iid] } let(:all_records) { [requirement2.iid, requirement1.iid, requirement5.iid, requirement3.iid, requirement4.iid] }
end end
end end
end end
......
...@@ -55,8 +55,8 @@ RSpec.describe 'getting test reports of a requirement' do ...@@ -55,8 +55,8 @@ RSpec.describe 'getting test reports of a requirement' do
post_graphql(query, current_user: current_user) post_graphql(query, current_user: current_user)
test_reports_ids = test_reports_data.map { |result| result['node']['id'] } test_reports_ids = test_reports_data.map { |result| result['node']['id'] }
expected_results = [test_report_1.to_global_id.to_s, test_report_2.to_global_id.to_s] all_records = [test_report_1.to_global_id.to_s, test_report_2.to_global_id.to_s]
expect(test_reports_ids).to match_array(expected_results) expect(test_reports_ids).to match_array(all_records)
end end
context 'with pagination' do context 'with pagination' do
...@@ -76,7 +76,7 @@ RSpec.describe 'getting test reports of a requirement' do ...@@ -76,7 +76,7 @@ RSpec.describe 'getting test reports of a requirement' do
it_behaves_like 'sorted paginated query' do it_behaves_like 'sorted paginated query' do
let(:sort_param) { :CREATED_ASC } let(:sort_param) { :CREATED_ASC }
let(:first_param) { 2 } let(:first_param) { 2 }
let(:expected_results) do let(:all_records) do
in_creation_order.map { |r| global_id_of(r) } in_creation_order.map { |r| global_id_of(r) }
end end
end end
...@@ -84,7 +84,7 @@ RSpec.describe 'getting test reports of a requirement' do ...@@ -84,7 +84,7 @@ RSpec.describe 'getting test reports of a requirement' do
it_behaves_like 'sorted paginated query' do it_behaves_like 'sorted paginated query' do
let(:sort_param) { :CREATED_DESC } let(:sort_param) { :CREATED_DESC }
let(:first_param) { 2 } let(:first_param) { 2 }
let(:expected_results) do let(:all_records) do
in_creation_order.reverse.map { |r| global_id_of(r) } in_creation_order.reverse.map { |r| global_id_of(r) }
end end
end end
......
...@@ -94,7 +94,7 @@ RSpec.describe 'get board lists' do ...@@ -94,7 +94,7 @@ RSpec.describe 'get board lists' do
it_behaves_like 'sorted paginated query' do it_behaves_like 'sorted paginated query' do
let(:sort_param) { } let(:sort_param) { }
let(:first_param) { 2 } let(:first_param) { 2 }
let(:expected_results) { lists.map { |list| global_id_of(list) } } let(:all_records) { lists.map { |list| global_id_of(list) } }
end end
end end
end end
......
...@@ -97,7 +97,7 @@ RSpec.describe 'Query.runners' do ...@@ -97,7 +97,7 @@ RSpec.describe 'Query.runners' do
it_behaves_like 'sorted paginated query' do it_behaves_like 'sorted paginated query' do
let(:sort_param) { :CONTACTED_ASC } let(:sort_param) { :CONTACTED_ASC }
let(:first_param) { 2 } let(:first_param) { 2 }
let(:expected_results) { ordered_runners.map(&:id) } let(:all_records) { ordered_runners.map(&:id) }
end end
end end
...@@ -107,7 +107,7 @@ RSpec.describe 'Query.runners' do ...@@ -107,7 +107,7 @@ RSpec.describe 'Query.runners' do
it_behaves_like 'sorted paginated query' do it_behaves_like 'sorted paginated query' do
let(:sort_param) { :CREATED_DESC } let(:sort_param) { :CREATED_DESC }
let(:first_param) { 2 } let(:first_param) { 2 }
let(:expected_results) { ordered_runners.map(&:id) } let(:all_records) { ordered_runners.map(&:id) }
end end
end end
end end
......
...@@ -109,7 +109,7 @@ RSpec.describe 'getting projects' do ...@@ -109,7 +109,7 @@ RSpec.describe 'getting projects' do
let(:node_path) { %w[name] } let(:node_path) { %w[name] }
let(:sort_param) { :SIMILARITY } let(:sort_param) { :SIMILARITY }
let(:first_param) { 2 } let(:first_param) { 2 }
let(:expected_results) { [project_3.name, project_2.name, project_4.name] } let(:all_records) { [project_3.name, project_2.name, project_4.name] }
end end
end end
end end
......
...@@ -190,7 +190,7 @@ RSpec.describe 'getting container repositories in a project' do ...@@ -190,7 +190,7 @@ RSpec.describe 'getting container repositories in a project' do
it_behaves_like 'sorted paginated query' do it_behaves_like 'sorted paginated query' do
let(:sort_param) { :NAME_ASC } let(:sort_param) { :NAME_ASC }
let(:first_param) { 2 } let(:first_param) { 2 }
let(:expected_results) { [container_repository2.name, container_repository1.name, container_repository4.name, container_repository3.name, container_repository5.name] } let(:all_records) { [container_repository2.name, container_repository1.name, container_repository4.name, container_repository3.name, container_repository5.name] }
end end
end end
...@@ -198,7 +198,7 @@ RSpec.describe 'getting container repositories in a project' do ...@@ -198,7 +198,7 @@ RSpec.describe 'getting container repositories in a project' do
it_behaves_like 'sorted paginated query' do it_behaves_like 'sorted paginated query' do
let(:sort_param) { :NAME_DESC } let(:sort_param) { :NAME_DESC }
let(:first_param) { 2 } let(:first_param) { 2 }
let(:expected_results) { [container_repository5.name, container_repository3.name, container_repository4.name, container_repository1.name, container_repository2.name] } let(:all_records) { [container_repository5.name, container_repository3.name, container_repository4.name, container_repository1.name, container_repository2.name] }
end end
end end
end end
......
...@@ -205,7 +205,7 @@ RSpec.describe 'getting an issue list for a project' do ...@@ -205,7 +205,7 @@ RSpec.describe 'getting an issue list for a project' do
it_behaves_like 'sorted paginated query' do it_behaves_like 'sorted paginated query' do
let(:sort_param) { :DUE_DATE_ASC } let(:sort_param) { :DUE_DATE_ASC }
let(:first_param) { 2 } let(:first_param) { 2 }
let(:expected_results) { [due_issue3.iid, due_issue5.iid, due_issue1.iid, due_issue4.iid, due_issue2.iid] } let(:all_records) { [due_issue3.iid, due_issue5.iid, due_issue1.iid, due_issue4.iid, due_issue2.iid] }
end end
end end
...@@ -213,7 +213,7 @@ RSpec.describe 'getting an issue list for a project' do ...@@ -213,7 +213,7 @@ RSpec.describe 'getting an issue list for a project' do
it_behaves_like 'sorted paginated query' do it_behaves_like 'sorted paginated query' do
let(:sort_param) { :DUE_DATE_DESC } let(:sort_param) { :DUE_DATE_DESC }
let(:first_param) { 2 } let(:first_param) { 2 }
let(:expected_results) { [due_issue1.iid, due_issue5.iid, due_issue3.iid, due_issue4.iid, due_issue2.iid] } let(:all_records) { [due_issue1.iid, due_issue5.iid, due_issue3.iid, due_issue4.iid, due_issue2.iid] }
end end
end end
end end
...@@ -230,7 +230,7 @@ RSpec.describe 'getting an issue list for a project' do ...@@ -230,7 +230,7 @@ RSpec.describe 'getting an issue list for a project' do
it_behaves_like 'sorted paginated query' do it_behaves_like 'sorted paginated query' do
let(:sort_param) { :RELATIVE_POSITION_ASC } let(:sort_param) { :RELATIVE_POSITION_ASC }
let(:first_param) { 2 } let(:first_param) { 2 }
let(:expected_results) do let(:all_records) do
[ [
relative_issue5.iid, relative_issue3.iid, relative_issue1.iid, relative_issue5.iid, relative_issue3.iid, relative_issue1.iid,
relative_issue4.iid, relative_issue2.iid relative_issue4.iid, relative_issue2.iid
...@@ -256,7 +256,7 @@ RSpec.describe 'getting an issue list for a project' do ...@@ -256,7 +256,7 @@ RSpec.describe 'getting an issue list for a project' do
it_behaves_like 'sorted paginated query' do it_behaves_like 'sorted paginated query' do
let(:sort_param) { :PRIORITY_ASC } let(:sort_param) { :PRIORITY_ASC }
let(:first_param) { 2 } let(:first_param) { 2 }
let(:expected_results) do let(:all_records) do
[ [
priority_issue3.iid, priority_issue1.iid, priority_issue3.iid, priority_issue1.iid,
priority_issue2.iid, priority_issue4.iid priority_issue2.iid, priority_issue4.iid
...@@ -269,7 +269,7 @@ RSpec.describe 'getting an issue list for a project' do ...@@ -269,7 +269,7 @@ RSpec.describe 'getting an issue list for a project' do
it_behaves_like 'sorted paginated query' do it_behaves_like 'sorted paginated query' do
let(:sort_param) { :PRIORITY_DESC } let(:sort_param) { :PRIORITY_DESC }
let(:first_param) { 2 } let(:first_param) { 2 }
let(:expected_results) do let(:all_records) do
[priority_issue1.iid, priority_issue3.iid, priority_issue2.iid, priority_issue4.iid] [priority_issue1.iid, priority_issue3.iid, priority_issue2.iid, priority_issue4.iid]
end end
end end
...@@ -290,7 +290,7 @@ RSpec.describe 'getting an issue list for a project' do ...@@ -290,7 +290,7 @@ RSpec.describe 'getting an issue list for a project' do
it_behaves_like 'sorted paginated query' do it_behaves_like 'sorted paginated query' do
let(:sort_param) { :LABEL_PRIORITY_ASC } let(:sort_param) { :LABEL_PRIORITY_ASC }
let(:first_param) { 2 } let(:first_param) { 2 }
let(:expected_results) { [label_issue3.iid, label_issue1.iid, label_issue2.iid, label_issue4.iid] } let(:all_records) { [label_issue3.iid, label_issue1.iid, label_issue2.iid, label_issue4.iid] }
end end
end end
...@@ -298,7 +298,7 @@ RSpec.describe 'getting an issue list for a project' do ...@@ -298,7 +298,7 @@ RSpec.describe 'getting an issue list for a project' do
it_behaves_like 'sorted paginated query' do it_behaves_like 'sorted paginated query' do
let(:sort_param) { :LABEL_PRIORITY_DESC } let(:sort_param) { :LABEL_PRIORITY_DESC }
let(:first_param) { 2 } let(:first_param) { 2 }
let(:expected_results) { [label_issue2.iid, label_issue3.iid, label_issue1.iid, label_issue4.iid] } let(:all_records) { [label_issue2.iid, label_issue3.iid, label_issue1.iid, label_issue4.iid] }
end end
end end
end end
...@@ -315,7 +315,7 @@ RSpec.describe 'getting an issue list for a project' do ...@@ -315,7 +315,7 @@ RSpec.describe 'getting an issue list for a project' do
it_behaves_like 'sorted paginated query' do it_behaves_like 'sorted paginated query' do
let(:sort_param) { :MILESTONE_DUE_ASC } let(:sort_param) { :MILESTONE_DUE_ASC }
let(:first_param) { 2 } let(:first_param) { 2 }
let(:expected_results) { [milestone_issue2.iid, milestone_issue3.iid, milestone_issue1.iid] } let(:all_records) { [milestone_issue2.iid, milestone_issue3.iid, milestone_issue1.iid] }
end end
end end
...@@ -323,7 +323,7 @@ RSpec.describe 'getting an issue list for a project' do ...@@ -323,7 +323,7 @@ RSpec.describe 'getting an issue list for a project' do
it_behaves_like 'sorted paginated query' do it_behaves_like 'sorted paginated query' do
let(:sort_param) { :MILESTONE_DUE_DESC } let(:sort_param) { :MILESTONE_DUE_DESC }
let(:first_param) { 2 } let(:first_param) { 2 }
let(:expected_results) { [milestone_issue3.iid, milestone_issue2.iid, milestone_issue1.iid] } let(:all_records) { [milestone_issue3.iid, milestone_issue2.iid, milestone_issue1.iid] }
end end
end end
end end
......
...@@ -385,7 +385,7 @@ RSpec.describe 'getting merge request listings nested in a project' do ...@@ -385,7 +385,7 @@ RSpec.describe 'getting merge request listings nested in a project' do
context 'when sorting by merged_at DESC' do context 'when sorting by merged_at DESC' do
let(:sort_param) { :MERGED_AT_DESC } let(:sort_param) { :MERGED_AT_DESC }
let(:expected_results) do let(:all_records) do
[ [
merge_request_b, merge_request_b,
merge_request_d, merge_request_d,
...@@ -418,14 +418,14 @@ RSpec.describe 'getting merge request listings nested in a project' do ...@@ -418,14 +418,14 @@ RSpec.describe 'getting merge request listings nested in a project' do
query = pagination_query(params) query = pagination_query(params)
post_graphql(query, current_user: current_user) post_graphql(query, current_user: current_user)
expect(results.map { |item| item["id"] }).to eq(expected_results.last(2)) expect(results.map { |item| item["id"] }).to eq(all_records.last(2))
end end
end end
end end
context 'when sorting by closed_at DESC' do context 'when sorting by closed_at DESC' do
let(:sort_param) { :CLOSED_AT_DESC } let(:sort_param) { :CLOSED_AT_DESC }
let(:expected_results) do let(:all_records) do
[ [
merge_request_b, merge_request_b,
merge_request_d, merge_request_d,
...@@ -458,7 +458,7 @@ RSpec.describe 'getting merge request listings nested in a project' do ...@@ -458,7 +458,7 @@ RSpec.describe 'getting merge request listings nested in a project' do
query = pagination_query(params) query = pagination_query(params)
post_graphql(query, current_user: current_user) post_graphql(query, current_user: current_user)
expect(results.map { |item| item["id"] }).to eq(expected_results.last(2)) expect(results.map { |item| item["id"] }).to eq(all_records.last(2))
end end
end end
end end
......
...@@ -324,7 +324,7 @@ RSpec.describe 'Query.project(fullPath).releases()' do ...@@ -324,7 +324,7 @@ RSpec.describe 'Query.project(fullPath).releases()' do
it_behaves_like 'sorted paginated query' do it_behaves_like 'sorted paginated query' do
let(:sort_param) { :RELEASED_AT_ASC } let(:sort_param) { :RELEASED_AT_ASC }
let(:first_param) { 2 } let(:first_param) { 2 }
let(:expected_results) { [release1.tag, release2.tag, release3.tag, release4.tag, release5.tag] } let(:all_records) { [release1.tag, release2.tag, release3.tag, release4.tag, release5.tag] }
end end
end end
...@@ -332,7 +332,7 @@ RSpec.describe 'Query.project(fullPath).releases()' do ...@@ -332,7 +332,7 @@ RSpec.describe 'Query.project(fullPath).releases()' do
it_behaves_like 'sorted paginated query' do it_behaves_like 'sorted paginated query' do
let(:sort_param) { :RELEASED_AT_DESC } let(:sort_param) { :RELEASED_AT_DESC }
let(:first_param) { 2 } let(:first_param) { 2 }
let(:expected_results) { [release5.tag, release4.tag, release3.tag, release2.tag, release1.tag] } let(:all_records) { [release5.tag, release4.tag, release3.tag, release2.tag, release1.tag] }
end end
end end
end end
...@@ -348,7 +348,7 @@ RSpec.describe 'Query.project(fullPath).releases()' do ...@@ -348,7 +348,7 @@ RSpec.describe 'Query.project(fullPath).releases()' do
it_behaves_like 'sorted paginated query' do it_behaves_like 'sorted paginated query' do
let(:sort_param) { :CREATED_ASC } let(:sort_param) { :CREATED_ASC }
let(:first_param) { 2 } let(:first_param) { 2 }
let(:expected_results) { [release1.tag, release2.tag, release3.tag, release4.tag, release5.tag] } let(:all_records) { [release1.tag, release2.tag, release3.tag, release4.tag, release5.tag] }
end end
end end
...@@ -356,7 +356,7 @@ RSpec.describe 'Query.project(fullPath).releases()' do ...@@ -356,7 +356,7 @@ RSpec.describe 'Query.project(fullPath).releases()' do
it_behaves_like 'sorted paginated query' do it_behaves_like 'sorted paginated query' do
let(:sort_param) { :CREATED_DESC } let(:sort_param) { :CREATED_DESC }
let(:first_param) { 2 } let(:first_param) { 2 }
let(:expected_results) { [release5.tag, release4.tag, release3.tag, release2.tag, release1.tag] } let(:all_records) { [release5.tag, release4.tag, release3.tag, release2.tag, release1.tag] }
end end
end end
end end
......
...@@ -116,7 +116,7 @@ RSpec.describe 'Users' do ...@@ -116,7 +116,7 @@ RSpec.describe 'Users' do
it_behaves_like 'sorted paginated query' do it_behaves_like 'sorted paginated query' do
let(:sort_param) { :CREATED_ASC } let(:sort_param) { :CREATED_ASC }
let(:first_param) { 1 } let(:first_param) { 1 }
let(:expected_results) { ascending_users } let(:all_records) { ascending_users }
end end
end end
...@@ -124,7 +124,7 @@ RSpec.describe 'Users' do ...@@ -124,7 +124,7 @@ RSpec.describe 'Users' do
it_behaves_like 'sorted paginated query' do it_behaves_like 'sorted paginated query' do
let(:sort_param) { :CREATED_DESC } let(:sort_param) { :CREATED_DESC }
let(:first_param) { 1 } let(:first_param) { 1 }
let(:expected_results) { ascending_users.reverse } let(:all_records) { ascending_users.reverse }
end end
end end
end end
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
# data_path: the keys necessary to dig into the return GraphQL data to get the # data_path: the keys necessary to dig into the return GraphQL data to get the
# returned results # returned results
# first_param: number of items expected (like a page size) # first_param: number of items expected (like a page size)
# expected_results: array of comparison data of all items sorted correctly # all_records: array of comparison data of all items sorted correctly
# pagination_query: method that specifies the GraphQL query # pagination_query: method that specifies the GraphQL query
# pagination_results_data: method that extracts the sorted data used to compare against # pagination_results_data: method that extracts the sorted data used to compare against
# the expected results # the expected results
...@@ -40,7 +40,7 @@ ...@@ -40,7 +40,7 @@
# it_behaves_like 'sorted paginated query' do # it_behaves_like 'sorted paginated query' do
# let(:sort_param) { :WEIGHT_ASC } # let(:sort_param) { :WEIGHT_ASC }
# let(:first_param) { 2 } # let(:first_param) { 2 }
# let(:expected_results) { ordered_issues.map(&:iid) } # let(:all_records) { ordered_issues.map(&:iid) }
# end # end
# end # end
# #
...@@ -51,7 +51,7 @@ RSpec.shared_examples 'sorted paginated query' do |conditions = {}| ...@@ -51,7 +51,7 @@ RSpec.shared_examples 'sorted paginated query' do |conditions = {}|
let(:node_path) { ['id'] } let(:node_path) { ['id'] }
it_behaves_like 'requires variables' do it_behaves_like 'requires variables' do
let(:required_variables) { [:sort_param, :first_param, :expected_results, :data_path, :current_user] } let(:required_variables) { [:sort_param, :first_param, :all_records, :data_path, :current_user] }
end end
describe do describe do
...@@ -101,13 +101,13 @@ RSpec.shared_examples 'sorted paginated query' do |conditions = {}| ...@@ -101,13 +101,13 @@ RSpec.shared_examples 'sorted paginated query' do |conditions = {}|
context 'when sorting' do context 'when sorting' do
it 'sorts correctly' do it 'sorts correctly' do
expect(results).to eq expected_results expect(results).to eq all_records
end end
context 'when paginating' do context 'when paginating' do
let(:params) { sort_argument.merge(first: first_param) } let(:params) { sort_argument.merge(first: first_param) }
let(:first_page) { expected_results.first(first_param) } let(:first_page) { all_records.first(first_param) }
let(:rest) { expected_results.drop(first_param) } let(:rest) { all_records.drop(first_param) }
it 'paginates correctly' do it 'paginates correctly' do
expect(results).to eq first_page expect(results).to eq first_page
...@@ -130,7 +130,7 @@ RSpec.shared_examples 'sorted paginated query' do |conditions = {}| ...@@ -130,7 +130,7 @@ RSpec.shared_examples 'sorted paginated query' do |conditions = {}|
it 'fetches last elements without error' do it 'fetches last elements without error' do
post_graphql(pagination_query(params), current_user: current_user) post_graphql(pagination_query(params), current_user: current_user)
expect(results.first).to eq(expected_results.last) expect(results.first).to eq(all_records.last)
end end
end end
end end
......
...@@ -64,7 +64,8 @@ RSpec.shared_examples 'group and project boards query' do ...@@ -64,7 +64,8 @@ RSpec.shared_examples 'group and project boards query' do
it_behaves_like 'sorted paginated query' do it_behaves_like 'sorted paginated query' do
let(:sort_param) { } let(:sort_param) { }
let(:first_param) { 2 } let(:first_param) { 2 }
let(:expected_results) do
let(:all_records) do
if board_parent.multiple_issue_boards_available? if board_parent.multiple_issue_boards_available?
boards.map { |board| global_id_of(board) } boards.map { |board| global_id_of(board) }
else else
......
...@@ -101,7 +101,7 @@ RSpec.shared_examples 'group and project packages query' do ...@@ -101,7 +101,7 @@ RSpec.shared_examples 'group and project packages query' do
it_behaves_like 'sorted paginated query' do it_behaves_like 'sorted paginated query' do
let(:sort_param) { order } let(:sort_param) { order }
let(:first_param) { 4 } let(:first_param) { 4 }
let(:expected_results) { ascending_packages } let(:all_records) { ascending_packages }
end end
end end
end end
...@@ -111,7 +111,7 @@ RSpec.shared_examples 'group and project packages query' do ...@@ -111,7 +111,7 @@ RSpec.shared_examples 'group and project packages query' do
it_behaves_like 'sorted paginated query' do it_behaves_like 'sorted paginated query' do
let(:sort_param) { order } let(:sort_param) { order }
let(:first_param) { 4 } let(:first_param) { 4 }
let(:expected_results) { ascending_packages.reverse } let(:all_records) { ascending_packages.reverse }
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