Skip to content

Commit 4cbf379

Browse files
author
Stanislav Kolotinskiy
committed
Add update_v2_subscription endpoint in billing client
1 parent abfca51 commit 4cbf379

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

lib/travis/api/v3/billing_client.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ def create_v2_subscription(subscription_data)
9494
handle_v2_subscription_response(response)
9595
end
9696

97+
def update_v2_subscription(subscription_id, plan_data)
98+
response = connection.patch("/v2/subscriptions/#{subscription_id}/plan", plan_data)
99+
handle_v2_subscription_response(response)
100+
end
101+
97102
def cancel_subscription(id, reason_data)
98103
response = connection.post("/subscriptions/#{id}/cancel", reason_data)
99104
handle_subscription_response(response)

spec/v3/billing_client_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,20 @@
232232
end
233233
end
234234

235+
describe '#update_v2_subscription' do
236+
let(:plan_data) { { 'plan' => 'enterprise_tier_plan' } }
237+
subject { billing.update_v2_subscription(subscription_id, plan_data) }
238+
239+
it 'requests the update' do
240+
stubbed_request = stub_billing_request(:patch, "/v2/subscriptions/#{subscription_id}/plan", auth_key: auth_key, user_id: user_id)
241+
.with(body: JSON.dump(plan_data))
242+
.to_return(status: 204)
243+
244+
expect { subject }.to_not raise_error
245+
expect(stubbed_request).to have_been_made
246+
end
247+
end
248+
235249
describe '#pay' do
236250
subject { billing.pay(subscription_id) }
237251

0 commit comments

Comments
 (0)