@@ -14,6 +14,7 @@ module Pacts
14
14
15
15
before do
16
16
allow ( described_class ) . to receive ( :webhook_service ) . and_return ( webhook_service )
17
+ allow ( described_class ) . to receive ( :webhook_trigger_service ) . and_return ( webhook_trigger_service )
17
18
allow ( pacticipant_repository ) . to receive ( :find_by_name_or_create ) . with ( params [ :consumer_name ] ) . and_return ( consumer )
18
19
allow ( pacticipant_repository ) . to receive ( :find_by_name_or_create ) . with ( params [ :provider_name ] ) . and_return ( provider )
19
20
allow ( version_repository ) . to receive ( :find_by_pacticipant_id_and_number_or_create ) . and_return ( version )
@@ -22,9 +23,12 @@ module Pacts
22
23
allow ( pact_repository ) . to receive ( :update ) . and_return ( new_pact )
23
24
allow ( pact_repository ) . to receive ( :find_previous_pacts ) . and_return ( previous_pacts )
24
25
allow ( webhook_service ) . to receive ( :trigger_webhooks )
26
+ allow ( webhook_trigger_service ) . to receive ( :trigger_webhooks_for_new_pact )
27
+ allow ( webhook_trigger_service ) . to receive ( :trigger_webhooks_for_updated_pact )
25
28
end
26
29
27
30
let ( :webhook_service ) { class_double ( "PactBroker::Webhooks::Service" ) . as_stubbed_const }
31
+ let ( :webhook_trigger_service ) { class_double ( "PactBroker::Webhooks::TriggerService" ) . as_stubbed_const }
28
32
let ( :consumer ) { double ( 'consumer' , id : 1 ) }
29
33
let ( :provider ) { double ( 'provider' , id : 2 ) }
30
34
let ( :version ) { double ( 'version' , id : 3 , pacticipant_id : 1 ) }
@@ -52,7 +56,6 @@ module Pacts
52
56
53
57
subject { Service . create_or_update_pact ( params ) }
54
58
55
-
56
59
context "when no pact exists with the same params" do
57
60
it "creates the sha before adding the interaction ids" do
58
61
expect ( PactBroker ::Pacts ::GenerateSha ) . to receive ( :call ) . ordered
@@ -65,8 +68,8 @@ module Pacts
65
68
subject
66
69
end
67
70
68
- it "triggers webhooks for contract publications " do
69
- expect ( webhook_service ) . to receive ( :trigger_webhooks ) . with ( new_pact , nil , PactBroker :: Webhooks :: WebhookEvent :: CONTRACT_PUBLISHED )
71
+ it "triggers webhooks" do
72
+ expect ( webhook_trigger_service ) . to receive ( :trigger_webhooks_for_new_pact ) . with ( new_pact )
70
73
subject
71
74
end
72
75
end
@@ -85,8 +88,8 @@ module Pacts
85
88
subject
86
89
end
87
90
88
- it "triggers webhooks for contract publications " do
89
- expect ( webhook_service ) . to receive ( :trigger_webhooks ) . with ( new_pact , nil , PactBroker :: Webhooks :: WebhookEvent :: CONTRACT_PUBLISHED )
91
+ it "triggers webhooks" do
92
+ expect ( webhook_trigger_service ) . to receive ( :trigger_webhooks_for_updated_pact ) . with ( existing_pact , new_pact )
90
93
subject
91
94
end
92
95
end
@@ -111,91 +114,6 @@ module Pacts
111
114
end
112
115
end
113
116
114
- describe "#pact_is_new_or_pact_has_changed_since_previous_version?" do
115
- let ( :json_content ) { { 'some' => 'json' } . to_json }
116
- let ( :pact ) { instance_double ( PactBroker ::Domain ::Pact , json_content : json_content ) }
117
-
118
- subject { Service . pact_is_new_or_pact_has_changed_since_previous_version? pact }
119
-
120
- context "when consumer version is untagged" do
121
- before do
122
- allow ( pact ) . to receive ( :consumer_version_tag_names ) . and_return ( [ ] ) ;
123
- allow_any_instance_of ( Pacts ::Repository ) . to receive ( :find_previous_pact ) . with ( pact , :untagged ) . and_return ( previous_pact )
124
- end
125
-
126
- context "when a previous pact is found" do
127
- let ( :previous_pact ) { instance_double ( PactBroker ::Domain ::Pact , json_content : previous_json_content ) }
128
- let ( :previous_json_content ) { { 'some' => 'json' } . to_json }
129
-
130
- context "when the json_content is the same" do
131
- it "returns false" do
132
- expect ( subject ) . to be_falsey
133
- end
134
- end
135
-
136
- context "when the json_content is not the same" do
137
- let ( :previous_json_content ) { { 'some-other' => 'json' } . to_json }
138
- it "returns truthy" do
139
- expect ( subject ) . to be_truthy
140
- end
141
- end
142
- end
143
-
144
- context "when a previous pact is not found" do
145
- let ( :previous_pact ) { nil }
146
-
147
- it "returns true" do
148
- expect ( subject ) . to be_truthy
149
- end
150
- end
151
- end
152
-
153
- context "when consumer version has two tags" do
154
- before do
155
- allow ( pact ) . to receive ( :consumer_version_tag_names ) . and_return ( [ 'tag_1' , 'tag_2' ] ) ;
156
- allow_any_instance_of ( Pacts ::Repository ) . to receive ( :find_previous_pact ) . with ( pact , 'tag_1' ) . and_return ( previous_pact_tag_1 )
157
- allow_any_instance_of ( Pacts ::Repository ) . to receive ( :find_previous_pact ) . with ( pact , 'tag_2' ) . and_return ( previous_pact_tag_2 )
158
- end
159
-
160
- context "when a previous pact is found for both tags" do
161
- let ( :previous_pact_tag_1 ) { instance_double ( PactBroker ::Domain ::Pact , json_content : previous_json_content_tag_1 ) }
162
- let ( :previous_json_content_tag_1 ) { { 'some' => 'json' } . to_json }
163
-
164
- let ( :previous_pact_tag_2 ) { instance_double ( PactBroker ::Domain ::Pact , json_content : previous_json_content_tag_2 ) }
165
- let ( :previous_json_content_tag_2 ) { { 'some' => 'json' } . to_json }
166
-
167
- context "when the json_content of both previous pacts and new pact is the same" do
168
- it "returns false" do
169
- expect ( subject ) . to be_falsey
170
- end
171
- end
172
-
173
- context "when the json_content of first previous pact is not the same" do
174
- let ( :previous_json_content_tag_1 ) { { 'some-other' => 'json' } . to_json }
175
- it "returns truthy" do
176
- expect ( subject ) . to be_truthy
177
- end
178
- end
179
-
180
- context "when the json_content of second previous pact not the same" do
181
- let ( :previous_json_content_tag_2 ) { { 'some-other' => 'json' } . to_json }
182
- it "returns truthy" do
183
- expect ( subject ) . to be_truthy
184
- end
185
- end
186
- end
187
-
188
- context "when no previous pacts are found" do
189
- let ( :previous_pact_tag_1 ) { nil }
190
- let ( :previous_pact_tag_2 ) { nil }
191
-
192
- it "returns true" do
193
- expect ( subject ) . to be_truthy
194
- end
195
- end
196
- end
197
- end
198
-
199
117
describe "delete" do
200
118
before do
201
119
td . create_pact_with_hierarchy
0 commit comments