diff options
Diffstat (limited to 'spec/requests/api/ci/pipelines_spec.rb')
-rw-r--r-- | spec/requests/api/ci/pipelines_spec.rb | 104 |
1 files changed, 103 insertions, 1 deletions
diff --git a/spec/requests/api/ci/pipelines_spec.rb b/spec/requests/api/ci/pipelines_spec.rb index eb6c0861844..640e1ee6422 100644 --- a/spec/requests/api/ci/pipelines_spec.rb +++ b/spec/requests/api/ci/pipelines_spec.rb @@ -34,7 +34,28 @@ RSpec.describe API::Ci::Pipelines do expect(json_response.first['sha']).to match(/\A\h{40}\z/) expect(json_response.first['id']).to eq pipeline.id expect(json_response.first['web_url']).to be_present - expect(json_response.first.keys).to contain_exactly(*%w[id project_id sha ref status web_url created_at updated_at]) + end + + describe 'keys in the response' do + context 'when `pipeline_source_filter` feature flag is disabled' do + before do + stub_feature_flags(pipeline_source_filter: false) + end + + it 'does not includes pipeline source' do + get api("/projects/#{project.id}/pipelines", user) + + expect(json_response.first.keys).to contain_exactly(*%w[id project_id sha ref status web_url created_at updated_at]) + end + end + + context 'when `pipeline_source_filter` feature flag is disabled' do + it 'includes pipeline source' do + get api("/projects/#{project.id}/pipelines", user) + + expect(json_response.first.keys).to contain_exactly(*%w[id project_id sha ref status web_url created_at updated_at source]) + end + end end context 'when parameter is passed' do @@ -294,6 +315,48 @@ RSpec.describe API::Ci::Pipelines do end end end + + context 'when a source is specified' do + before do + create(:ci_pipeline, project: project, source: :push) + create(:ci_pipeline, project: project, source: :web) + create(:ci_pipeline, project: project, source: :api) + end + + context 'when `pipeline_source_filter` feature flag is disabled' do + before do + stub_feature_flags(pipeline_source_filter: false) + end + + it 'returns all pipelines' do + get api("/projects/#{project.id}/pipelines", user), params: { source: 'web' } + + expect(response).to have_gitlab_http_status(:ok) + expect(response).to include_pagination_headers + expect(json_response).not_to be_empty + expect(json_response.length).to be >= 3 + end + end + + context 'when `pipeline_source_filter` feature flag is enabled' do + it 'returns matched pipelines' do + get api("/projects/#{project.id}/pipelines", user), params: { source: 'web' } + + expect(response).to have_gitlab_http_status(:ok) + expect(response).to include_pagination_headers + expect(json_response).not_to be_empty + json_response.each { |r| expect(r['source']).to eq('web') } + end + + context 'when source is invalid' do + it 'returns bad_request' do + get api("/projects/#{project.id}/pipelines", user), params: { source: 'invalid-source' } + + expect(response).to have_gitlab_http_status(:bad_request) + end + end + end + end end end @@ -1150,4 +1213,43 @@ RSpec.describe API::Ci::Pipelines do end end end + + describe 'GET /projects/:id/pipelines/:pipeline_id/test_report_summary' do + subject { get api("/projects/#{project.id}/pipelines/#{pipeline.id}/test_report_summary", current_user) } + + context 'authorized user' do + let(:current_user) { user } + + let(:pipeline) { create(:ci_pipeline, project: project) } + + context 'when pipeline does not have a test report summary' do + it 'returns an empty test report summary' do + subject + + expect(response).to have_gitlab_http_status(:ok) + expect(json_response['total']['count']).to eq(0) + end + end + + context 'when pipeline has a test report summary' do + let(:pipeline) { create(:ci_pipeline, :with_report_results, project: project) } + + it 'returns the test report summary' do + subject + + expect(response).to have_gitlab_http_status(:ok) + expect(json_response['total']['count']).to eq(2) + end + end + end + + context 'unauthorized user' do + it 'does not return project pipelines' do + get api("/projects/#{project.id}/pipelines/#{pipeline.id}/test_report_summary", non_member) + + expect(response).to have_gitlab_http_status(:not_found) + expect(json_response['message']).to eq '404 Project Not Found' + end + end + end end |