Skip to content

Commit

Permalink
refactor: rename triggered webhook context to event_context
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Jan 18, 2021
1 parent 3a2c98b commit 840973e
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion db/migrations/20210116_add_context_to_triggered_webhook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Sequel.migration do
change do
alter_table(:triggered_webhooks) do
add_column(:context, String)
add_column(:event_context, String)
end
end
end
4 changes: 2 additions & 2 deletions lib/pact_broker/test/test_data_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,8 @@ def create_triggered_webhook params = {}
trigger_uuid = params[:trigger_uuid] || webhook_service.next_uuid
event_name = params.key?(:event_name) ? params[:event_name] : @webhook.events.first.name # could be nil, for backwards compatibility
verification = @webhook.trigger_on_provider_verification_published? ? @verification : nil
context = params[:context]
@triggered_webhook = webhook_repository.create_triggered_webhook(trigger_uuid, @webhook, @pact, verification, PactBroker::Webhooks::Service::RESOURCE_CREATION, event_name, context)
event_context = params[:event_context]
@triggered_webhook = webhook_repository.create_triggered_webhook(trigger_uuid, @webhook, @pact, verification, PactBroker::Webhooks::Service::RESOURCE_CREATION, event_name, event_context)
@triggered_webhook.update(status: params[:status]) if params[:status]
set_created_at_if_set params[:created_at], :triggered_webhooks, { id: @triggered_webhook.id }
self
Expand Down
4 changes: 2 additions & 2 deletions lib/pact_broker/webhooks/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def find_by_consumer_and_provider_and_event_name consumer, provider, event_name
.collect(&:to_domain)
end

def create_triggered_webhook trigger_uuid, webhook, pact, verification, trigger_type, event_name, context
def create_triggered_webhook trigger_uuid, webhook, pact, verification, trigger_type, event_name, event_context
db_webhook = Webhook.where(uuid: webhook.uuid).single_record
TriggeredWebhook.create(
status: TriggeredWebhook::STATUS_NOT_RUN,
Expand All @@ -114,7 +114,7 @@ def create_triggered_webhook trigger_uuid, webhook, pact, verification, trigger_
consumer: pact.consumer,
provider: pact.provider,
event_name: event_name,
context: context
event_context: event_context
)
end

Expand Down
2 changes: 1 addition & 1 deletion lib/pact_broker/webhooks/triggered_webhook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module PactBroker
module Webhooks
class TriggeredWebhook < Sequel::Model(:triggered_webhooks)
plugin :timestamps, update_on_create: true
plugin :serialization, :json, :context
plugin :serialization, :json, :event_context

TRIGGER_TYPE_RESOURCE_CREATION = 'resource_creation'
TRIGGER_TYPE_USER = 'user'
Expand Down
6 changes: 3 additions & 3 deletions spec/lib/pact_broker/webhooks/repository_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -386,9 +386,9 @@ module Webhooks
.create_verification
end

let(:context) { { 'some' => 'info' } }
let(:event_context) { { 'some' => 'info' } }

subject { Repository.new.create_triggered_webhook '1234', td.webhook, td.pact, td.verification, 'publication', 'some_event', context }
subject { Repository.new.create_triggered_webhook '1234', td.webhook, td.pact, td.verification, 'publication', 'some_event', event_context }

it "creates a TriggeredWebhook" do
expect(subject.webhook_uuid ).to eq td.webhook.uuid
Expand All @@ -398,7 +398,7 @@ module Webhooks
expect(subject.trigger_uuid).to eq '1234'
expect(subject.trigger_type).to eq 'publication'
expect(subject.event_name).to eq 'some_event'
expect(subject.context).to eq context
expect(subject.event_context).to eq event_context
end

it "sets the webhook" do
Expand Down

0 comments on commit 840973e

Please sign in to comment.