|
935 | 935 | let(:expected_codes_and_responses) { responses_for_space_restricted_async_delete_endpoint } |
936 | 936 | let(:db_check) { lambda {} } |
937 | 937 | let(:job) { VCAP::CloudController::PollableJobModel.last } |
| 938 | + let(:broker_base_url) { service_instance.service_broker.broker_url } |
| 939 | + let(:broker_unbind_url) { "#{broker_base_url}/v2/service_instances/#{service_instance.guid}/service_bindings/#{binding.guid}" } |
| 940 | + let(:route_service_url) { 'https://route_service_url.com' } |
| 941 | + let(:broker_unbind_status_code) { 200 } |
| 942 | + let(:broker_response) { {} } |
| 943 | + let(:query) do |
| 944 | + { |
| 945 | + service_id: service_instance.service_plan.service.unique_id, |
| 946 | + plan_id: service_instance.service_plan.unique_id, |
| 947 | + accepts_incomplete: true, |
| 948 | + } |
| 949 | + end |
938 | 950 |
|
939 | 951 | it_behaves_like 'permissions for delete endpoint', ALL_PERMISSIONS |
940 | 952 |
|
|
955 | 967 | end |
956 | 968 |
|
957 | 969 | describe 'the pollable job' do |
958 | | - let(:broker_base_url) { service_instance.service_broker.broker_url } |
959 | | - let(:broker_unbind_url) { "#{broker_base_url}/v2/service_instances/#{service_instance.guid}/service_bindings/#{binding.guid}" } |
960 | | - let(:route_service_url) { 'https://route_service_url.com' } |
961 | | - let(:broker_unbind_status_code) { 200 } |
962 | | - let(:broker_response) { {} } |
963 | | - let(:query) do |
964 | | - { |
965 | | - service_id: service_instance.service_plan.service.unique_id, |
966 | | - plan_id: service_instance.service_plan.unique_id, |
967 | | - accepts_incomplete: true, |
968 | | - } |
969 | | - end |
970 | | - |
971 | 970 | before do |
972 | 971 | api_call.call(space_dev_headers) |
973 | 972 | expect(last_response).to have_status_code(202) |
|
1113 | 1112 | end |
1114 | 1113 | end |
1115 | 1114 | end |
| 1115 | + |
| 1116 | + context 'when the service instance has an operation in progress' do |
| 1117 | + it 'responds with 422' do |
| 1118 | + service_instance.save_with_new_operation({}, { type: 'guacamole', state: 'in progress' }) |
| 1119 | + |
| 1120 | + api_call.call admin_headers |
| 1121 | + expect(last_response).to have_status_code(422) |
| 1122 | + expect(parsed_response['errors']).to include(include({ |
| 1123 | + 'detail' => include('There is an operation in progress for the service instance'), |
| 1124 | + 'title' => 'CF-UnprocessableEntity', |
| 1125 | + 'code' => 10008, |
| 1126 | + })) |
| 1127 | + end |
| 1128 | + end |
| 1129 | + |
| 1130 | + context 'when the route binding is still creating' do |
| 1131 | + before do |
| 1132 | + binding.save_with_new_operation( |
| 1133 | + {}, |
| 1134 | + { type: 'create', state: 'in progress', broker_provided_operation: 'very important info' } |
| 1135 | + ) |
| 1136 | + end |
| 1137 | + |
| 1138 | + context 'but the broker accepts the delete request' do |
| 1139 | + before do |
| 1140 | + @delete_stub = stub_request(:delete, broker_unbind_url). |
| 1141 | + with(query: query). |
| 1142 | + to_return(status: 202, body: '{"operation": "very important delete info"}', headers: {}) |
| 1143 | + |
| 1144 | + @last_op_stub = stub_request(:get, "#{broker_unbind_url}/last_operation"). |
| 1145 | + with(query: hash_including({ |
| 1146 | + operation: 'very important delete info' |
| 1147 | + })). |
| 1148 | + to_return(status: 200, body: '{"state": "in progress"}', headers: {}) |
| 1149 | + end |
| 1150 | + |
| 1151 | + it 'starts the route binding deletion' do |
| 1152 | + api_call.call(admin_headers) |
| 1153 | + expect(last_response).to have_status_code(202) |
| 1154 | + execute_all_jobs(expected_successes: 1, expected_failures: 0) |
| 1155 | + |
| 1156 | + expect(@delete_stub).to have_been_requested.once |
| 1157 | + expect(@last_op_stub).to have_been_requested |
| 1158 | + |
| 1159 | + binding.reload |
| 1160 | + expect(binding.last_operation.type).to eq('delete') |
| 1161 | + expect(binding.last_operation.state).to eq('in progress') |
| 1162 | + expect(binding.last_operation.broker_provided_operation).to eq('very important delete info') |
| 1163 | + end |
| 1164 | + end |
| 1165 | + |
| 1166 | + context 'and the broker rejects the delete request' do |
| 1167 | + before do |
| 1168 | + stub_request(:delete, broker_unbind_url). |
| 1169 | + with(query: query). |
| 1170 | + to_return(status: 422, body: '{"error": "ConcurrencyError"}', headers: {}) |
| 1171 | + |
| 1172 | + api_call.call(admin_headers) |
| 1173 | + execute_all_jobs(expected_successes: 0, expected_failures: 1) |
| 1174 | + binding.reload |
| 1175 | + end |
| 1176 | + |
| 1177 | + it 'leaves the route binding in its current state' do |
| 1178 | + expect(binding.last_operation.type).to eq('create') |
| 1179 | + expect(binding.last_operation.state).to eq('in progress') |
| 1180 | + expect(binding.last_operation.broker_provided_operation).to eq('very important info') |
| 1181 | + end |
| 1182 | + end |
| 1183 | + end |
1116 | 1184 | end |
1117 | 1185 | end |
1118 | 1186 |
|
|
0 commit comments