pact_broker-client 1.33.0 → 1.37.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/release_gem.yml +1 -0
  3. data/.github/workflows/test.yml +23 -0
  4. data/CHANGELOG.md +47 -0
  5. data/README.md +15 -3
  6. data/Rakefile +2 -0
  7. data/doc/pacts/markdown/Pact Broker Client - Pact Broker.md +331 -8
  8. data/lib/pact_broker/client.rb +1 -1
  9. data/lib/pact_broker/client/backports.rb +13 -0
  10. data/lib/pact_broker/client/cli/broker.rb +76 -33
  11. data/lib/pact_broker/client/cli/can_i_deploy_long_desc.txt +18 -9
  12. data/lib/pact_broker/client/cli/create_or_update_webhook_long_desc.txt +3 -1
  13. data/lib/pact_broker/client/cli/create_webhook_long_desc.txt +2 -0
  14. data/lib/pact_broker/client/cli/custom_thor.rb +11 -17
  15. data/lib/pact_broker/client/git.rb +43 -22
  16. data/lib/pact_broker/client/hal/entity.rb +27 -3
  17. data/lib/pact_broker/client/hal/http_client.rb +4 -0
  18. data/lib/pact_broker/client/hal/links.rb +39 -0
  19. data/lib/pact_broker/client/hal_client_methods.rb +11 -0
  20. data/lib/pact_broker/client/hash_refinements.rb +19 -0
  21. data/lib/pact_broker/client/matrix.rb +2 -1
  22. data/lib/pact_broker/client/matrix/text_formatter.rb +46 -11
  23. data/lib/pact_broker/client/publish_pacts.rb +93 -14
  24. data/lib/pact_broker/client/tasks/publication_task.rb +37 -6
  25. data/lib/pact_broker/client/version.rb +1 -1
  26. data/lib/pact_broker/client/versions/record_deployment.rb +109 -0
  27. data/pact-broker-client.gemspec +1 -0
  28. data/script/publish-pact.sh +7 -1
  29. data/script/trigger-release.sh +1 -1
  30. data/spec/lib/pact_broker/client/cli/broker_can_i_deploy_spec.rb +15 -2
  31. data/spec/lib/pact_broker/client/cli/broker_publish_spec.rb +108 -12
  32. data/spec/lib/pact_broker/client/cli/custom_thor_spec.rb +1 -7
  33. data/spec/lib/pact_broker/client/git_spec.rb +39 -2
  34. data/spec/lib/pact_broker/client/hal/entity_spec.rb +4 -3
  35. data/spec/lib/pact_broker/client/matrix/text_formatter_spec.rb +29 -4
  36. data/spec/lib/pact_broker/client/publish_pacts_spec.rb +119 -7
  37. data/spec/lib/pact_broker/client/tasks/publication_task_spec.rb +88 -10
  38. data/spec/lib/pact_broker/client/versions/describe_spec.rb +0 -1
  39. data/spec/lib/pact_broker/client/versions/record_deployment_spec.rb +82 -0
  40. data/spec/pacts/pact_broker_client-pact_broker.json +335 -8
  41. data/spec/service_providers/pact_broker_client_create_version_spec.rb +89 -0
  42. data/spec/service_providers/pact_broker_client_matrix_spec.rb +4 -0
  43. data/spec/service_providers/pact_broker_client_versions_spec.rb +1 -2
  44. data/spec/service_providers/record_deployment_spec.rb +219 -0
  45. data/spec/support/matrix.json +6 -1
  46. data/spec/support/matrix.txt +3 -3
  47. data/spec/support/matrix_error.txt +3 -3
  48. data/spec/support/matrix_with_results.txt +10 -0
  49. data/tasks/pact.rake +2 -0
  50. metadata +30 -4
  51. data/.travis.yml +0 -11
@@ -9,8 +9,9 @@ module PactBroker::Client
9
9
  end
10
10
 
11
11
  let(:provider_response) do
12
- double('response', body: provider_hash, success?: true)
12
+ double('response', body: provider_hash, success?: true, status: status)
13
13
  end
14
+ let(:status) { 200 }
14
15
 
15
16
  let(:provider_hash) do
16
17
  {
@@ -72,12 +73,12 @@ module PactBroker::Client
72
73
  subject(:entity) { ErrorEntity.new("http://pact", pact_hash, http_client) }
73
74
 
74
75
  it "raises an error" do
75
- expect { entity.assert_success! }.to raise_error ErrorResponseReturned, "Error retrieving http://pact status= "
76
+ expect { entity.assert_success! }.to raise_error ErrorResponseReturned, "Error retrieving http://pact status="
76
77
  end
77
78
  end
78
79
 
79
80
  context "when the response is not successful and there is a response" do
80
- let(:response) { double('response', code: 200, raw_body: "body") }
81
+ let(:response) { double('response', status: 200, raw_body: "body") }
81
82
 
82
83
  subject(:entity) { ErrorEntity.new("http://pact", pact_hash, http_client, response) }
83
84
 
@@ -1,29 +1,54 @@
1
+ require 'pact_broker/client/matrix/resource'
1
2
  require 'pact_broker/client/matrix/text_formatter'
2
3
 
3
4
  module PactBroker
4
5
  module Client
5
6
  describe Matrix::TextFormatter do
6
- let(:matrix_lines) { JSON.parse(File.read('spec/support/matrix.json'), symbolize_names: true)[:matrix] }
7
+ let(:matrix) { PactBroker::Client::Matrix::Resource.new(JSON.parse(File.read('spec/support/matrix.json'), symbolize_names: true)) }
7
8
  let(:expected_matrix_lines) { File.read('spec/support/matrix.txt') }
8
9
 
9
10
  # SublimeText removes whitespace from the end of files when you save them,
10
11
  # so removing trailing whitespace before comparing
11
- subject { Matrix::TextFormatter.call(matrix: matrix_lines).split("\n").collect(&:strip).join("\n") }
12
+ def strip_trailing_whitespace(text)
13
+ text.split("\n").collect(&:strip).join("\n")
14
+ end
15
+
16
+ subject { strip_trailing_whitespace(Matrix::TextFormatter.call(matrix)) }
12
17
 
13
18
  context "with valid data" do
14
19
  it "it has the right text" do
15
- expect(subject).to eq expected_matrix_lines
20
+ expect(subject).to start_with expected_matrix_lines
16
21
  end
17
22
  end
18
23
 
19
24
  context "with invalid data" do
20
25
  let(:expected_matrix_lines) { File.read('spec/support/matrix_error.txt') }
21
- let(:matrix_lines) { [{}] }
26
+ let(:matrix) { PactBroker::Client::Matrix::Resource.new(matrix: [{}]) }
22
27
 
23
28
  it "doesn't blow up" do
24
29
  expect(subject).to eq expected_matrix_lines
25
30
  end
26
31
  end
32
+
33
+ context "when some rows have a verification result URL and some don't" do
34
+ let(:matrix_lines) do
35
+ line_creator = -> { JSON.parse(File.read('spec/support/matrix.json'), symbolize_names: true)[:matrix].first }
36
+ line_1 = line_creator.call
37
+ line_2 = line_creator.call
38
+ line_3 = line_creator.call
39
+ line_2[:verificationResult] = nil
40
+ line_3[:verificationResult][:success] = false
41
+ [line_1, line_2, line_3]
42
+ end
43
+
44
+ let(:matrix) { PactBroker::Client::Matrix::Resource.new(matrix: matrix_lines) }
45
+
46
+ let(:expected_matrix_lines) { File.read('spec/support/matrix_with_results.txt') }
47
+
48
+ it "only provides a result number for the lines that have a result URL" do
49
+ expect(subject).to eq expected_matrix_lines
50
+ end
51
+ end
27
52
  end
28
53
  end
29
54
  end
@@ -23,6 +23,7 @@ module PactBroker
23
23
  File.open("spec/pacts/consumer-provider.json", "w") { |file| file << pact_hash.to_json }
24
24
  File.open("spec/pacts/consumer-provider-2.json", "w") { |file| file << pact_hash.to_json }
25
25
  File.open("spec/pacts/foo-bar.json", "w") { |file| file << pact_hash_2.to_json }
26
+ allow_any_instance_of(PublishPacts).to receive(:create_index_entry_point).and_return(index_entry_point)
26
27
  end
27
28
 
28
29
  after do
@@ -34,11 +35,23 @@ module PactBroker
34
35
  let(:pact_file_paths) { ['spec/pacts/consumer-provider.json']}
35
36
  let(:consumer_version) { "1.2.3" }
36
37
  let(:tags) { nil }
37
- let(:pact_hash) { {consumer: {name: 'Consumer'}, provider: {name: 'Provider'}, interactions: [] } }
38
- let(:pact_hash_2) { {consumer: {name: 'Foo'}, provider: {name: 'Bar'}, interactions: [] } }
38
+ let(:branch) { nil }
39
+ let(:build_url) { nil }
40
+ let(:version_required) { false }
41
+ let(:pact_hash) { { consumer: { name: 'Consumer'}, provider: { name: 'Provider' }, interactions: [] } }
42
+ let(:pact_hash_2) { {consumer: { name: 'Foo' }, provider: { name: 'Bar' }, interactions: [] } }
39
43
  let(:pacts_client) { instance_double("PactBroker::ClientSupport::Pacts")}
40
44
  let(:pact_versions_client) { instance_double("PactBroker::Client::Versions", tag: false) }
41
45
  let(:pact_broker_base_url) { 'http://some-host'}
46
+ let(:consumer_version_params) do
47
+ {
48
+ number: consumer_version,
49
+ branch: branch,
50
+ tags: tags,
51
+ build_url: build_url,
52
+ version_required: version_required
53
+ }
54
+ end
42
55
  let(:pact_broker_client_options) do
43
56
  {
44
57
  basic_auth: {
@@ -47,8 +60,11 @@ module PactBroker
47
60
  }
48
61
  }
49
62
  end
63
+ let(:index_entry_point) { instance_double("PactBroker::Client::Hal::EntryPoint", :get! => index_resource )}
64
+ let(:index_resource) { instance_double("PactBroker::Client::Hal::Entity", can?: can_create_version ) }
65
+ let(:can_create_version) { false }
50
66
 
51
- subject { PublishPacts.new(pact_broker_base_url, pact_file_paths, consumer_version, tags, pact_broker_client_options) }
67
+ subject { PublishPacts.new(pact_broker_base_url, pact_file_paths, consumer_version_params, pact_broker_client_options) }
52
68
 
53
69
  describe "call" do
54
70
  it "creates a PactBroker Client" do
@@ -62,12 +78,12 @@ module PactBroker
62
78
  end
63
79
 
64
80
  context "when publishing is successful" do
65
-
66
81
  it "puts the location of the latest pact" do
67
82
  allow($stdout).to receive(:puts)
68
83
  expect($stdout).to receive(:puts).with(/#{latest_pact_url}/)
69
84
  subject.call
70
85
  end
86
+
71
87
  it "returns true" do
72
88
  expect(subject.call).to be true
73
89
  end
@@ -142,6 +158,15 @@ module PactBroker
142
158
  end
143
159
  end
144
160
 
161
+ context "when consumer_version has a new line" do
162
+ let(:consumer_version) { "1\n" }
163
+
164
+ it "strips the new line" do
165
+ expect(pacts_client).to receive(:publish).with(pact_hash: pact_hash, consumer_version: "1")
166
+ subject.call
167
+ end
168
+ end
169
+
145
170
  context "when pact_broker_base_url is blank" do
146
171
  let(:pact_broker_base_url) { " " }
147
172
  it "raises a validation errror" do
@@ -164,8 +189,17 @@ module PactBroker
164
189
  subject.call
165
190
  end
166
191
 
167
- context "when an error occurs tagging the pact" do
192
+ context "when the tag has a new line on the end of it" do
193
+ let(:tags) { ["foo\n"] }
168
194
 
195
+ it "strips the newline" do
196
+ expect(pact_versions_client).to receive(:tag).with({pacticipant: "Consumer",
197
+ version: consumer_version, tag: "foo"})
198
+ subject.call
199
+ end
200
+ end
201
+
202
+ context "when an error occurs tagging the pact" do
169
203
  before do
170
204
  allow(pact_versions_client).to receive(:tag).and_raise("an error")
171
205
  allow(Retry).to receive(:sleep)
@@ -184,7 +218,6 @@ module PactBroker
184
218
  end
185
219
 
186
220
  context "when an error occurs every time while publishing a pact" do
187
-
188
221
  before do
189
222
  allow(Retry).to receive(:sleep)
190
223
  allow(pacts_client).to receive(:publish).and_raise("an error")
@@ -202,7 +235,6 @@ module PactBroker
202
235
  end
203
236
 
204
237
  context "when an error occurs less than the maximum number of retries" do
205
-
206
238
  before do
207
239
  allow(Retry).to receive(:sleep)
208
240
  tries = 0
@@ -226,6 +258,86 @@ module PactBroker
226
258
  expect(subject.call).to eq true
227
259
  end
228
260
  end
261
+
262
+ context "when the broker does not support creation of a version with a branch but a branch is specified" do
263
+ let(:branch) { "main" }
264
+
265
+ context "when version_required is true" do
266
+ let(:version_required) { true }
267
+
268
+ it "raises an error" do
269
+ expect { subject.call }.to raise_error PactBroker::Client::Error
270
+ end
271
+ end
272
+ end
273
+
274
+ context "when the broker supports creation of a version with a branch" do
275
+ before do
276
+ allow(version_link).to receive(:expand).and_return(version_link)
277
+ allow(version_resource).to receive(:assert_success!).and_return(version_resource)
278
+ allow(version_resource).to receive_message_chain(:response, :status).and_return(version_creation_response_status)
279
+ end
280
+ let(:can_create_version) { true }
281
+ let(:version_link) { instance_double("PactBroker::Client::Hal::Link", put: version_resource) }
282
+ let(:version_resource) { instance_double("PactBroker::Client::Hal::Entity") }
283
+ let(:version_creation_response_status) { 201 }
284
+
285
+ before do
286
+ allow(index_resource).to receive(:_link).and_return(version_link)
287
+ end
288
+
289
+ context "when there is a branch, build_url or tags specified" do
290
+ let(:tags) { ["dev"] }
291
+ let(:branch) { ["main"] }
292
+ let(:build_url) { "build_url" }
293
+
294
+ it "creates a version with the branch, build_url and tags" do
295
+ expect(index_resource).to receive(:_link)
296
+ expect(version_link).to receive(:expand).with(pacticipant: "Consumer", version: "1.2.3")
297
+ expect(version_link).to receive(:put).with(branch: branch, buildUrl: build_url)
298
+ subject.call
299
+ end
300
+
301
+ context "when there is a branch but no tags" do
302
+ let(:tags) { [] }
303
+
304
+ it "does not set the tags, as this would overwrite the existing ones - not sure about this implementation" do
305
+ expect(version_link).to receive(:put).with(branch: branch, buildUrl: build_url)
306
+ subject.call
307
+ end
308
+ end
309
+
310
+ context "when the version response status is 201" do
311
+ it "puts a message indicating the version was created" do
312
+ expect($stdout).to receive(:puts).with(/Created/)
313
+ subject.call
314
+ end
315
+ end
316
+
317
+ context "when the version response status is 200" do
318
+ let(:version_creation_response_status) { 200 }
319
+
320
+ it "puts a message indicating the version was replaced" do
321
+ expect($stdout).to receive(:puts).with(/Replaced/)
322
+ subject.call
323
+ end
324
+ end
325
+ end
326
+
327
+ context "when there is no branch, tags or build_url specified" do
328
+ before do
329
+ allow(Retry).to receive(:while_error) { |&block| block.call }
330
+ end
331
+ let(:tags) { [] }
332
+ let(:branch) { nil }
333
+ let(:build_url) { nil }
334
+
335
+ it "does not create a version resource" do
336
+ expect(index_resource).to_not receive(:_link)
337
+ subject.call
338
+ end
339
+ end
340
+ end
229
341
  end
230
342
  end
231
343
  end
@@ -3,7 +3,6 @@ require 'pact_broker/client/tasks/publication_task'
3
3
  require 'pact_broker/client/publish_pacts'
4
4
 
5
5
  module PactBroker::Client
6
-
7
6
  describe PublicationTask do
8
7
 
9
8
  before do
@@ -22,7 +21,6 @@ module PactBroker::Client
22
21
  let(:pattern) { "spec/pacts/*.json" }
23
22
 
24
23
  describe "default task" do
25
-
26
24
  before :all do
27
25
  PactBroker::Client::PublicationTask.new do | task |
28
26
  task.consumer_version = '1.2.3'
@@ -31,7 +29,7 @@ module PactBroker::Client
31
29
 
32
30
  context "when pacts are succesfully published" do
33
31
  it "invokes PublishPacts with the default values" do
34
- expect(PactBroker::Client::PublishPacts).to receive(:new).with('http://pact-broker', pact_file_list, '1.2.3', [], {}).and_return(publish_pacts)
32
+ expect(PactBroker::Client::PublishPacts).to receive(:new).with('http://pact-broker', pact_file_list, { number: '1.2.3', branch: "foo", tags: [], version_required: false}, {}).and_return(publish_pacts)
35
33
  expect(publish_pacts).to receive(:call).and_return(true)
36
34
  Rake::Task['pact:publish'].execute
37
35
  end
@@ -54,7 +52,7 @@ module PactBroker::Client
54
52
  end
55
53
 
56
54
  it "invokes PublishPacts with the write method set" do
57
- expect(PactBroker::Client::PublishPacts).to receive(:new).with('http://pact-broker', pact_file_list, '1.2.3', [], {write: :merge}).and_return(publish_pacts)
55
+ expect(PactBroker::Client::PublishPacts).to receive(:new).with('http://pact-broker', pact_file_list, { number: "1.2.3", branch: "foo", tags: [], version_required: false }, {write: :merge}).and_return(publish_pacts)
58
56
  expect(publish_pacts).to receive(:call).and_return(true)
59
57
  Rake::Task['pact:publish:merge'].execute
60
58
  end
@@ -65,17 +63,98 @@ module PactBroker::Client
65
63
  PactBroker::Client::PublicationTask.new(:git_branch) do | task |
66
64
  task.consumer_version = '1.2.3'
67
65
  task.tag_with_git_branch = true
66
+ task.auto_detect_version_properties = false
68
67
  task.tags = ['bar']
69
68
  end
70
69
  end
71
70
 
72
- it "invokes PublishPacts with the git branch name as a tag" do
73
- expect(PactBroker::Client::PublishPacts).to receive(:new).with(anything, anything, anything, ['bar', 'foo'], anything).and_return(publish_pacts)
71
+ it "gets the git branch name" do
72
+ expect(PactBroker::Client::Git).to receive(:branch).with(raise_error: true)
73
+ Rake::Task['pact:publish:git_branch'].execute
74
+ end
74
75
 
76
+ it "invokes PublishPacts with the git branch name as a tag" do
77
+ expect(PactBroker::Client::PublishPacts).to receive(:new).with(anything, anything, hash_including(tags: ['bar', 'foo']), anything).and_return(publish_pacts)
75
78
  Rake::Task['pact:publish:git_branch'].execute
76
79
  end
77
80
  end
78
81
 
82
+ context "when auto_detect_version_properties is explicitly set to true" do
83
+ before :all do
84
+ PactBroker::Client::PublicationTask.new(:git_branch_auto_detect_true) do | task |
85
+ task.consumer_version = '1.2.3'
86
+ task.auto_detect_version_properties = true
87
+ end
88
+ end
89
+
90
+ it "gets the git branch name" do
91
+ expect(PactBroker::Client::Git).to receive(:branch).with(raise_error: true)
92
+ Rake::Task['pact:publish:git_branch_auto_detect_true'].execute
93
+ end
94
+
95
+ it "invokes PublishPacts with the branch name" do
96
+ expect(PactBroker::Client::PublishPacts).to receive(:new).with(anything, anything, hash_including(branch: "foo"), anything).and_return(publish_pacts)
97
+ Rake::Task['pact:publish:git_branch_auto_detect_true'].execute
98
+ end
99
+ end
100
+
101
+ context "when auto_detect_version_properties is explicitly set to true and the branch is specified" do
102
+ before :all do
103
+ PactBroker::Client::PublicationTask.new(:git_branch_auto_detect_true_with_branch) do | task |
104
+ task.consumer_version = '1.2.3'
105
+ task.auto_detect_version_properties = true
106
+ task.branch = "main"
107
+ end
108
+ end
109
+
110
+ it "does not get the branch name" do
111
+ expect(PactBroker::Client::Git).to_not receive(:branch)
112
+ Rake::Task['pact:publish:git_branch_auto_detect_true_with_branch'].execute
113
+ end
114
+
115
+ it "invokes PublishPacts with the specified branch name" do
116
+ expect(PactBroker::Client::PublishPacts).to receive(:new).with(anything, anything, hash_including(branch: "main"), anything).and_return(publish_pacts)
117
+ Rake::Task['pact:publish:git_branch_auto_detect_true_with_branch'].execute
118
+ end
119
+ end
120
+
121
+ context "when auto_detect_version_properties is explicitly set to false" do
122
+ before :all do
123
+ PactBroker::Client::PublicationTask.new(:git_branch_auto_detect_false) do | task |
124
+ task.consumer_version = '1.2.3'
125
+ task.auto_detect_version_properties = false
126
+ end
127
+ end
128
+
129
+ it "does not get the git branch name" do
130
+ expect(PactBroker::Client::Git).to_not receive(:branch)
131
+ Rake::Task['pact:publish:git_branch_auto_detect_false'].execute
132
+ end
133
+
134
+ it "invokes PublishPacts without the branch name" do
135
+ expect(PactBroker::Client::PublishPacts).to receive(:new).with(anything, anything, hash_not_including(branch: "foo"), anything).and_return(publish_pacts)
136
+ Rake::Task['pact:publish:git_branch_auto_detect_false'].execute
137
+ end
138
+ end
139
+
140
+ context "when auto_detect_version_properties is left as its default" do
141
+ before :all do
142
+ PactBroker::Client::PublicationTask.new(:git_branch_auto_detect_default) do | task |
143
+ task.consumer_version = '1.2.3'
144
+ end
145
+ end
146
+
147
+ it "gets the git branch name" do
148
+ expect(PactBroker::Client::Git).to receive(:branch).with(raise_error: false)
149
+ Rake::Task['pact:publish:git_branch_auto_detect_default'].execute
150
+ end
151
+
152
+ it "invokes PublishPacts with the branch name" do
153
+ expect(PactBroker::Client::PublishPacts).to receive(:new).with(anything, anything, hash_including(branch: "foo"), anything).and_return(publish_pacts)
154
+ Rake::Task['pact:publish:git_branch_auto_detect_default'].execute
155
+ end
156
+ end
157
+
79
158
  describe "custom task" do
80
159
 
81
160
  before :all do
@@ -98,10 +177,9 @@ module PactBroker::Client
98
177
 
99
178
  it "invokes PublishPacts with the customised values" do
100
179
  expect(PactBroker::Client::PublishPacts).to receive(:new).with(
101
- @pact_broker_base_url,
102
- pact_file_list,
103
- '1.2.3',
104
- [@tag],
180
+ @pact_broker_base_url,
181
+ pact_file_list,
182
+ { number: "1.2.3", tags: [@tag], branch: "foo", version_required: false},
105
183
  { basic_auth: @pact_broker_basic_auth, token: @pact_broker_token }
106
184
  )
107
185
  expect(publish_pacts).to receive(:call).and_return(true)
@@ -5,7 +5,6 @@ module PactBroker
5
5
  class Versions
6
6
  describe Describe do
7
7
  describe ".call" do
8
-
9
8
  let(:versions_client) do
10
9
  instance_double('PactBroker::Client::Versions', latest: version_hash)
11
10
  end
@@ -0,0 +1,82 @@
1
+ require 'pact_broker/client/versions/record_deployment'
2
+
3
+ module PactBroker
4
+ module Client
5
+ class Versions
6
+ describe RecordDeployment do
7
+ describe ".call" do
8
+ let(:broker_base_url) { "http://broker" }
9
+ let(:index_body_hash) do
10
+ {
11
+ _links: {}
12
+ }
13
+ end
14
+ let!(:index_request) do
15
+ stub_request(:get, broker_base_url).to_return(status: 200, body: index_body_hash.to_json, headers: { "Content-Type" => "application/hal+json" } )
16
+ end
17
+
18
+ let(:replaced_previous_deployed_version) { true }
19
+
20
+ let(:params) do
21
+ {
22
+ pacticipant_name: "Foo",
23
+ version_number: "1",
24
+ environment_name: "test",
25
+ replaced_previous_deployed_version: replaced_previous_deployed_version,
26
+ output: "text"
27
+ }
28
+ end
29
+
30
+ let(:pact_broker_client_options) { {} }
31
+
32
+ subject { RecordDeployment.call(params, broker_base_url, pact_broker_client_options) }
33
+
34
+ context "when the pb:environments relation does not exist" do
35
+ it "returns an error response" do
36
+ expect(subject.success).to be false
37
+ expect(subject.message).to include "does not support"
38
+ end
39
+ end
40
+
41
+ context "when the response headers contain Pactflow" do
42
+ before do
43
+ allow_any_instance_of(RecordDeployment).to receive(:check_if_command_supported)
44
+ allow_any_instance_of(RecordDeployment).to receive(:check_environment_exists)
45
+ allow_any_instance_of(RecordDeployment).to receive(:record_deployment)
46
+ allow_any_instance_of(RecordDeployment).to receive(:deployed_version_resource).and_return(deployed_version_resource)
47
+ end
48
+
49
+ let(:response_headers) { { "X-Pactflow-Sha" => "abc" } }
50
+
51
+ let(:deployed_version_resource) do
52
+ double('PactBroker::Client::Hal::Entity', response: double('response', headers: response_headers) )
53
+ end
54
+
55
+ it "indicates the API was Pactflow" do
56
+ expect(subject.message).to include "Recorded deployment of Foo version 1 to test in Pactflow"
57
+ end
58
+ end
59
+
60
+ context "when replaced_previous_deployed_version is false" do
61
+ before do
62
+ allow_any_instance_of(RecordDeployment).to receive(:check_if_command_supported)
63
+ allow_any_instance_of(RecordDeployment).to receive(:check_environment_exists)
64
+ allow_any_instance_of(RecordDeployment).to receive(:record_deployment)
65
+ allow_any_instance_of(RecordDeployment).to receive(:pact_broker_name).and_return("")
66
+ end
67
+
68
+ let(:replaced_previous_deployed_version) { false }
69
+
70
+ let(:deployed_version_resource) do
71
+ double('PactBroker::Client::Hal::Entity', response: double('response', headers: response_headers) )
72
+ end
73
+
74
+ it "does not include the message about marking the previous version as undeployed" do
75
+ expect(subject.message).to_not include "undeployed"
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
81
+ end
82
+ end