Skip to content

Commit

Permalink
Organized tests for viewing shared spaces for a route
Browse files Browse the repository at this point in the history
Co-authored-by: Rebecca Roberts <[email protected]>
Co-authored-by: Merric de Launey <[email protected]>
  • Loading branch information
rroberts2222 and MerricdeLauney committed May 31, 2022
1 parent 0ee2a98 commit 81b5b65
Showing 1 changed file with 79 additions and 66 deletions.
145 changes: 79 additions & 66 deletions spec/request/routes_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2591,6 +2591,85 @@
end
end

describe 'GET /v3/routes/:guid/relationships/shared_spaces' do
let(:api_call) { lambda { |user_headers| get "/v3/routes/#{guid}/relationships/shared_spaces", nil, user_headers } }
let(:target_space_1) { VCAP::CloudController::Space.make(organization: org) }
let(:route) {
route = VCAP::CloudController::Route.make(space: space)
route.add_shared_space(target_space_1)
route
}
let(:guid) { route.guid }
let(:space_dev_headers) do
org.add_user(user)
space.add_developer(user)
headers_for(user)
end
let!(:feature_flag) do
VCAP::CloudController::FeatureFlag.make(name: 'route_sharing', enabled: true, error_message: nil)
end

before do
org.add_user(user)
target_space_1.add_developer(user)
end

describe 'permissions' do
it_behaves_like 'permissions for single object endpoint', ALL_PERMISSIONS do
let(:expected_codes_and_responses) do
h = Hash.new(code: 200, response_object: {
data: [
{
guid: target_space_1.guid
}
],
links: {
self: { href: %r(#{Regexp.escape(link_prefix)}\/v3\/routes\/#{route.guid}\/relationships\/shared_spaces) },
}
})

h['org_billing_manager'] = { code: 404 }
h['no_role'] = { code: 404 }
h
end
end
end

describe 'when route_sharing flag is disabled' do
before do
feature_flag.enabled = false
feature_flag.save
end

it 'makes users unable to unshare routes' do
api_call.call(space_dev_headers)

expect(last_response).to have_status_code(403)
expect(parsed_response['errors']).to include(
include(
{
'detail' => 'Feature Disabled: route_sharing',
'title' => 'CF-FeatureDisabled',
'code' => 330002,
})
)
end
end

it 'responds with 404 when the route does not exist' do
get '/v3/routes/some-fake-guid/relationships/shared_spaces', nil, space_dev_headers

expect(last_response).to have_status_code(404)
expect(parsed_response['errors']).to include(
include(
{
'detail' => 'Route not found',
'title' => 'CF-ResourceNotFound'
})
)
end
end

describe 'POST /v3/routes/:guid/relationships/shared_spaces' do
let(:api_call) { lambda { |user_headers| post "/v3/routes/#{guid}/relationships/shared_spaces", request_body.to_json, user_headers } }
let(:target_space_1) { VCAP::CloudController::Space.make(organization: org) }
Expand Down Expand Up @@ -2864,72 +2943,6 @@
end
end

describe 'GET /v3/routes/:guid/relationships/shared_spaces' do
let(:api_call) { lambda { |user_headers| get "/v3/routes/#{guid}/relationships/shared_spaces", nil, user_headers } }
let(:target_space_1) { VCAP::CloudController::Space.make(organization: org) }
let(:route) {
route = VCAP::CloudController::Route.make(space: space)
route.add_shared_space(target_space_1)
route
}
let(:guid) { route.guid }
let(:space_dev_headers) do
org.add_user(user)
space.add_developer(user)
headers_for(user)
end
let!(:feature_flag) do
VCAP::CloudController::FeatureFlag.make(name: 'route_sharing', enabled: true, error_message: nil)
end

before do
org.add_user(user)
target_space_1.add_developer(user)
end

describe 'permissions' do
it_behaves_like 'permissions for single object endpoint', ALL_PERMISSIONS do
let(:expected_codes_and_responses) do
h = Hash.new(code: 200, response_object: {
data: [
{
guid: target_space_1.guid
}
],
links: {
self: { href: %r(#{Regexp.escape(link_prefix)}\/v3\/routes\/#{route.guid}\/relationships\/shared_spaces) },
}
})

h['org_billing_manager'] = { code: 404 }
h['no_role'] = { code: 404 }
h
end
end
end

describe 'when route_sharing flag is disabled' do
before do
feature_flag.enabled = false
feature_flag.save
end

it 'makes users unable to unshare routes' do
api_call.call(space_dev_headers)

expect(last_response).to have_status_code(403)
expect(parsed_response['errors']).to include(
include(
{
'detail' => 'Feature Disabled: route_sharing',
'title' => 'CF-FeatureDisabled',
'code' => 330002,
})
)
end
end
end

describe 'errors while sharing' do
# isolation segments?
end
Expand Down

0 comments on commit 81b5b65

Please sign in to comment.