Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add delete endpoint for portfolio_item #84

Merged
merged 1 commit into from
Jan 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:
Copy link
Contributor

@mkanoor mkanoor Jan 7, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@syncrou The 204 status reads

The HTTP 204 No Content success status response code indicates that the request has succeeded, but that the client doesn't need to go away from its current page

@lgalis Is the UI going to react properly for a 204, it would have to issue a refresh of the portfolio items page

description: Portfolio Item deleted
404:
description: Portfolio Item not Found
'/portfolio_items/{portfolio_item_id}/service_plans':
get:
tags:
Expand Down
16 changes: 16 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,21 @@
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
#TODO https://github.com/ManageIQ/service_portal-api/issues/85
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@syncrou Do we need a TODO to add a test as a non admin user it should fail. Since we don't have any constraints check now we would have to wait. Also a GitHub issue might help

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a TODO that points to this Issue: #85

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