Skip to content

Commit

Permalink
fix: raise PactBroker::Error when either pacticipant is not found in …
Browse files Browse the repository at this point in the history
…the business layer while attempting to delete an integration
  • Loading branch information
bethesque committed May 26, 2020
1 parent 690e6cf commit 3c209a4
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 8 deletions.
4 changes: 2 additions & 2 deletions lib/pact_broker/integrations/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions lib/pact_broker/pacts/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
4 changes: 2 additions & 2 deletions lib/pact_broker/verifications/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions spec/features/delete_integration_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
describe "Deleting pact versions" do
describe "Deleting an integration" do

let(:path) { "/integrations/provider/Bar/consumer/Foo" }

Expand All @@ -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
Expand Down
6 changes: 6 additions & 0 deletions spec/lib/pact_broker/integrations/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3c209a4

Please sign in to comment.