1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
|
require 'spec_helper'
describe API::API, api: true do
include ApiHelpers
let(:user) { create(:user) }
let(:user2) { create(:user) }
let!(:project) { create(:project, creator_id: user.id) }
let!(:developer) { create(:project_member, user: user, project: project, access_level: ProjectMember::DEVELOPER) }
let!(:reporter) { create(:project_member, user: user2, project: project, access_level: ProjectMember::REPORTER) }
let(:commit) { create(:ci_commit, project: project)}
let(:build) { create(:ci_build, commit: commit) }
let(:build_with_trace) { create(:ci_build_with_trace, commit: commit) }
let(:build_canceled) { create(:ci_build, :canceled, commit: commit) }
describe 'GET /projects/:id/builds ' do
context 'authorized user' do
it 'should return project builds' do
get api("/projects/#{project.id}/builds", user)
expect(response.status).to eq(200)
expect(json_response).to be_an Array
end
it 'should filter project with one scope element' do
get api("/projects/#{project.id}/builds?scope=pending", user)
expect(response.status).to eq(200)
expect(json_response).to be_an Array
end
it 'should filter project with array of scope elements' do
get api("/projects/#{project.id}/builds?scope[0]=pending&scope[1]=running", user)
expect(response.status).to eq(200)
expect(json_response).to be_an Array
end
it 'should respond 400 when scope contains invalid state' do
get api("/projects/#{project.id}/builds?scope[0]=pending&scope[1]=unknown_status", user)
expect(response.status).to eq(400)
end
end
context 'unauthorized user' do
it 'should not return project builds' do
get api("/projects/#{project.id}/builds")
expect(response.status).to eq(401)
end
end
end
describe 'GET /projects/:id/repository/commits/:sha/builds' do
context 'authorized user' do
it 'should return project builds for specific commit' do
project.ensure_ci_commit(commit.sha)
get api("/projects/#{project.id}/repository/commits/#{commit.sha}/builds", user)
expect(response.status).to eq(200)
expect(json_response).to be_an Array
end
end
context 'unauthorized user' do
it 'should not return project builds' do
project.ensure_ci_commit(commit.sha)
get api("/projects/#{project.id}/repository/commits/#{commit.sha}/builds")
expect(response.status).to eq(401)
end
end
end
describe 'GET /projects/:id/builds/:build_id' do
context 'authorized user' do
it 'should return specific build data' do
get api("/projects/#{project.id}/builds/#{build.id}", user)
expect(response.status).to eq(200)
expect(json_response['name']).to eq('test')
end
end
context 'unauthorized user' do
it 'should not return specific build data' do
get api("/projects/#{project.id}/builds/#{build.id}")
expect(response.status).to eq(401)
end
end
end
describe 'GET /projects/:id/builds/:build_id/trace' do
context 'authorized user' do
it 'should return specific build trace' do
get api("/projects/#{project.id}/builds/#{build_with_trace.id}/trace", user)
expect(response.status).to eq(200)
expect(response.body).to eq(build_with_trace.trace)
end
end
context 'unauthorized user' do
it 'should not return specific build trace' do
get api("/projects/#{project.id}/builds/#{build_with_trace.id}/trace")
expect(response.status).to eq(401)
end
end
end
describe 'POST /projects/:id/builds/:build_id/cancel' do
context 'authorized user' do
context 'user with :update_build persmission' do
it 'should cancel running or pending build' do
post api("/projects/#{project.id}/builds/#{build.id}/cancel", user)
expect(response.status).to eq(201)
expect(project.builds.first.status).to eq('canceled')
end
end
context 'user without :update_build permission' do
it 'should not cancel build' do
post api("/projects/#{project.id}/builds/#{build.id}/cancel", user2)
expect(response.status).to eq(403)
end
end
end
context 'unauthorized user' do
it 'should not cancel build' do
post api("/projects/#{project.id}/builds/#{build.id}/cancel")
expect(response.status).to eq(401)
end
end
end
describe 'POST /projects/:id/builds/:build_id/retry' do
context 'authorized user' do
context 'user with :update_build persmission' do
it 'should retry non-running build' do
post api("/projects/#{project.id}/builds/#{build_canceled.id}/retry", user)
expect(response.status).to eq(201)
expect(project.builds.first.status).to eq('canceled')
expect(json_response['status']).to eq('pending')
end
end
context 'user without :update_build permission' do
it 'should not retry build' do
post api("/projects/#{project.id}/builds/#{build_canceled.id}/retry", user2)
expect(response.status).to eq(403)
end
end
end
context 'unauthorized user' do
it 'should not retry build' do
post api("/projects/#{project.id}/builds/#{build_canceled.id}/retry")
expect(response.status).to eq(401)
end
end
end
end
|