|
7 | 7 | let(:space) { VCAP::CloudController::Space.make } |
8 | 8 | let(:org) { space.organization } |
9 | 9 |
|
| 10 | + describe 'GET /v3/routes' do |
| 11 | + let(:other_space) { VCAP::CloudController::Space.make } |
| 12 | + let(:domain) { VCAP::CloudController::PrivateDomain.make(owning_organization: space.organization) } |
| 13 | + let(:route_in_org) { VCAP::CloudController::Route.make(space: space, domain: domain) } |
| 14 | + let(:route_in_other_org) { VCAP::CloudController::Route.make(space: other_space) } |
| 15 | + let(:api_call) { lambda { |user_headers| get '/v3/routes', nil, user_headers } } |
| 16 | + let(:route_in_org_json) do |
| 17 | + { |
| 18 | + guid: UUID_REGEX, |
| 19 | + host: route_in_org.host, |
| 20 | + path: route_in_org.path, |
| 21 | + created_at: iso8601, |
| 22 | + updated_at: iso8601, |
| 23 | + relationships: { |
| 24 | + space: { |
| 25 | + data: { guid: route_in_org.space.guid } |
| 26 | + }, |
| 27 | + domain: { |
| 28 | + data: { guid: route_in_org.domain.guid } |
| 29 | + } |
| 30 | + }, |
| 31 | + links: { |
| 32 | + self: { href: %r(#{Regexp.escape(link_prefix)}\/v3\/routes\/#{UUID_REGEX}) }, |
| 33 | + space: { href: %r(#{Regexp.escape(link_prefix)}\/v3\/spaces\/#{route_in_org.space.guid}) }, |
| 34 | + domain: { href: %r(#{Regexp.escape(link_prefix)}\/v3\/domains\/#{route_in_org.domain.guid}) } |
| 35 | + } |
| 36 | + } |
| 37 | + end |
| 38 | + |
| 39 | + let(:route_in_other_org_json) do |
| 40 | + { |
| 41 | + guid: UUID_REGEX, |
| 42 | + host: route_in_other_org.host, |
| 43 | + path: route_in_other_org.path, |
| 44 | + created_at: iso8601, |
| 45 | + updated_at: iso8601, |
| 46 | + relationships: { |
| 47 | + space: { |
| 48 | + data: { guid: route_in_other_org.space.guid } |
| 49 | + }, |
| 50 | + domain: { |
| 51 | + data: { guid: route_in_other_org.domain.guid } |
| 52 | + } |
| 53 | + }, |
| 54 | + links: { |
| 55 | + self: { href: %r(#{Regexp.escape(link_prefix)}\/v3\/routes\/#{UUID_REGEX}) }, |
| 56 | + space: { href: %r(#{Regexp.escape(link_prefix)}\/v3\/spaces\/#{route_in_other_org.space.guid}) }, |
| 57 | + domain: { href: %r(#{Regexp.escape(link_prefix)}\/v3\/domains\/#{route_in_other_org.domain.guid}) } |
| 58 | + } |
| 59 | + } |
| 60 | + end |
| 61 | + |
| 62 | + context 'when the user is a member in the routes org' do |
| 63 | + let(:expected_codes_and_responses) do |
| 64 | + h = Hash.new( |
| 65 | + code: 200, |
| 66 | + response_objects: [route_in_org_json] |
| 67 | + ) |
| 68 | + |
| 69 | + h['admin'] = { code: 200, response_objects: [route_in_org_json, route_in_other_org_json] } |
| 70 | + h['admin_read_only'] = { code: 200, response_objects: [route_in_org_json, route_in_other_org_json] } |
| 71 | + h['global_auditor'] = { code: 200, response_objects: [route_in_org_json, route_in_other_org_json] } |
| 72 | + |
| 73 | + h['org_billing_manager'] = { code: 200, response_objects: [] } |
| 74 | + h['no_role'] = { code: 200, response_objects: [] } |
| 75 | + h |
| 76 | + end |
| 77 | + |
| 78 | + it_behaves_like 'permissions for list endpoint', ALL_PERMISSIONS |
| 79 | + end |
| 80 | + |
| 81 | + context 'when the request is invalid' do |
| 82 | + it 'returns 400 with a meaningful error' do |
| 83 | + get '/v3/routes?page=potato', nil, admin_header |
| 84 | + expect(last_response.status).to eq(400) |
| 85 | + expect(last_response).to have_error_message('The query parameter is invalid: Page must be a positive integer') |
| 86 | + end |
| 87 | + end |
| 88 | + |
| 89 | + context 'when the user is not logged in' do |
| 90 | + it 'returns 401 for Unauthenticated requests' do |
| 91 | + get '/v3/routes', nil, base_json_headers |
| 92 | + expect(last_response.status).to eq(401) |
| 93 | + end |
| 94 | + end |
| 95 | + end |
| 96 | + |
10 | 97 | describe 'GET /v3/routes/:guid' do |
11 | 98 | let(:domain) { VCAP::CloudController::PrivateDomain.make(owning_organization: space.organization) } |
12 | 99 | let(:route) { VCAP::CloudController::Route.make(space: space, domain: domain) } |
|
0 commit comments