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

Commit e440137

Browse files
committed
v3(services): space filtering include org offerings
There was an issue where filtering service offerings by space_guids would not include org-restricted offerings, which was inconsistent with service plans and with the design for V3 service visibility. This was corrected in a previous commit by sharing code between the offering and plan fetchers, and this commit adds integration testing to check the behaviors for offering and plans, with space_guids and organization_guids. [#175415141](https://www.pivotaltracker.com/story/show/175415141)
1 parent a129c1f commit e440137

File tree

2 files changed

+80
-42
lines changed

2 files changed

+80
-42
lines changed

spec/request/service_offerings_spec.rb

Lines changed: 48 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -398,53 +398,67 @@
398398
end
399399

400400
describe 'space_guids' do
401-
let!(:service_broker_1) { VCAP::CloudController::ServiceBroker.make(space: space) }
402-
let!(:service_offering_1) { VCAP::CloudController::Service.make(service_broker: service_broker_1) }
401+
let(:org_1) { VCAP::CloudController::Organization.make }
402+
let(:org_2) { VCAP::CloudController::Organization.make }
403+
let!(:org_plan_1) { VCAP::CloudController::ServicePlan.make(public: false) }
404+
let!(:org_plan_2) { VCAP::CloudController::ServicePlan.make(public: false) }
405+
let!(:org_offering_1) { org_plan_1.service }
406+
let!(:org_offering_2) { org_plan_2.service }
403407

404-
let(:space_2) { VCAP::CloudController::Space.make(organization: org) }
405-
let(:service_broker_2) { VCAP::CloudController::ServiceBroker.make(space: space_2) }
406-
let!(:service_offering_2) { VCAP::CloudController::Service.make(service_broker: service_broker_2) }
408+
let(:space_1) { VCAP::CloudController::Space.make(organization: org_1) }
409+
let(:space_2) { VCAP::CloudController::Space.make(organization: org_2) }
410+
let!(:space_offering_1) { generate_space_scoped_offering(space_1) }
411+
let!(:space_offering_2) { generate_space_scoped_offering(space_2) }
407412

408-
let(:space_3) { VCAP::CloudController::Space.make(organization: org) }
409-
let(:service_broker_3) { VCAP::CloudController::ServiceBroker.make(space: space_3) }
410-
let!(:service_offering_3) { VCAP::CloudController::Service.make(service_broker: service_broker_3) }
413+
let!(:public_offering) { VCAP::CloudController::ServicePlan.make(public: true).service }
411414

412-
let!(:public_plan) { VCAP::CloudController::ServicePlan.make(public: true) }
413-
let!(:public_service_offering) { public_plan.service }
415+
before do
416+
VCAP::CloudController::ServicePlanVisibility.make(service_plan: org_plan_1, organization: org_1)
417+
VCAP::CloudController::ServicePlanVisibility.make(service_plan: org_plan_2, organization: org_2)
418+
end
414419

415-
let!(:space_guids) { [space.guid, space_2.guid] }
420+
it 'selects on space plans, org plans, and public plans' do
421+
expect_filtered_service_offerings(
422+
"space_guids=#{space_1.guid}",
423+
[org_offering_1, space_offering_1, public_offering]
424+
)
416425

417-
it 'returns the right offerings' do
418426
expect_filtered_service_offerings(
419-
"space_guids=#{space_guids.join(',')}",
420-
[service_offering_1, service_offering_2, public_service_offering]
427+
"space_guids=#{space_1.guid},#{space_2.guid}",
428+
[org_offering_1, org_offering_2, space_offering_1, space_offering_2, public_offering]
421429
)
422430
end
423431
end
424432

425433
describe 'organization_guids' do
426-
let!(:service_broker_1) { VCAP::CloudController::ServiceBroker.make(space: space) }
427-
let!(:service_offering_1) { VCAP::CloudController::Service.make(service_broker: service_broker_1) }
428-
434+
let(:org_1) { VCAP::CloudController::Organization.make }
429435
let(:org_2) { VCAP::CloudController::Organization.make }
436+
let!(:org_plan_1) { VCAP::CloudController::ServicePlan.make(public: false) }
437+
let!(:org_plan_2) { VCAP::CloudController::ServicePlan.make(public: false) }
438+
let!(:org_offering_1) { org_plan_1.service }
439+
let!(:org_offering_2) { org_plan_2.service }
440+
441+
let(:space_1) { VCAP::CloudController::Space.make(organization: org_1) }
430442
let(:space_2) { VCAP::CloudController::Space.make(organization: org_2) }
431-
let(:service_broker_2) { VCAP::CloudController::ServiceBroker.make(space: space_2) }
432-
let!(:service_offering_2) { VCAP::CloudController::Service.make(service_broker: service_broker_2) }
443+
let!(:space_offering_1) { generate_space_scoped_offering(space_1) }
444+
let!(:space_offering_2) { generate_space_scoped_offering(space_2) }
433445

434-
let(:org_3) { VCAP::CloudController::Organization.make }
435-
let(:space_3) { VCAP::CloudController::Space.make(organization: org_3) }
436-
let(:service_broker_3) { VCAP::CloudController::ServiceBroker.make(space: space_3) }
437-
let!(:service_offering_3) { VCAP::CloudController::Service.make(service_broker: service_broker_3) }
446+
let!(:public_offering) { VCAP::CloudController::ServicePlan.make(public: true).service }
438447

439-
let!(:public_plan) { VCAP::CloudController::ServicePlan.make(public: true) }
440-
let!(:public_service_offering) { public_plan.service }
448+
before do
449+
VCAP::CloudController::ServicePlanVisibility.make(service_plan: org_plan_1, organization: org_1)
450+
VCAP::CloudController::ServicePlanVisibility.make(service_plan: org_plan_2, organization: org_2)
451+
end
441452

442-
let!(:org_guids) { [org.guid, org_2.guid] }
453+
it 'selects on space plans, org plans, and public plans' do
454+
expect_filtered_service_offerings(
455+
"organization_guids=#{org_1.guid}",
456+
[org_offering_1, space_offering_1, public_offering]
457+
)
443458

444-
it 'returns the right offerings' do
445459
expect_filtered_service_offerings(
446-
"organization_guids=#{org_guids.join(',')}",
447-
[service_offering_1, service_offering_2, public_service_offering]
460+
"organization_guids=#{org_1.guid},#{org_2.guid}",
461+
[org_offering_1, org_offering_2, space_offering_1, space_offering_2, public_offering]
448462
)
449463
end
450464
end
@@ -971,4 +985,9 @@ def expect_filtered_service_offerings(filter, list)
971985
expect(parsed_response['resources'][index]['guid']).to eq(service_offering.guid)
972986
end
973987
end
988+
989+
def generate_space_scoped_offering(space)
990+
broker = VCAP::CloudController::ServiceBroker.make(space: space)
991+
VCAP::CloudController::Service.make(service_broker: broker)
992+
end
974993
end

spec/request/service_plans_spec.rb

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -338,35 +338,54 @@
338338
describe 'organization_guids' do
339339
let(:org_1) { VCAP::CloudController::Organization.make }
340340
let(:org_2) { VCAP::CloudController::Organization.make }
341-
let(:plan_1) { VCAP::CloudController::ServicePlan.make(public: false) }
342-
let(:plan_2) { VCAP::CloudController::ServicePlan.make(public: false) }
341+
let!(:org_plan_1) { VCAP::CloudController::ServicePlan.make(public: false) }
342+
let!(:org_plan_2) { VCAP::CloudController::ServicePlan.make(public: false) }
343+
344+
let(:space_1){VCAP::CloudController::Space.make(organization: org_1)}
345+
let(:space_2){VCAP::CloudController::Space.make(organization: org_2)}
346+
let!(:space_plan_1) {generate_space_scoped_plan(space_1)}
347+
let!(:space_plan_2) {generate_space_scoped_plan(space_2)}
348+
349+
let!(:public_plan){VCAP::CloudController::ServicePlan.make(public: true)}
343350

344351
before do
345-
VCAP::CloudController::ServicePlanVisibility.make(service_plan: plan_1, organization: org_1)
346-
VCAP::CloudController::ServicePlanVisibility.make(service_plan: plan_2, organization: org_2)
352+
VCAP::CloudController::ServicePlanVisibility.make(service_plan: org_plan_1, organization: org_1)
353+
VCAP::CloudController::ServicePlanVisibility.make(service_plan: org_plan_2, organization: org_2)
347354
end
348355

349-
it 'selects on org guid' do
356+
it 'selects on org plans, space plans and public plans' do
350357
get "/v3/service_plans?organization_guids=#{org_1.guid}", {}, admin_headers
351-
check_filtered_plans(plan_1)
358+
check_filtered_plans(org_plan_1, space_plan_1, public_plan)
359+
360+
get "/v3/service_plans?organization_guids=#{org_1.guid},#{org_2.guid}", {}, admin_headers
361+
check_filtered_plans(org_plan_1, org_plan_2, space_plan_1, space_plan_2, public_plan)
352362
end
353363
end
354364

355365
describe 'space_guids' do
356366
let(:org_1) { VCAP::CloudController::Organization.make }
357367
let(:org_2) { VCAP::CloudController::Organization.make }
358-
let(:plan_1) { VCAP::CloudController::ServicePlan.make(public: false) }
359-
let(:plan_2) { VCAP::CloudController::ServicePlan.make(public: false) }
360-
let(:space_1) { VCAP::CloudController::Space.make(organization: org_1) }
368+
let!(:org_plan_1) { VCAP::CloudController::ServicePlan.make(public: false) }
369+
let!(:org_plan_2) { VCAP::CloudController::ServicePlan.make(public: false) }
370+
371+
let(:space_1){VCAP::CloudController::Space.make(organization: org_1)}
372+
let(:space_2){VCAP::CloudController::Space.make(organization: org_2)}
373+
let!(:space_plan_1) {generate_space_scoped_plan(space_1)}
374+
let!(:space_plan_2) {generate_space_scoped_plan(space_2)}
375+
376+
let!(:public_plan){VCAP::CloudController::ServicePlan.make(public: true)}
361377

362378
before do
363-
VCAP::CloudController::ServicePlanVisibility.make(service_plan: plan_1, organization: org_1)
364-
VCAP::CloudController::ServicePlanVisibility.make(service_plan: plan_2, organization: org_2)
379+
VCAP::CloudController::ServicePlanVisibility.make(service_plan: org_plan_1, organization: org_1)
380+
VCAP::CloudController::ServicePlanVisibility.make(service_plan: org_plan_2, organization: org_2)
365381
end
366382

367-
it 'selects on org guid' do
383+
it 'selects on org plans, space plans and public plans' do
368384
get "/v3/service_plans?space_guids=#{space_1.guid}", {}, admin_headers
369-
check_filtered_plans(plan_1)
385+
check_filtered_plans(org_plan_1, space_plan_1, public_plan)
386+
387+
get "/v3/service_plans?space_guids=#{space_1.guid},#{space_2.guid}", {}, admin_headers
388+
check_filtered_plans(org_plan_1, org_plan_2, space_plan_1, space_plan_2, public_plan)
370389
end
371390
end
372391

0 commit comments

Comments
 (0)