From 447c4cfc646ef83f6b014922ce00fe6dbf704930 Mon Sep 17 00:00:00 2001 From: Beth Skurrie Date: Mon, 18 Sep 2017 11:07:20 +1000 Subject: [PATCH] test: add tests to ensure webhooks with deprecated webhook executions can be deleted --- spec/features/delete_webhook_spec.rb | 2 +- .../pact_broker/pacticipants/service_spec.rb | 2 +- .../pact_broker/webhooks/repository_spec.rb | 9 +-------- spec/lib/pact_broker/webhooks/service_spec.rb | 20 +++++++++++++++++-- spec/support/test_data_builder.rb | 11 ++++++++++ 5 files changed, 32 insertions(+), 12 deletions(-) diff --git a/spec/features/delete_webhook_spec.rb b/spec/features/delete_webhook_spec.rb index 16b309881..b505a50dc 100644 --- a/spec/features/delete_webhook_spec.rb +++ b/spec/features/delete_webhook_spec.rb @@ -10,7 +10,7 @@ .create_pact .create_webhook .create_triggered_webhook - .create_webhook_execution + .create_deprecated_webhook_execution .and_return(:webhook) end diff --git a/spec/lib/pact_broker/pacticipants/service_spec.rb b/spec/lib/pact_broker/pacticipants/service_spec.rb index 82bf337ce..736f2871c 100644 --- a/spec/lib/pact_broker/pacticipants/service_spec.rb +++ b/spec/lib/pact_broker/pacticipants/service_spec.rb @@ -142,7 +142,7 @@ module Pacticipants .create_pact .create_webhook .create_triggered_webhook - .create_webhook_execution + .create_deprecated_webhook_execution .create_verification end diff --git a/spec/lib/pact_broker/webhooks/repository_spec.rb b/spec/lib/pact_broker/webhooks/repository_spec.rb index 2d1703f0f..aa355bb68 100644 --- a/spec/lib/pact_broker/webhooks/repository_spec.rb +++ b/spec/lib/pact_broker/webhooks/repository_spec.rb @@ -364,14 +364,7 @@ module Webhooks .create_pact .create_webhook .create_triggered_webhook - .create_webhook_execution - - DeprecatedExecution.where(id: td.webhook_execution.id).update( - consumer_id: td.consumer.id, - provider_id: td.provider.id, - pact_publication_id: td.pact.id, - webhook_id: Webhook.find(uuid: td.webhook.uuid).id - ) + .create_deprecated_webhook_execution end subject { Repository.new.unlink_triggered_webhooks_by_webhook_uuid td.webhook.uuid } diff --git a/spec/lib/pact_broker/webhooks/service_spec.rb b/spec/lib/pact_broker/webhooks/service_spec.rb index ec2896257..a0d158a5e 100644 --- a/spec/lib/pact_broker/webhooks/service_spec.rb +++ b/spec/lib/pact_broker/webhooks/service_spec.rb @@ -8,6 +8,24 @@ module PactBroker module Webhooks describe Service do + let(:td) { TestDataBuilder.new } + + describe ".delete_by_uuid" do + before do + td.create_pact_with_hierarchy + .create_webhook + .create_triggered_webhook + .create_deprecated_webhook_execution + end + + subject { Service.delete_by_uuid td.webhook.uuid } + + it "deletes the webhook" do + expect { subject }.to change { + Webhook.count + }.by(-1) + end + end describe ".execute_webhooks" do @@ -103,8 +121,6 @@ module Webhooks end describe ".execute_webhooks integration test" do - let(:td) { TestDataBuilder.new } - let!(:http_request) do stub_request(:get, "http://example.org"). to_return(:status => 200) diff --git a/spec/support/test_data_builder.rb b/spec/support/test_data_builder.rb index 1d576859c..4bd8468a7 100644 --- a/spec/support/test_data_builder.rb +++ b/spec/support/test_data_builder.rb @@ -187,6 +187,17 @@ def create_webhook_execution params = {} self end + def create_deprecated_webhook_execution params = {} + create_webhook_execution params + Sequel::Model.db[:webhook_executions].where(id: webhook_execution.id).update( + consumer_id: consumer.id, + provider_id: provider.id, + webhook_id: PactBroker::Webhooks::Webhook.find(uuid: webhook.uuid).id, + pact_publication_id: pact.id + ) + self + end + def create_verification parameters = {} default_parameters = {success: true, provider_version: '4.5.6', number: 1} verification = PactBroker::Domain::Verification.new(default_parameters.merge(parameters))