Skip to content

Commit

Permalink
feat(tagged-pact-versions): ensure triggered webhooks are deleted whe…
Browse files Browse the repository at this point in the history
…n pact versions are deleted
  • Loading branch information
bethesque committed Oct 3, 2018
1 parent 8624861 commit 288475f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/pact_broker/pacts/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
28 changes: 28 additions & 0 deletions spec/features/delete_tagged_pact_versions_spec.rb
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions spec/lib/pact_broker/pacts/repository_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 288475f

Please sign in to comment.