Skip to content

Commit

Permalink
Add delete endpoint for portfolio_item
Browse files Browse the repository at this point in the history
  • Loading branch information
syncrou committed Jan 7, 2019
1 parent 76445a3 commit 51e8289
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
5 changes: 5 additions & 0 deletions app/controllers/api/v0/admins_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
17 changes: 17 additions & 0 deletions public/doc/swagger-2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
15 changes: 15 additions & 0 deletions spec/requests/portfolio_items_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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") }
Expand All @@ -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)
Expand Down

0 comments on commit 51e8289

Please sign in to comment.