From 288475f13371b2e531ddef0cdcb79745e739cbd2 Mon Sep 17 00:00:00 2001 From: Beth Skurrie Date: Wed, 3 Oct 2018 14:32:29 +1000 Subject: [PATCH] feat(tagged-pact-versions): ensure triggered webhooks are deleted when pact versions are deleted --- lib/pact_broker/pacts/repository.rb | 1 + .../delete_tagged_pact_versions_spec.rb | 28 +++++++++++++++++++ spec/lib/pact_broker/pacts/repository_spec.rb | 3 ++ 3 files changed, 32 insertions(+) create mode 100644 spec/features/delete_tagged_pact_versions_spec.rb diff --git a/lib/pact_broker/pacts/repository.rb b/lib/pact_broker/pacts/repository.rb index 013f7d206..ca15f9cc7 100644 --- a/lib/pact_broker/pacts/repository.rb +++ b/lib/pact_broker/pacts/repository.rb @@ -83,6 +83,7 @@ def find_all_pact_versions_between consumer_name, options def delete_all_pact_versions_between consumer_name, options ids = find_all_database_versions_between(consumer_name, options).select_for_subquery(:id) + webhook_repository.delete_triggered_webhooks_by_pact_publication_ids(ids) PactPublication.where(id: ids).delete end diff --git a/spec/features/delete_tagged_pact_versions_spec.rb b/spec/features/delete_tagged_pact_versions_spec.rb new file mode 100644 index 000000000..5e38e14d0 --- /dev/null +++ b/spec/features/delete_tagged_pact_versions_spec.rb @@ -0,0 +1,28 @@ +describe "Deleting tagged pact versions" do + + let(:path) { "/pacts/provider/Bar/consumer/Foo/tag/prod" } + + subject { delete(path) } + + context "when the pact exists" do + before do + TestDataBuilder.new + .create_pact_with_hierarchy("Foo", "1.2.3", "Bar") + .create_consumer_version_tag("prod") + end + + it "deletes the pact" do + expect{ subject }.to change{ PactBroker::Pacts::PactPublication.count }.by(-1) + end + + it "returns a 204" do + expect(subject.status).to be 204 + end + end + + context "when the pact does not exist" do + it "returns a 404 Not Found" do + expect(subject.status).to be 404 + end + end +end diff --git a/spec/lib/pact_broker/pacts/repository_spec.rb b/spec/lib/pact_broker/pacts/repository_spec.rb index 4e742c627..237e0e231 100644 --- a/spec/lib/pact_broker/pacts/repository_spec.rb +++ b/spec/lib/pact_broker/pacts/repository_spec.rb @@ -305,6 +305,9 @@ module Pacts .create_consumer_version("1.2.3") .create_provider(provider_name) .create_pact + .create_webhook + .create_triggered_webhook + .create_webhook_execution .create_consumer_version("2.3.4") .create_consumer_version_tag("prod") .create_consumer_version_tag("branch")