From c0f0f0ea81715efd54c2ce45ae472c34dd99e135 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 7 Sep 2018 15:11:53 -0700 Subject: [PATCH 1/2] close SCI-2698; unit tests for DELETE inventory item --- .../api/v1/inventory_items_controller_spec.rb | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/spec/requests/api/v1/inventory_items_controller_spec.rb b/spec/requests/api/v1/inventory_items_controller_spec.rb index 5da4f1cae..8fd4c36e5 100644 --- a/spec/requests/api/v1/inventory_items_controller_spec.rb +++ b/spec/requests/api/v1/inventory_items_controller_spec.rb @@ -126,4 +126,50 @@ RSpec.describe 'Api::V1::InventoryItemsController', type: :request do expect(hash_body).to match({}) end end + + describe 'DELETE inventory_items, #destroy' do + it 'Destroys inventory item' do + deleted_id = @teams.first.repositories.first.repository_rows.last.id + delete api_v1_team_inventory_item_path( + id: deleted_id, + team_id: @teams.first.id, + inventory_id: @teams.first.repositories.first.id + ), headers: @valid_headers + expect(response).to have_http_status(200) + expect(RepositoryRow.where(id: deleted_id)).to_not exist + expect(RepositoryCell.where(repository_row: deleted_id).count).to equal 0 + end + + it 'Invalid request, non existing inventory item' do + deleted_id = RepositoryRow.last.id + 1 + delete api_v1_team_inventory_item_path( + id: deleted_id, + team_id: @teams.first.id, + inventory_id: @teams.first.repositories.first.id + ), headers: @valid_headers + expect(response).to have_http_status(404) + end + + it 'When invalid request, incorrect repository' do + deleted_id = @teams.first.repositories.first.repository_rows.last.id + delete api_v1_team_inventory_item_path( + id: deleted_id, + team_id: @teams.first.id, + inventory_id: @teams.second.repositories.first.id + ), headers: @valid_headers + expect(response).to have_http_status(404) + expect(RepositoryRow.where(id: deleted_id)).to exist + end + + it 'When invalid request, repository from another team' do + deleted_id = @teams.first.repositories.first.repository_rows.last.id + delete api_v1_team_inventory_item_path( + id: deleted_id, + team_id: @teams.second.id, + inventory_id: @teams.first.repositories.first.id + ), headers: @valid_headers + expect(response).to have_http_status(403) + expect(RepositoryRow.where(id: deleted_id)).to exist + end + end end From 9fab092c314d10e4fde721e3da1bf2f5d902ff03 Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 11 Sep 2018 09:55:38 -0700 Subject: [PATCH 2/2] remove funky symbol --- spec/requests/api/v1/inventory_items_controller_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/requests/api/v1/inventory_items_controller_spec.rb b/spec/requests/api/v1/inventory_items_controller_spec.rb index 8fd4c36e5..c8ac4f394 100644 --- a/spec/requests/api/v1/inventory_items_controller_spec.rb +++ b/spec/requests/api/v1/inventory_items_controller_spec.rb @@ -161,7 +161,7 @@ RSpec.describe 'Api::V1::InventoryItemsController', type: :request do expect(RepositoryRow.where(id: deleted_id)).to exist end - it 'When invalid request, repository from another team' do + it 'When invalid request, repository from another team' do deleted_id = @teams.first.repositories.first.repository_rows.last.id delete api_v1_team_inventory_item_path( id: deleted_id,