diff --git a/app/controllers/api/v0/admins_controller.rb b/app/controllers/api/v0/admins_controller.rb index 6d239fcb9..0751c6646 100644 --- a/app/controllers/api/v0/admins_controller.rb +++ b/app/controllers/api/v0/admins_controller.rb @@ -34,6 +34,11 @@ def add_to_order render json: AddToOrder.new(params).process.to_hash end + def destroy_portfolio_item + PortfolioItem.find(params.require(:portfolio_item_id)).destroy + head :no_content + end + private def portfolio_item_params params.permit(:service_offering_ref) diff --git a/config/routes.rb b/config/routes.rb index 0c8027ae3..b69accf84 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -36,6 +36,7 @@ def add_swagger_route(http_method, path, opts = {}) add_swagger_route 'GET', '/portfolios/{portfolio_id}', :controller_name => 'admins', :action_name => 'fetch_portfolio_with_id' add_swagger_route 'PATCH', '/portfolios/{portfolio_id}', :controller_name => 'admins', :action_name => 'edit_portfolio' add_swagger_route 'DELETE', '/portfolios/{portfolio_id}', :controller_name => 'admins', :action_name => 'destroy_portfolio' + add_swagger_route 'DELETE', '/portfolio_items/{portfolio_item_id}', :controller_name => 'admins', :action_name => 'destroy_portfolio_item' add_swagger_route 'GET', '/orders/{order_id}/items/{order_item_id}', :controller_name => 'admins', :action_name => 'list_order_item' add_swagger_route 'GET', '/orders/{order_id}/items', :controller_name => 'admins', :action_name => 'list_order_items' add_swagger_route 'GET', '/orders', :controller_name => 'admins', :action_name => 'list_orders' diff --git a/public/doc/swagger-2.yaml b/public/doc/swagger-2.yaml index 038d577b4..214ae52bb 100644 --- a/public/doc/swagger-2.yaml +++ b/public/doc/swagger-2.yaml @@ -298,6 +298,23 @@ paths: description: Service Offering not found '422': $ref: '#/responses/InvalidEntity' + '/portfolio_items/{portfolio_item_id}': + delete: + tags: + - admins + summary: Delete an existing portfolio item + operationId: destroyPortfolioItem + description: | + Deletes the portfolio item id passed in as the param. + produces: + - application/json + parameters: + - $ref: '#/parameters/PortfolioItemID' + responses: + 204: + description: Portfolio Item deleted + 404: + description: Portfolio Item not Found '/portfolio_items/{portfolio_item_id}/service_plans': get: tags: diff --git a/spec/requests/portfolio_items_spec.rb b/spec/requests/portfolio_items_spec.rb index ec8524ebd..e062dca18 100644 --- a/spec/requests/portfolio_items_spec.rb +++ b/spec/requests/portfolio_items_spec.rb @@ -4,6 +4,7 @@ let(:service_offering_ref) { "998" } let(:order) { create(:order) } let(:portfolio_item) { create(:portfolio_item, :service_offering_ref => service_offering_ref) } + let(:portfolio_item_id) { portfolio_item.id } let(:svc_object) { instance_double("ServiceCatalog::ServicePlans") } let(:plans) { [{}, {}] } let(:topo_ex) { ServiceCatalog::TopologyError.new("kaboom") } @@ -12,6 +13,20 @@ allow(ServiceCatalog::ServicePlans).to receive(:new).with(portfolio_item.id.to_s).and_return(svc_object) end + describe 'DELETE admin tagged /portfolio_items/:portfolio_item_id' do + let(:valid_attributes) { { :name => 'PatchPortfolio', :description => 'description for patched portfolio' } } + + context 'when :portfolio_item_id is valid' do + before do + delete "/api/v0.0/portfolio_items/#{portfolio_item_id}", :headers => admin_headers, :params => valid_attributes + end + + it 'deletes the record' do + expect(response).to have_http_status(204) + end + end + end + it "fetches plans" do allow(svc_object).to receive(:process).and_return(svc_object) allow(svc_object).to receive(:items).and_return(plans)