Skip to content

Commit

Permalink
test: add tests to ensure webhooks with deprecated webhook executions…
Browse files Browse the repository at this point in the history
… can be deleted
  • Loading branch information
bethesque committed Sep 18, 2017
1 parent f2bf848 commit 447c4cf
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 12 deletions.
2 changes: 1 addition & 1 deletion spec/features/delete_webhook_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
.create_pact
.create_webhook
.create_triggered_webhook
.create_webhook_execution
.create_deprecated_webhook_execution
.and_return(:webhook)
end

Expand Down
2 changes: 1 addition & 1 deletion spec/lib/pact_broker/pacticipants/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ module Pacticipants
.create_pact
.create_webhook
.create_triggered_webhook
.create_webhook_execution
.create_deprecated_webhook_execution
.create_verification
end

Expand Down
9 changes: 1 addition & 8 deletions spec/lib/pact_broker/webhooks/repository_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
20 changes: 18 additions & 2 deletions spec/lib/pact_broker/webhooks/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down
11 changes: 11 additions & 0 deletions spec/support/test_data_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 447c4cf

Please sign in to comment.