Skip to content

Commit

Permalink
v3(services): space filtering include org offerings
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
blgm committed Oct 27, 2020
1 parent a129c1f commit e440137
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 42 deletions.
77 changes: 48 additions & 29 deletions spec/request/service_offerings_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -398,53 +398,67 @@
end

describe 'space_guids' do
let!(:service_broker_1) { VCAP::CloudController::ServiceBroker.make(space: space) }
let!(:service_offering_1) { VCAP::CloudController::Service.make(service_broker: service_broker_1) }
let(:org_1) { VCAP::CloudController::Organization.make }
let(:org_2) { VCAP::CloudController::Organization.make }
let!(:org_plan_1) { VCAP::CloudController::ServicePlan.make(public: false) }
let!(:org_plan_2) { VCAP::CloudController::ServicePlan.make(public: false) }
let!(:org_offering_1) { org_plan_1.service }
let!(:org_offering_2) { org_plan_2.service }

let(:space_2) { VCAP::CloudController::Space.make(organization: org) }
let(:service_broker_2) { VCAP::CloudController::ServiceBroker.make(space: space_2) }
let!(:service_offering_2) { VCAP::CloudController::Service.make(service_broker: service_broker_2) }
let(:space_1) { VCAP::CloudController::Space.make(organization: org_1) }
let(:space_2) { VCAP::CloudController::Space.make(organization: org_2) }
let!(:space_offering_1) { generate_space_scoped_offering(space_1) }
let!(:space_offering_2) { generate_space_scoped_offering(space_2) }

let(:space_3) { VCAP::CloudController::Space.make(organization: org) }
let(:service_broker_3) { VCAP::CloudController::ServiceBroker.make(space: space_3) }
let!(:service_offering_3) { VCAP::CloudController::Service.make(service_broker: service_broker_3) }
let!(:public_offering) { VCAP::CloudController::ServicePlan.make(public: true).service }

let!(:public_plan) { VCAP::CloudController::ServicePlan.make(public: true) }
let!(:public_service_offering) { public_plan.service }
before do
VCAP::CloudController::ServicePlanVisibility.make(service_plan: org_plan_1, organization: org_1)
VCAP::CloudController::ServicePlanVisibility.make(service_plan: org_plan_2, organization: org_2)
end

let!(:space_guids) { [space.guid, space_2.guid] }
it 'selects on space plans, org plans, and public plans' do
expect_filtered_service_offerings(
"space_guids=#{space_1.guid}",
[org_offering_1, space_offering_1, public_offering]
)

it 'returns the right offerings' do
expect_filtered_service_offerings(
"space_guids=#{space_guids.join(',')}",
[service_offering_1, service_offering_2, public_service_offering]
"space_guids=#{space_1.guid},#{space_2.guid}",
[org_offering_1, org_offering_2, space_offering_1, space_offering_2, public_offering]
)
end
end

describe 'organization_guids' do
let!(:service_broker_1) { VCAP::CloudController::ServiceBroker.make(space: space) }
let!(:service_offering_1) { VCAP::CloudController::Service.make(service_broker: service_broker_1) }

let(:org_1) { VCAP::CloudController::Organization.make }
let(:org_2) { VCAP::CloudController::Organization.make }
let!(:org_plan_1) { VCAP::CloudController::ServicePlan.make(public: false) }
let!(:org_plan_2) { VCAP::CloudController::ServicePlan.make(public: false) }
let!(:org_offering_1) { org_plan_1.service }
let!(:org_offering_2) { org_plan_2.service }

let(:space_1) { VCAP::CloudController::Space.make(organization: org_1) }
let(:space_2) { VCAP::CloudController::Space.make(organization: org_2) }
let(:service_broker_2) { VCAP::CloudController::ServiceBroker.make(space: space_2) }
let!(:service_offering_2) { VCAP::CloudController::Service.make(service_broker: service_broker_2) }
let!(:space_offering_1) { generate_space_scoped_offering(space_1) }
let!(:space_offering_2) { generate_space_scoped_offering(space_2) }

let(:org_3) { VCAP::CloudController::Organization.make }
let(:space_3) { VCAP::CloudController::Space.make(organization: org_3) }
let(:service_broker_3) { VCAP::CloudController::ServiceBroker.make(space: space_3) }
let!(:service_offering_3) { VCAP::CloudController::Service.make(service_broker: service_broker_3) }
let!(:public_offering) { VCAP::CloudController::ServicePlan.make(public: true).service }

let!(:public_plan) { VCAP::CloudController::ServicePlan.make(public: true) }
let!(:public_service_offering) { public_plan.service }
before do
VCAP::CloudController::ServicePlanVisibility.make(service_plan: org_plan_1, organization: org_1)
VCAP::CloudController::ServicePlanVisibility.make(service_plan: org_plan_2, organization: org_2)
end

let!(:org_guids) { [org.guid, org_2.guid] }
it 'selects on space plans, org plans, and public plans' do
expect_filtered_service_offerings(
"organization_guids=#{org_1.guid}",
[org_offering_1, space_offering_1, public_offering]
)

it 'returns the right offerings' do
expect_filtered_service_offerings(
"organization_guids=#{org_guids.join(',')}",
[service_offering_1, service_offering_2, public_service_offering]
"organization_guids=#{org_1.guid},#{org_2.guid}",
[org_offering_1, org_offering_2, space_offering_1, space_offering_2, public_offering]
)
end
end
Expand Down Expand Up @@ -971,4 +985,9 @@ def expect_filtered_service_offerings(filter, list)
expect(parsed_response['resources'][index]['guid']).to eq(service_offering.guid)
end
end

def generate_space_scoped_offering(space)
broker = VCAP::CloudController::ServiceBroker.make(space: space)
VCAP::CloudController::Service.make(service_broker: broker)
end
end
45 changes: 32 additions & 13 deletions spec/request/service_plans_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -338,35 +338,54 @@
describe 'organization_guids' do
let(:org_1) { VCAP::CloudController::Organization.make }
let(:org_2) { VCAP::CloudController::Organization.make }
let(:plan_1) { VCAP::CloudController::ServicePlan.make(public: false) }
let(:plan_2) { VCAP::CloudController::ServicePlan.make(public: false) }
let!(:org_plan_1) { VCAP::CloudController::ServicePlan.make(public: false) }
let!(:org_plan_2) { VCAP::CloudController::ServicePlan.make(public: false) }

let(:space_1){VCAP::CloudController::Space.make(organization: org_1)}
let(:space_2){VCAP::CloudController::Space.make(organization: org_2)}
let!(:space_plan_1) {generate_space_scoped_plan(space_1)}
let!(:space_plan_2) {generate_space_scoped_plan(space_2)}

let!(:public_plan){VCAP::CloudController::ServicePlan.make(public: true)}

before do
VCAP::CloudController::ServicePlanVisibility.make(service_plan: plan_1, organization: org_1)
VCAP::CloudController::ServicePlanVisibility.make(service_plan: plan_2, organization: org_2)
VCAP::CloudController::ServicePlanVisibility.make(service_plan: org_plan_1, organization: org_1)
VCAP::CloudController::ServicePlanVisibility.make(service_plan: org_plan_2, organization: org_2)
end

it 'selects on org guid' do
it 'selects on org plans, space plans and public plans' do
get "/v3/service_plans?organization_guids=#{org_1.guid}", {}, admin_headers
check_filtered_plans(plan_1)
check_filtered_plans(org_plan_1, space_plan_1, public_plan)

get "/v3/service_plans?organization_guids=#{org_1.guid},#{org_2.guid}", {}, admin_headers
check_filtered_plans(org_plan_1, org_plan_2, space_plan_1, space_plan_2, public_plan)
end
end

describe 'space_guids' do
let(:org_1) { VCAP::CloudController::Organization.make }
let(:org_2) { VCAP::CloudController::Organization.make }
let(:plan_1) { VCAP::CloudController::ServicePlan.make(public: false) }
let(:plan_2) { VCAP::CloudController::ServicePlan.make(public: false) }
let(:space_1) { VCAP::CloudController::Space.make(organization: org_1) }
let!(:org_plan_1) { VCAP::CloudController::ServicePlan.make(public: false) }
let!(:org_plan_2) { VCAP::CloudController::ServicePlan.make(public: false) }

let(:space_1){VCAP::CloudController::Space.make(organization: org_1)}
let(:space_2){VCAP::CloudController::Space.make(organization: org_2)}
let!(:space_plan_1) {generate_space_scoped_plan(space_1)}
let!(:space_plan_2) {generate_space_scoped_plan(space_2)}

let!(:public_plan){VCAP::CloudController::ServicePlan.make(public: true)}

before do
VCAP::CloudController::ServicePlanVisibility.make(service_plan: plan_1, organization: org_1)
VCAP::CloudController::ServicePlanVisibility.make(service_plan: plan_2, organization: org_2)
VCAP::CloudController::ServicePlanVisibility.make(service_plan: org_plan_1, organization: org_1)
VCAP::CloudController::ServicePlanVisibility.make(service_plan: org_plan_2, organization: org_2)
end

it 'selects on org guid' do
it 'selects on org plans, space plans and public plans' do
get "/v3/service_plans?space_guids=#{space_1.guid}", {}, admin_headers
check_filtered_plans(plan_1)
check_filtered_plans(org_plan_1, space_plan_1, public_plan)

get "/v3/service_plans?space_guids=#{space_1.guid},#{space_2.guid}", {}, admin_headers
check_filtered_plans(org_plan_1, org_plan_2, space_plan_1, space_plan_2, public_plan)
end
end

Expand Down

0 comments on commit e440137

Please sign in to comment.