From beff430b6188b077bda5700c802834a61dfb7b08 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 9 Sep 2018 13:37:26 -0700 Subject: [PATCH] unit tests for DELETE inventory [SCI-2704] --- .../api/v1/inventories_controller_spec.rb | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/spec/requests/api/v1/inventories_controller_spec.rb b/spec/requests/api/v1/inventories_controller_spec.rb index bfdbefcc2..ba3f0fa3f 100644 --- a/spec/requests/api/v1/inventories_controller_spec.rb +++ b/spec/requests/api/v1/inventories_controller_spec.rb @@ -92,4 +92,36 @@ RSpec.describe "Api::V1::InventoriesController", type: :request do expect(hash_body).to match({}) end end + + describe 'DELETE inventories, #destroy' do + it 'Destroys inventory' do + deleted_id = @teams.first.repositories.last.id + delete api_v1_team_inventory_path( + id: deleted_id, + team_id: @teams.first.id + ), headers: @valid_headers + expect(response).to have_http_status(200) + expect(Repository.where(id: deleted_id)).to_not exist + expect(RepositoryRow.where(repository: deleted_id).count).to equal 0 + expect(RepositoryColumn.where(repository: deleted_id).count).to equal 0 + end + + it 'Invalid request, non existing inventory' do + delete api_v1_team_inventory_path( + id: 123, + team_id: @teams.first.id + ), headers: @valid_headers + expect(response).to have_http_status(404) + end + + it 'When invalid request, repository from another team' do + deleted_id = @teams.first.repositories.last.id + delete api_v1_team_inventory_path( + id: deleted_id, + team_id: @teams.second.id + ), headers: @valid_headers + expect(response).to have_http_status(403) + expect(Repository.where(id: deleted_id)).to exist + end + end end