Skip to content

Commit 8e1672b

Browse files
authored
Minor refactor of v2 endpoints (#4140)
1 parent 2868f02 commit 8e1672b

File tree

4 files changed

+51
-38
lines changed

4 files changed

+51
-38
lines changed

app/controllers/services/managed_service_instances_controller.rb

Lines changed: 0 additions & 12 deletions
This file was deleted.

app/controllers/services/service_instances_controller.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
require 'presenters/v2/service_instance_shared_from_presenter'
1111

1212
module VCAP::CloudController
13+
# rubocop:disable Metrics/ClassLength
1314
class ServiceInstancesController < RestController::ModelController
1415
include VCAP::CloudController::LockCheck
1516

@@ -142,6 +143,10 @@ def update(guid)
142143
raise CloudController::Errors::ApiError.new_from_details('AsyncServiceBindingOperationInProgress', e.service_binding.app.name, e.service_binding.service_instance.name)
143144
end
144145

146+
deprecated_endpoint '/v2/managed_service_instances'
147+
get '/v2/managed_service_instances', :enumerate
148+
get '/v2/managed_service_instances/:guid', :read
149+
145150
def read(guid)
146151
service_instance = find_guid_and_validate_access(:read, guid, ServiceInstance)
147152

@@ -597,4 +602,5 @@ def projected_service_instance(service_instance)
597602
service_instance.clone.set(request_attrs.select { |k, _v| ServiceInstanceUpdate::KEYS_TO_UPDATE_CC.include? k })
598603
end
599604
end
605+
# rubocop:enable Metrics/ClassLength
600606
end

spec/unit/controllers/services/managed_service_instances_controller_spec.rb

Lines changed: 0 additions & 26 deletions
This file was deleted.

spec/unit/controllers/services/service_instances_controller_spec.rb

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,6 +1123,28 @@ def stub_delete_and_return(status, body)
11231123
end
11241124
end
11251125

1126+
describe 'GET', '/v2/managed_service_instances' do
1127+
let(:service_instance) { ManagedServiceInstance.make(gateway_name: Sham.name) }
1128+
let(:space) { service_instance.space }
1129+
let(:developer) { make_developer_for_space(space) }
1130+
1131+
it 'is deprecated' do
1132+
set_current_user(developer)
1133+
get '/v2/managed_service_instances'
1134+
expect(last_response).to be_a_deprecated_response
1135+
end
1136+
1137+
it 'behaves the same as /v2/service_instances/' do
1138+
set_current_user(developer)
1139+
get '/v2/managed_service_instances'
1140+
deprecated_response = last_response
1141+
expect(deprecated_response).to have_status_code(200)
1142+
get '/v2/service_instances'
1143+
new_response = last_response
1144+
expect(new_response.body).to eq(deprecated_response.body)
1145+
end
1146+
end
1147+
11261148
describe 'GET /v2/service_instances' do
11271149
context 'dashboard_url' do
11281150
let(:service_instance) { ManagedServiceInstance.make(gateway_name: Sham.name) }
@@ -1535,6 +1557,29 @@ def stub_delete_and_return(status, body)
15351557
end
15361558
end
15371559

1560+
describe 'GET', '/v2/managed_service_instances/:guid' do
1561+
let(:space) { Space.make }
1562+
let(:developer) { make_developer_for_space(space) }
1563+
let(:service_instance) { ManagedServiceInstance.make(space:) }
1564+
let(:service_plan) { ServicePlan.make(active: false) }
1565+
1566+
it 'is deprecated' do
1567+
set_current_user(developer)
1568+
get "v2/managed_service_instances/#{service_instance.guid}"
1569+
expect(last_response).to be_a_deprecated_response
1570+
end
1571+
1572+
it 'behaves the same as /v2/service_instances/:guid' do
1573+
set_current_user(developer)
1574+
get "v2/managed_service_instances/#{service_instance.guid}"
1575+
deprecated_response = last_response
1576+
expect(deprecated_response).to have_status_code(200)
1577+
get "v2/service_instances/#{service_instance.guid}"
1578+
new_response = last_response
1579+
expect(new_response.body).to eq(deprecated_response.body)
1580+
end
1581+
end
1582+
15381583
describe 'GET /v2/service_instances/:service_instance_guid' do
15391584
let(:space) { service_instance.space }
15401585
let(:developer) { make_developer_for_space(space) }

0 commit comments

Comments
 (0)