Skip to content

Commit

Permalink
feat: support DELETE /integrations for deleting all integration relat…
Browse files Browse the repository at this point in the history
…ed data at once (pacticipants, pacts, verifications and webhooks)
  • Loading branch information
bethesque committed Jan 5, 2020
1 parent 1c0530c commit d7e2ef2
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/pact_broker/api/resources/integrations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def integrations
end

def delete_resource
integration_service.delete(consumer_name, provider_name)
integration_service.delete_all
true
end
end
Expand Down
37 changes: 37 additions & 0 deletions lib/pact_broker/db/models.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
require 'pact_broker/webhooks/execution'
require 'pact_broker/webhooks/triggered_webhook'
require 'pact_broker/webhooks/webhook'
require 'pact_broker/pacts/latest_pact_publication_id_by_consumer_version'
require 'pact_broker/verifications/latest_verification_id_for_pact_version_and_provider_version'
require 'pact_broker/pacts/pact_publication'
require 'pact_broker/pacts/pact_version'
require 'pact_broker/domain/verification'
require 'pact_broker/domain/tag'
require 'pact_broker/domain/version'
require 'pact_broker/domain/label'
require 'pact_broker/domain/pacticipant'

module PactBroker
INTEGRATIONS_TABLES = [
PactBroker::Webhooks::Execution,
PactBroker::Webhooks::TriggeredWebhook,
PactBroker::Webhooks::Webhook,
PactBroker::Pacts::LatestPactPublicationIdForConsumerVersion,
PactBroker::Verifications::LatestVerificationIdForPactVersionAndProviderVersion,
PactBroker::Domain::Verification,
PactBroker::Pacts::PactPublication,
PactBroker::Pacts::PactVersion,
PactBroker::Domain::Tag,
PactBroker::Domain::Version,
PactBroker::Domain::Label,
PactBroker::Domain::Pacticipant
]

module DB
def self.each_integration_model
INTEGRATIONS_TABLES.each do | model |
yield model
end
end
end
end
9 changes: 9 additions & 0 deletions lib/pact_broker/integrations/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
require 'pact_broker/repositories'
require 'pact_broker/logging'
require 'pact_broker/integrations/integration'
require 'pact_broker/db/models'

module PactBroker
module Integrations
Expand Down Expand Up @@ -41,6 +42,14 @@ def self.delete(consumer_name, provider_name)
pacticipant_service.delete_if_orphan(consumer)
pacticipant_service.delete_if_orphan(provider) unless consumer == provider
end

def self.delete_all
# TODO move all these into their own repositories
PactBroker::DB.each_integration_model do | model |
logger.info("Truncating ", model.table_name)
model.truncate
end
end
end
end
end
10 changes: 10 additions & 0 deletions lib/pact_broker/test/test_data_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,16 @@ def create_certificate options = {path: 'spec/fixtures/single-certificate.pem'}
self
end

def create_everything_for_an_integration
create_pact_with_verification("Foo", "1", "Bar", "2")
.create_label("label")
.create_consumer_version_tag("master")
.create_provider_version_tag("master")
.create_webhook
.create_triggered_webhook
.create_webhook_execution
end

def model_counter
@@model_counter ||= 0
@@model_counter += 1
Expand Down
10 changes: 10 additions & 0 deletions spec/lib/pact_broker/integrations/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,16 @@ module Integrations
end
end
end

describe "delete_all" do
before do
td.create_everything_for_an_integration
end

it "doesn't blow up" do
Service.delete_all
end
end
end
end
end

0 comments on commit d7e2ef2

Please sign in to comment.