Skip to content

Commit

Permalink
fix: correctly remove webhook consumer/provider when update params do…
Browse files Browse the repository at this point in the history
… not contain a consumer/provider
  • Loading branch information
bethesque committed Jun 6, 2019
1 parent 481e045 commit 118bbee
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
4 changes: 2 additions & 2 deletions lib/pact_broker/webhooks/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ def find_by_uuid uuid

def update_by_uuid uuid, webhook
existing_webhook = Webhook.find(uuid: uuid)
existing_webhook.consumer_id = pacticipant_repository.find_by_name(webhook.consumer.name).id if webhook.consumer
existing_webhook.provider_id = pacticipant_repository.find_by_name(webhook.provider.name).id if webhook.provider
existing_webhook.consumer_id = webhook.consumer ? pacticipant_repository.find_by_name(webhook.consumer.name).id : nil
existing_webhook.provider_id = webhook.provider ? pacticipant_repository.find_by_name(webhook.provider.name).id : nil
existing_webhook.update_from_domain(webhook).save
existing_webhook.events.collect(&:delete)
(webhook.events || []).each do | webhook_event |
Expand Down
32 changes: 22 additions & 10 deletions spec/lib/pact_broker/webhooks/repository_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -228,16 +228,28 @@ module Webhooks
subject { Repository.new.update_by_uuid(uuid, new_webhook) }

it "updates the webhook" do
updated_webhook = subject
expect(updated_webhook.uuid).to eq uuid
expect(updated_webhook.request.method).to eq 'GET'
expect(updated_webhook.request.url).to eq 'http://example.com'
expect(updated_webhook.request.body).to eq 'foo'
expect(updated_webhook.request.headers).to eq 'Content-Type' => 'text/plain'
expect(updated_webhook.request.username).to eq nil
expect(updated_webhook.request.password).to eq nil
expect(updated_webhook.events.first.name).to eq 'something_else'
expect(updated_webhook.consumer.name).to eq "Foo2"
expect(subject.uuid).to eq uuid
expect(subject.request.method).to eq 'GET'
expect(subject.request.url).to eq 'http://example.com'
expect(subject.request.body).to eq 'foo'
expect(subject.request.headers).to eq 'Content-Type' => 'text/plain'
expect(subject.request.username).to eq nil
expect(subject.request.password).to eq nil
expect(subject.events.first.name).to eq 'something_else'
expect(subject.consumer.name).to eq "Foo2"
end

context "when the updated params do not contain a consumer or provider" do
let(:new_webhook) do
PactBroker::Domain::Webhook.new(
events: [new_event],
request: new_request
)
end

it "removes the existing consumer or provider" do
expect(subject.consumer).to be nil
end
end
end

Expand Down

0 comments on commit 118bbee

Please sign in to comment.