summaryrefslogtreecommitdiff
path: root/spec/requests/api/builds_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/requests/api/builds_spec.rb')
-rw-r--r--spec/requests/api/builds_spec.rb61
1 files changed, 49 insertions, 12 deletions
diff --git a/spec/requests/api/builds_spec.rb b/spec/requests/api/builds_spec.rb
index 2ab9d640269..f5b39c3d698 100644
--- a/spec/requests/api/builds_spec.rb
+++ b/spec/requests/api/builds_spec.rb
@@ -63,23 +63,60 @@ describe API::API, api: true do
end
describe 'GET /projects/:id/repository/commits/:sha/builds' do
- before do
- project.ensure_pipeline(pipeline.sha, 'master')
- get api("/projects/#{project.id}/repository/commits/#{pipeline.sha}/builds", api_user)
- end
+ context 'when commit does not exist in repository' do
+ before do
+ get api("/projects/#{project.id}/repository/commits/1a271fd1/builds", api_user)
+ end
- context 'authorized user' do
- it 'should return project builds for specific commit' do
- expect(response).to have_http_status(200)
- expect(json_response).to be_an Array
+ it 'responds with 404' do
+ expect(response).to have_http_status(404)
end
end
- context 'unauthorized user' do
- let(:api_user) { nil }
+ context 'when commit exists in repository' do
+ context 'when user is authorized' do
+ context 'when pipeline has builds' do
+ before do
+ create(:ci_pipeline, project: project, sha: project.commit.id)
+ create(:ci_build, pipeline: pipeline)
+ create(:ci_build)
+
+ get api("/projects/#{project.id}/repository/commits/#{project.commit.id}/builds", api_user)
+ end
+
+ it 'should return project builds for specific commit' do
+ expect(response).to have_http_status(200)
+ expect(json_response).to be_an Array
+ expect(json_response.size).to eq 2
+ end
+ end
- it 'should not return project builds' do
- expect(response).to have_http_status(401)
+ context 'when pipeline has no builds' do
+ before do
+ branch_head = project.commit('feature').id
+ get api("/projects/#{project.id}/repository/commits/#{branch_head}/builds", api_user)
+ end
+
+ it 'returns an empty array' do
+ expect(response).to have_http_status(200)
+ expect(json_response).to be_an Array
+ expect(json_response).to be_empty
+ end
+ end
+ end
+
+ context 'when user is not authorized' do
+ before do
+ create(:ci_pipeline, project: project, sha: project.commit.id)
+ create(:ci_build, pipeline: pipeline)
+
+ get api("/projects/#{project.id}/repository/commits/#{project.commit.id}/builds", nil)
+ end
+
+ it 'should not return project builds' do
+ expect(response).to have_http_status(401)
+ expect(json_response.except('message')).to be_empty
+ end
end
end
end