diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-07 00:11:11 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-07 00:11:11 +0000 |
commit | d4f8f25db649b973f1ae344cb0f8a407862d106b (patch) | |
tree | f71f2d2243dc768a1ec44e79556d8020bff51dc7 /spec/controllers/projects/pipelines_controller_spec.rb | |
parent | 5f0e3773e9695fd0c9e92ea9180c8a1f5cfaa5c5 (diff) | |
download | gitlab-ce-d4f8f25db649b973f1ae344cb0f8a407862d106b.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/controllers/projects/pipelines_controller_spec.rb')
-rw-r--r-- | spec/controllers/projects/pipelines_controller_spec.rb | 66 |
1 files changed, 64 insertions, 2 deletions
diff --git a/spec/controllers/projects/pipelines_controller_spec.rb b/spec/controllers/projects/pipelines_controller_spec.rb index 8dc337e3a3d..3c34d41504d 100644 --- a/spec/controllers/projects/pipelines_controller_spec.rb +++ b/spec/controllers/projects/pipelines_controller_spec.rb @@ -145,11 +145,61 @@ describe Projects::PipelinesController do end end - def get_pipelines_index_json + context 'filter by scope' do + it 'returns matched pipelines' do + get_pipelines_index_json(scope: 'running') + + check_pipeline_response(returned: 2, all: 6, running: 2, pending: 1, finished: 3) + end + + context 'scope is branches or tags' do + before do + create(:ci_pipeline, :failed, project: project, ref: 'v1.0.0', tag: true) + end + + context 'when scope is branches' do + it 'returns matched pipelines' do + get_pipelines_index_json(scope: 'branches') + + check_pipeline_response(returned: 1, all: 7, running: 2, pending: 1, finished: 4) + end + end + + context 'when scope is tags' do + it 'returns matched pipelines' do + get_pipelines_index_json(scope: 'tags') + + check_pipeline_response(returned: 1, all: 7, running: 2, pending: 1, finished: 4) + end + end + end + end + + context 'filter by username' do + let!(:pipeline) { create(:ci_pipeline, :running, project: project, user: user) } + + context 'when username exists' do + it 'returns matched pipelines' do + get_pipelines_index_json(username: user.username) + + check_pipeline_response(returned: 1, all: 1, running: 1, pending: 0, finished: 0) + end + end + + context 'when username does not exist' do + it 'returns empty' do + get_pipelines_index_json(username: 'invalid-username') + + check_pipeline_response(returned: 0, all: 0, running: 0, pending: 0, finished: 0) + end + end + end + + def get_pipelines_index_json(params = {}) get :index, params: { namespace_id: project.namespace, project_id: project - }, + }.merge(params), format: :json end @@ -199,6 +249,18 @@ describe Projects::PipelinesController do user: user ) end + + def check_pipeline_response(returned:, all:, running:, pending:, finished:) + aggregate_failures do + expect(response).to match_response_schema('pipeline') + + expect(json_response['pipelines'].count).to eq returned + expect(json_response['count']['all'].to_i).to eq all + expect(json_response['count']['running'].to_i).to eq running + expect(json_response['count']['pending'].to_i).to eq pending + expect(json_response['count']['finished'].to_i).to eq finished + end + end end describe 'GET show.json' do |