@@ -8,14 +8,21 @@ module Webhooks
8
8
PactBroker . configuration . webhook_retry_schedule = [ 10 , 60 , 120 , 300 , 600 , 1200 ]
9
9
allow ( PactBroker ::Webhooks ::Service ) . to receive ( :execute_triggered_webhook_now ) . and_return ( result )
10
10
allow ( PactBroker ::Webhooks ::Service ) . to receive ( :update_triggered_webhook_status )
11
+ allow ( PactBroker ::Webhooks ::TriggeredWebhook ) . to receive ( :find ) . and_return ( triggered_webhook )
11
12
end
12
13
13
14
let ( :triggered_webhook ) { instance_double ( "PactBroker::Webhooks::TriggeredWebhook" , webhook_uuid : '1234' , id : 1 ) }
14
15
let ( :result ) { instance_double ( "PactBroker::Domain::WebhookExecutionResult" , success? : success ) }
15
16
let ( :success ) { true }
16
17
18
+ subject { Job . new . perform ( triggered_webhook : triggered_webhook ) }
19
+
20
+ it "reloads the TriggeredWebhook object to make sure it has a fresh copy" do
21
+ expect ( PactBroker ::Webhooks ::TriggeredWebhook ) . to receive ( :find ) . with ( id : 1 )
22
+ subject
23
+ end
24
+
17
25
context "when the job succeeds" do
18
- subject { Job . new . perform ( triggered_webhook : triggered_webhook ) }
19
26
20
27
it "does not reschedule the job" do
21
28
expect ( Job ) . to_not receive ( :perform_in )
@@ -34,8 +41,6 @@ module Webhooks
34
41
allow ( PactBroker ::Webhooks ::Service ) . to receive ( :execute_triggered_webhook_now ) . and_raise ( "an error" )
35
42
end
36
43
37
- subject { Job . new . perform ( triggered_webhook : triggered_webhook ) }
38
-
39
44
it "reschedules the job in 10 seconds" do
40
45
expect ( Job ) . to receive ( :perform_in ) . with ( 10 , { triggered_webhook : triggered_webhook , error_count : 1 } )
41
46
subject
@@ -51,8 +56,6 @@ module Webhooks
51
56
context "when the webhook execution result is not successful for the first time" do
52
57
let ( :success ) { false }
53
58
54
- subject { Job . new . perform ( triggered_webhook : triggered_webhook ) }
55
-
56
59
it "reschedules the job in 10 seconds" do
57
60
expect ( Job ) . to receive ( :perform_in ) . with ( 10 , { triggered_webhook : triggered_webhook , error_count : 1 } )
58
61
subject
0 commit comments