Skip to content
This repository was archived by the owner on Jun 2, 2021. It is now read-only.

Commit ed6ea82

Browse files
pivotal-marcela-campoFelisiaM
authored andcommitted
Service plan include of service offering/space.organization
[#172649375](https://www.pivotaltracker.com/story/show/172649375)
1 parent f7134bd commit ed6ea82

6 files changed

Lines changed: 53 additions & 2 deletions

File tree

app/controllers/v3/service_plans_controller.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ def show
2525
service_plan_not_found! unless visible_to_current_user?(plan: service_plan)
2626

2727
decorators = []
28+
decorators << IncludeServicePlanSpaceOrganizationDecorator if IncludeServicePlanSpaceOrganizationDecorator.match?(message.include)
29+
decorators << IncludeServicePlanServiceOfferingDecorator if IncludeServicePlanServiceOfferingDecorator.match?(message.include)
2830
decorators << FieldServicePlanServiceBrokerDecorator.new(message.fields) if FieldServicePlanServiceBrokerDecorator.match?(message.fields)
2931

3032
presenter = Presenters::V3::ServicePlanPresenter.new(service_plan, decorators: decorators)
Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
11
module VCAP::CloudController
22
class ServicePlansShowMessage < BaseMessage
3-
register_allowed_keys [:fields]
3+
@array_keys = [
4+
:include
5+
]
6+
@single_keys = [
7+
:fields
8+
]
9+
10+
register_allowed_keys(@single_keys + @array_keys)
411

512
validates_with NoAdditionalParamsValidator
13+
validates_with IncludeParamValidator, valid_values: %w(space.organization service_offering)
614
validates :fields, allow_nil: true, fields: {
715
allowed: {
816
'service_offering.service_broker' => ['guid', 'name']
917
}
1018
}
1119

1220
def self.from_params(params)
13-
super(params, [], fields: %w(fields))
21+
super(params, @array_keys.map(&:to_s), fields: %w(fields))
1422
end
1523
end
1624
end

docs/v3/source/includes/concepts/_includes.md.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Resource | Allowed values
1919
**routes** | `domain`
2020
**routes/[:guid]** | `domain`
2121
**service_plans** | `space.organization`, `service_offering`
22+
**service_plans/[:guid]** | `space.organization`, `service_offering`
2223
**spaces** | `organization`
2324
**spaces/[:guid]** | `organization`
2425

docs/v3/source/includes/experimental_resources/service_plans/_get.md.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ This endpoint retrieves the service plan by GUID.
3131
Name | Type | Description
3232
---- | ---- | ------------
3333
**fields** | [_fields parameter_](#fields-parameter) | [_Allowed values_](#service-plan-fields)
34+
**include** | _list of strings_ | Optionally include a list of related resources in the response. <br>Valid values are `space.organization` and `service_offering`.
3435

3536
##### Service Plan Fields
3637

spec/request/service_plans_spec.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,34 @@
141141
expect(parsed_response['included']['service_brokers'][0]['name']).to eq(service_plan.service.service_broker.name)
142142
end
143143
end
144+
145+
describe 'includes' do
146+
it 'can include `space.organization`' do
147+
plan = generate_space_scoped_plan(space)
148+
guid = plan.guid
149+
150+
get "/v3/service_plans/#{guid}?include=space.organization", nil, admin_headers
151+
expect(last_response).to have_status_code(200)
152+
153+
expect(parsed_response['included']['spaces']).to have(1).element
154+
expect(parsed_response['included']['spaces'][0]['guid']).to eq(space.guid)
155+
156+
expect(parsed_response['included']['organizations']).to have(1).element
157+
expect(parsed_response['included']['organizations'][0]['guid']).to eq(space.organization.guid)
158+
end
159+
160+
it 'can include `service_offering`' do
161+
offering = VCAP::CloudController::Service.make
162+
plan = VCAP::CloudController::ServicePlan.make(service: offering)
163+
guid = plan.guid
164+
165+
get "/v3/service_plans/#{guid}?include=service_offering", nil, admin_headers
166+
expect(last_response).to have_status_code(200)
167+
168+
expect(parsed_response['included']['service_offerings']).to have(1).element
169+
expect(parsed_response['included']['service_offerings'][0]['guid']).to eq(offering.guid)
170+
end
171+
end
144172
end
145173

146174
describe 'GET /v3/service_plans' do

spec/unit/messages/service_plans_show_message_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ module VCAP::CloudController
88
let(:params) do
99
{
1010
'fields' => { 'service_offering.service_broker' => 'guid,name' },
11+
'include' => 'space.organization,service_offering',
1112
}.with_indifferent_access
1213
end
1314

@@ -17,11 +18,13 @@ module VCAP::CloudController
1718
expect(message).to be_valid
1819
expect(message).to be_a(described_class)
1920
expect(message.fields).to match({ 'service_offering.service_broker': ['guid', 'name'] })
21+
expect(message.include).to contain_exactly('space.organization', 'service_offering')
2022
end
2123

2224
it 'converts requested keys to symbols' do
2325
message = described_class.from_params(params)
2426
expect(message.requested?(:fields)).to be_truthy
27+
expect(message.requested?(:include)).to be_truthy
2528
end
2629

2730
it 'accepts an empty set' do
@@ -41,6 +44,14 @@ module VCAP::CloudController
4144

4245
it_behaves_like 'field query parameter', 'service_offering.service_broker', 'guid,name'
4346
end
47+
48+
context 'include' do
49+
it 'does not accept other values' do
50+
message = described_class.from_params({ include: 'space' }.with_indifferent_access)
51+
expect(message).not_to be_valid
52+
expect(message.errors[:base]).to include(include("Invalid included resource: 'space'"))
53+
end
54+
end
4455
end
4556
end
4657
end

0 commit comments

Comments
 (0)