Skip to content

Commit b627e58

Browse files
authored
feat: add 'broker_catalog_ids' filter to /v3/service_offerings endpoint (#4805)
The /v3/service_plans endpoint allows query by broker_catalog_ids This makes the /v3/service_offerings endpoint consistent with that.
1 parent 544cac6 commit b627e58

File tree

6 files changed

+40
-0
lines changed

6 files changed

+40
-0
lines changed

app/fetchers/service_offering_list_fetcher.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ def fetch(message, omniscient: false, readable_orgs_query: nil, readable_spaces_
1515
private
1616

1717
def filter(message, dataset, klass)
18+
dataset = dataset.where(Sequel[:services][:unique_id] =~ message.broker_catalog_ids) if message.requested?(:broker_catalog_ids)
19+
1820
dataset = dataset.where(Sequel[:services][:label] =~ message.names) if message.requested?(:names)
1921

2022
dataset = dataset.where { Sequel[:services][:active] =~ message.available? } if message.requested?(:available)

app/messages/service_offerings_list_message.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
module VCAP::CloudController
55
class ServiceOfferingsListMessage < MetadataListMessage
66
@array_keys = %i[
7+
broker_catalog_ids
78
service_broker_guids
89
service_broker_names
910
names

docs/v3/source/includes/resources/service_offerings/_list.md.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Name | Type | Description
3232
---- | ---- | ------------
3333
**names** | _list of strings_ | Comma-delimited list of names to filter by
3434
**available** | _boolean_ | Filter by the `available` property; valid values are `true` or `false`
35+
**broker_catalog_ids** | _list of strings_ | Comma-delimited list of IDs provided by the service broker for the service offering to filter by
3536
**service_broker_guids** | _list of strings_ | Comma-delimited list of service broker GUIDs to filter by
3637
**service_broker_names** | _list of strings_ | Comma-delimited list of service broker names to filter by
3738
**space_guids** | _list of strings_ | Comma-delimited list of space GUIDs to filter by

spec/request/service_offerings_spec.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@
210210
let(:params) do
211211
{
212212
available: true,
213+
broker_catalog_ids: %w[catalog-id-1 catalog-id-2],
213214
service_broker_guids: %w[foo bar],
214215
service_broker_names: %w[baz qux],
215216
names: %w[quux quuz],
@@ -373,6 +374,20 @@
373374
end
374375
end
375376

377+
describe 'broker_catalog_ids' do
378+
let!(:service_offering_1) { VCAP::CloudController::ServicePlan.make(public: true).service }
379+
let!(:service_offering_2) { VCAP::CloudController::ServicePlan.make(public: true).service }
380+
let!(:service_offering_3) { VCAP::CloudController::ServicePlan.make(public: true).service }
381+
let!(:service_offering_4) { VCAP::CloudController::ServicePlan.make(public: true).service }
382+
383+
it 'filters by broker catalog id' do
384+
expect_filtered_service_offerings(
385+
"broker_catalog_ids=#{service_offering_1.unique_id},#{service_offering_3.unique_id}",
386+
[service_offering_1, service_offering_3]
387+
)
388+
end
389+
end
390+
376391
describe 'guids' do
377392
let!(:service_broker_1) { VCAP::CloudController::ServiceBroker.make(space:) }
378393
let!(:service_offering_1) { VCAP::CloudController::Service.make(service_broker: service_broker_1) }

spec/unit/fetchers/service_offering_list_fetcher_spec.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,24 @@ module VCAP::CloudController
397397
end
398398
end
399399

400+
describe 'the `broker_catalog_ids` filter' do
401+
let!(:service_offering_1) { VCAP::CloudController::ServicePlan.make(public: true).service }
402+
let!(:service_offering_2) { VCAP::CloudController::ServicePlan.make(public: true).service }
403+
let!(:service_offering_3) { VCAP::CloudController::ServicePlan.make(public: true).service }
404+
let!(:service_offering_4) { VCAP::CloudController::ServicePlan.make(public: true).service }
405+
406+
let(:message) do
407+
ServiceOfferingsListMessage.from_params({ broker_catalog_ids: [service_offering_1.unique_id, service_offering_4.unique_id].join(',') }.with_indifferent_access)
408+
end
409+
410+
it 'filters the service offerings with matching broker catalog IDs' do
411+
expect(service_offerings).to contain_exactly(
412+
service_offering_1,
413+
service_offering_4
414+
)
415+
end
416+
end
417+
400418
describe 'the `service_broker_guids` filter' do
401419
let!(:service_broker) { VCAP::CloudController::ServiceBroker.make }
402420
let!(:service_offering_1) do

spec/unit/messages/service_offerings_list_message_spec.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ module VCAP::CloudController
77
let(:params) do
88
{
99
'available' => 'true',
10+
'broker_catalog_ids' => 'broker_catalog_id_1,broker_catalog_id_2',
1011
'service_broker_guids' => 'one,two',
1112
'service_broker_names' => 'zhou,qin',
1213
'names' => 'service_offering1,other_2',
@@ -23,6 +24,7 @@ module VCAP::CloudController
2324
expect(message).to be_valid
2425
expect(message).to be_a(described_class)
2526
expect(message.available).to eq('true')
27+
expect(message.broker_catalog_ids).to eq(%w[broker_catalog_id_1 broker_catalog_id_2])
2628
expect(message.service_broker_guids).to eq(%w[one two])
2729
expect(message.service_broker_names).to eq(%w[zhou qin])
2830
expect(message.names).to eq(%w[service_offering1 other_2])
@@ -34,6 +36,7 @@ module VCAP::CloudController
3436
message = described_class.from_params(params)
3537

3638
expect(message).to be_requested(:available)
39+
expect(message).to be_requested(:broker_catalog_ids)
3740
expect(message).to be_requested(:names)
3841
expect(message).to be_requested(:service_broker_guids)
3942
expect(message).to be_requested(:service_broker_names)

0 commit comments

Comments
 (0)