File tree 2 files changed +27
-6
lines changed
spec/lib/pact_broker/webhooks
2 files changed +27
-6
lines changed Original file line number Diff line number Diff line change 7
7
require 'pact_broker/webhooks/triggered_webhook'
8
8
require 'pact_broker/webhooks/latest_triggered_webhook'
9
9
require 'pact_broker/webhooks/execution'
10
+ require 'pact_broker/logging'
10
11
11
12
module PactBroker
12
13
module Webhooks
13
-
14
14
class Repository
15
+ include PactBroker ::Logging
15
16
16
17
include Repositories
17
18
@@ -125,10 +126,15 @@ def update_triggered_webhook_status triggered_webhook, status
125
126
end
126
127
127
128
def create_execution triggered_webhook , webhook_execution_result
128
- Execution . create (
129
- triggered_webhook : triggered_webhook ,
130
- success : webhook_execution_result . success? ,
131
- logs : webhook_execution_result . logs )
129
+ # TriggeredWebhook may have been deleted since the webhook execution started
130
+ if TriggeredWebhook . where ( id : triggered_webhook . id ) . any?
131
+ Execution . create (
132
+ triggered_webhook : triggered_webhook ,
133
+ success : webhook_execution_result . success? ,
134
+ logs : webhook_execution_result . logs )
135
+ else
136
+ logger . info ( "Could not save webhook execution for triggered webhook with id #{ triggered_webhook . id } as it has been delete from the database" )
137
+ end
132
138
end
133
139
134
140
def delete_triggered_webhooks_by_pacticipant pacticipant
Original file line number Diff line number Diff line change @@ -430,8 +430,9 @@ module Webhooks
430
430
431
431
let ( :webhook_domain ) { Repository . new . find_by_uuid td . webhook . uuid }
432
432
let ( :webhook_execution_result ) { instance_double ( "PactBroker::Domain::WebhookExecutionResult" , success? : true , logs : "logs" ) }
433
+ let ( :repository ) { Repository . new }
433
434
434
- subject { Repository . new . create_execution td . triggered_webhook , webhook_execution_result }
435
+ subject { repository . create_execution td . triggered_webhook , webhook_execution_result }
435
436
436
437
it "saves a new webhook execution " do
437
438
expect { subject } . to change { Execution . count } . by ( 1 )
@@ -444,6 +445,20 @@ module Webhooks
444
445
it "sets the logs" do
445
446
expect ( subject . logs ) . to eq "logs"
446
447
end
448
+
449
+ context "when the triggered webhook has been deleted in the meantime" do
450
+ before do
451
+ TriggeredWebhook . where ( id : td . triggered_webhook . id ) . delete
452
+ allow ( repository ) . to receive ( :logger ) . and_return ( logger )
453
+ end
454
+
455
+ let ( :logger ) { double ( 'logger' ) }
456
+
457
+ it "just logs the error" do
458
+ expect ( logger ) . to receive ( :info ) . with ( /triggered webhook with id #{ td . triggered_webhook . id } / )
459
+ subject
460
+ end
461
+ end
447
462
end
448
463
449
464
describe "delete_triggered_webhooks_by_webhook_uuid" do
You can’t perform that action at this time.
0 commit comments