summaryrefslogtreecommitdiff
path: root/spec/requests/api/branches_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/requests/api/branches_spec.rb')
-rw-r--r--spec/requests/api/branches_spec.rb116
1 files changed, 96 insertions, 20 deletions
diff --git a/spec/requests/api/branches_spec.rb b/spec/requests/api/branches_spec.rb
index f2dc5b1c045..46acd92803f 100644
--- a/spec/requests/api/branches_spec.rb
+++ b/spec/requests/api/branches_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe API::Branches do
+RSpec.describe API::Branches do
let_it_be(:user) { create(:user) }
let(:project) { create(:project, :repository, creator: user, path: 'my.project') }
let(:guest) { create(:user).tap { |u| project.add_guest(u) } }
@@ -17,6 +17,7 @@ describe API::Branches do
before do
project.add_maintainer(user)
project.repository.add_branch(user, 'ends-with.txt', branch_sha)
+ stub_feature_flags(branch_list_keyset_pagination: false)
end
describe "GET /projects/:id/repository/branches" do
@@ -29,16 +30,6 @@ describe API::Branches do
end
end
- it 'returns the repository branches' do
- get api(route, current_user), params: { per_page: 100 }
-
- expect(response).to have_gitlab_http_status(:ok)
- expect(response).to match_response_schema('public_api/v4/branches')
- expect(response).to include_pagination_headers
- branch_names = json_response.map { |x| x['name'] }
- expect(branch_names).to match_array(project.repository.branch_names)
- end
-
def check_merge_status(json_response)
merged, unmerged = json_response.partition { |branch| branch['merged'] }
merged_branches = merged.map { |branch| branch['name'] }
@@ -47,22 +38,107 @@ describe API::Branches do
expect(project.repository.merged_branch_names(unmerged_branches)).to be_empty
end
- it 'determines only a limited number of merged branch names' do
- expect(API::Entities::Branch).to receive(:represent).with(anything, has_up_to_merged_branch_names_count(2)).and_call_original
+ context 'with branch_list_keyset_pagination feature off' do
+ context 'with legacy pagination params' do
+ it 'returns the repository branches' do
+ get api(route, current_user), params: { per_page: 100 }
- get api(route, current_user), params: { per_page: 2 }
+ expect(response).to have_gitlab_http_status(:ok)
+ expect(response).to match_response_schema('public_api/v4/branches')
+ expect(response).to include_pagination_headers
+ branch_names = json_response.map { |x| x['name'] }
+ expect(branch_names).to match_array(project.repository.branch_names)
+ end
- expect(response).to have_gitlab_http_status(:ok)
+ it 'determines only a limited number of merged branch names' do
+ expect(API::Entities::Branch).to receive(:represent).with(anything, has_up_to_merged_branch_names_count(2)).and_call_original
+
+ get api(route, current_user), params: { per_page: 2 }
+
+ expect(response).to have_gitlab_http_status(:ok)
+ expect(json_response.count).to eq 2
+
+ check_merge_status(json_response)
+ end
- check_merge_status(json_response)
+ it 'merge status matches reality on paginated input' do
+ expected_first_branch_name = project.repository.branches_sorted_by('name')[20].name
+
+ get api(route, current_user), params: { per_page: 20, page: 2 }
+
+ expect(response).to have_gitlab_http_status(:ok)
+ expect(json_response.count).to eq 20
+ expect(json_response.first['name']).to eq(expected_first_branch_name)
+
+ check_merge_status(json_response)
+ end
+ end
+
+ context 'with gitaly pagination params ' do
+ it 'merge status matches reality on paginated input' do
+ expected_first_branch_name = project.repository.branches_sorted_by('name').first.name
+
+ get api(route, current_user), params: { per_page: 20, page_token: 'feature' }
+
+ expect(response).to have_gitlab_http_status(:ok)
+ expect(json_response.count).to eq 20
+ expect(json_response.first['name']).to eq(expected_first_branch_name)
+
+ check_merge_status(json_response)
+ end
+ end
end
- it 'merge status matches reality on paginated input' do
- get api(route, current_user), params: { per_page: 20, page: 2 }
+ context 'with branch_list_keyset_pagination feature on' do
+ before do
+ stub_feature_flags(branch_list_keyset_pagination: true)
+ end
- expect(response).to have_gitlab_http_status(:ok)
+ context 'with gitaly pagination params ' do
+ it 'returns the repository branches' do
+ get api(route, current_user), params: { per_page: 100 }
+
+ expect(response).to have_gitlab_http_status(:ok)
+ expect(response).to match_response_schema('public_api/v4/branches')
+ branch_names = json_response.map { |x| x['name'] }
+ expect(branch_names).to match_array(project.repository.branch_names)
+ end
+
+ it 'determines only a limited number of merged branch names' do
+ expect(API::Entities::Branch).to receive(:represent).with(anything, has_up_to_merged_branch_names_count(2)).and_call_original
+
+ get api(route, current_user), params: { per_page: 2 }
+
+ expect(response).to have_gitlab_http_status(:ok)
+ expect(json_response.count).to eq 2
+
+ check_merge_status(json_response)
+ end
- check_merge_status(json_response)
+ it 'merge status matches reality on paginated input' do
+ expected_first_branch_name = project.repository.branches_sorted_by('name').drop_while { |b| b.name <= 'feature' }.first.name
+
+ get api(route, current_user), params: { per_page: 20, page_token: 'feature' }
+
+ expect(response).to have_gitlab_http_status(:ok)
+ expect(json_response.count).to eq 20
+ expect(json_response.first['name']).to eq(expected_first_branch_name)
+
+ check_merge_status(json_response)
+ end
+ end
+
+ context 'with legacy pagination params' do
+ it 'ignores legacy pagination params' do
+ expected_first_branch_name = project.repository.branches_sorted_by('name').first.name
+ get api(route, current_user), params: { per_page: 20, page: 2 }
+
+ expect(response).to have_gitlab_http_status(:ok)
+ expect(json_response.first['name']).to eq(expected_first_branch_name)
+
+ check_merge_status(json_response)
+ end
+ end
end
context 'when repository is disabled' do