From 3c209a4610b56f317914fc7f1726beaa56ba840e Mon Sep 17 00:00:00 2001 From: Beth Skurrie Date: Wed, 27 May 2020 06:39:21 +1000 Subject: [PATCH] fix: raise PactBroker::Error when either pacticipant is not found in the business layer while attempting to delete an integration --- lib/pact_broker/integrations/service.rb | 4 ++-- lib/pact_broker/pacts/repository.rb | 4 ++-- lib/pact_broker/verifications/repository.rb | 4 ++-- spec/features/delete_integration_spec.rb | 4 ++-- spec/lib/pact_broker/integrations/service_spec.rb | 6 ++++++ 5 files changed, 14 insertions(+), 8 deletions(-) diff --git a/lib/pact_broker/integrations/service.rb b/lib/pact_broker/integrations/service.rb index ad2dc25a9..fb3c63b98 100644 --- a/lib/pact_broker/integrations/service.rb +++ b/lib/pact_broker/integrations/service.rb @@ -31,8 +31,8 @@ def self.find_all end def self.delete(consumer_name, provider_name) - consumer = pacticipant_service.find_pacticipant_by_name(consumer_name) - provider = pacticipant_service.find_pacticipant_by_name(provider_name) + consumer = pacticipant_service.find_pacticipant_by_name!(consumer_name) + provider = pacticipant_service.find_pacticipant_by_name!(provider_name) # this takes care of the triggered webhooks and webhook executions pact_service.delete_all_pact_publications_between(consumer_name, and: provider_name) verification_service.delete_all_verifications_between(consumer_name, and: provider_name) diff --git a/lib/pact_broker/pacts/repository.rb b/lib/pact_broker/pacts/repository.rb index 3c3bca3ae..dcbe8fbad 100644 --- a/lib/pact_broker/pacts/repository.rb +++ b/lib/pact_broker/pacts/repository.rb @@ -107,8 +107,8 @@ def find_all_pact_versions_between consumer_name, options end def delete_all_pact_publications_between consumer_name, options - consumer = pacticipant_repository.find_by_name(consumer_name) - provider = pacticipant_repository.find_by_name(options.fetch(:and)) + consumer = pacticipant_repository.find_by_name!(consumer_name) + provider = pacticipant_repository.find_by_name!(options.fetch(:and)) query = PactPublication.where(consumer: consumer, provider: provider) query = query.tag(options[:tag]) if options[:tag] diff --git a/lib/pact_broker/verifications/repository.rb b/lib/pact_broker/verifications/repository.rb index ee80f7efe..b1ae36795 100644 --- a/lib/pact_broker/verifications/repository.rb +++ b/lib/pact_broker/verifications/repository.rb @@ -136,8 +136,8 @@ def delete_by_provider_version_id version_id end def delete_all_verifications_between(consumer_name, options) - consumer = pacticipant_repository.find_by_name(consumer_name) - provider = pacticipant_repository.find_by_name(options.fetch(:and)) + consumer = pacticipant_repository.find_by_name!(consumer_name) + provider = pacticipant_repository.find_by_name!(options.fetch(:and)) PactBroker::Domain::Verification.where(provider: provider, consumer: consumer).delete end diff --git a/spec/features/delete_integration_spec.rb b/spec/features/delete_integration_spec.rb index f0bb69390..2c95c17ea 100644 --- a/spec/features/delete_integration_spec.rb +++ b/spec/features/delete_integration_spec.rb @@ -1,4 +1,4 @@ -describe "Deleting pact versions" do +describe "Deleting an integration" do let(:path) { "/integrations/provider/Bar/consumer/Foo" } @@ -19,7 +19,7 @@ end end - context "when the pact does not exist" do + context "when the integration does not exist" do it "returns a 404 Not Found" do expect(subject.status).to be 404 end diff --git a/spec/lib/pact_broker/integrations/service_spec.rb b/spec/lib/pact_broker/integrations/service_spec.rb index f3816f864..0c57be52c 100644 --- a/spec/lib/pact_broker/integrations/service_spec.rb +++ b/spec/lib/pact_broker/integrations/service_spec.rb @@ -248,6 +248,12 @@ module Integrations Service.delete("Foo", "Foo") end end + + context "when the pacticipants are not found for some bizarre reason (I can't see how this can happen, but it has)" do + it "raises an error" do + expect { Service.delete("Foo", "Bar") }.to raise_error(PactBroker::Error, /found/) + end + end end describe "delete_all" do