Skip to content

Commit a3bb95f

Browse files
author
Shairyar Baig
authored
Merge pull request #1162 from travis-ci/pd-fix-restart-for-legacy-plans
Rescue NotFound exception when authorizing build restart
2 parents b450b70 + 291048f commit a3bb95f

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

lib/travis/api/enqueue/services/restart_model.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ def billing?
4444
rescue Travis::API::V3::InsufficientAccess => e
4545
@cause_of_denial = e.message
4646
false
47+
rescue Travis::API::V3::NotFound
48+
# Owner is on a legacy plan
49+
true
4750
end
4851
end
4952

spec/v3/services/job/restart_spec.rb

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,47 @@
219219
example { expect(Sidekiq::Client.last['class']).to be == 'Travis::Hub::Sidekiq::Worker' }
220220
end
221221

222+
context 'billing authorization' do
223+
context 'billing service authorizes the job' do
224+
before do
225+
stub_request(:post, /http:\/\/localhost:9292\/(users|organizations)\/(.+)\/authorize_build/).to_return(
226+
body: MultiJson.dump(allowed: true, rejection_code: :nil), status: 200
227+
)
228+
end
229+
230+
it 'restarts the job' do
231+
post("/v3/job/#{job.id}/restart", params, headers)
232+
expect(last_response.status).to eq(202)
233+
end
234+
end
235+
236+
context 'billing service returns 404 (user is not on a new plan)' do
237+
before do
238+
stub_request(:post, /http:\/\/localhost:9292\/(users|organizations)\/(.+)\/authorize_build/).to_return(
239+
body: MultiJson.dump(error: 'Plan not found'), status: 404
240+
)
241+
end
242+
243+
it 'restarts the job' do
244+
post("/v3/job/#{job.id}/restart", params, headers)
245+
expect(last_response.status).to eq(202)
246+
end
247+
end
248+
249+
context 'billing service rejects the job' do
250+
before do
251+
stub_request(:post, /http:\/\/localhost:9292\/(users|organizations)\/(.+)\/authorize_build/).to_return(
252+
body: MultiJson.dump(allowed: false, rejection_code: :no_build_credits), status: 403
253+
)
254+
end
255+
256+
it 'does not restart the job' do
257+
post("/v3/job/#{job.id}/restart", params, headers)
258+
expect(last_response.status).to eq(403)
259+
end
260+
end
261+
end
262+
222263
describe "passed state" do
223264
include_examples 'clears debug_options'
224265

0 commit comments

Comments
 (0)