pact_broker-client 1.75.2 → 1.75.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (112) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +10 -0
  3. data/lib/pact_broker/client/version.rb +1 -1
  4. metadata +19 -216
  5. data/.github/workflows/test.yml +0 -59
  6. data/.rspec +0 -3
  7. data/lib/pact_broker/client/pacts/list_latest_versions.rb +0 -66
  8. data/lib/pact_broker/client/webhooks/test.rb +0 -16
  9. data/pact-broker-client.gemspec +0 -30
  10. data/spec/fixtures/MyConsumer-MyProvider (1).json +0 -37
  11. data/spec/fixtures/MyConsumer-MyProvider.json +0 -37
  12. data/spec/fixtures/approvals/can_i_deploy_failure_dry_run.approved.txt +0 -7
  13. data/spec/fixtures/approvals/can_i_deploy_ignore.approved.txt +0 -13
  14. data/spec/fixtures/approvals/can_i_deploy_success_dry_run.approved.txt +0 -7
  15. data/spec/fixtures/approvals/describe_environment.approved.txt +0 -7
  16. data/spec/fixtures/approvals/describe_pacticipant.approved.txt +0 -2
  17. data/spec/fixtures/approvals/list_environments.approved.txt +0 -3
  18. data/spec/fixtures/approvals/publish_provider_contract.approved.txt +0 -2
  19. data/spec/fixtures/certificates/ca_cert.pem +0 -19
  20. data/spec/fixtures/certificates/ca_cert.srl +0 -1
  21. data/spec/fixtures/certificates/ca_key.pem +0 -28
  22. data/spec/fixtures/certificates/client_cert.pem +0 -17
  23. data/spec/fixtures/certificates/key.pem +0 -28
  24. data/spec/fixtures/certificates/server.csr +0 -15
  25. data/spec/fixtures/certificates/unsigned_cert.pem +0 -19
  26. data/spec/fixtures/certificates/unsigned_key.pem +0 -28
  27. data/spec/fixtures/foo-bar.json +0 -31
  28. data/spec/integration/can_i_deploy_spec.rb +0 -24
  29. data/spec/integration/can_i_merge_spec.rb +0 -44
  30. data/spec/integration/create_version_tag_spec.rb +0 -20
  31. data/spec/integration/describe_environment_spec.rb +0 -31
  32. data/spec/integration/publish_provider_contract_spec.rb +0 -53
  33. data/spec/integration/unknown_options_spec.rb +0 -39
  34. data/spec/lib/pact_broker/client/base_client_spec.rb +0 -182
  35. data/spec/lib/pact_broker/client/branches/delete_branch_spec.rb +0 -103
  36. data/spec/lib/pact_broker/client/can_i_deploy_spec.rb +0 -250
  37. data/spec/lib/pact_broker/client/cli/broker_can_i_deploy_spec.rb +0 -196
  38. data/spec/lib/pact_broker/client/cli/broker_create_or_update_webhook_spec.rb +0 -23
  39. data/spec/lib/pact_broker/client/cli/broker_create_webhook_spec.rb +0 -23
  40. data/spec/lib/pact_broker/client/cli/broker_publish_spec.rb +0 -327
  41. data/spec/lib/pact_broker/client/cli/broker_run_webhook_commands_spec.rb +0 -287
  42. data/spec/lib/pact_broker/client/cli/custom_thor_spec.rb +0 -174
  43. data/spec/lib/pact_broker/client/cli/version_selector_options_parser_spec.rb +0 -97
  44. data/spec/lib/pact_broker/client/deployments/record_deployment_spec.rb +0 -224
  45. data/spec/lib/pact_broker/client/deployments/record_support_ended_spec.rb +0 -208
  46. data/spec/lib/pact_broker/client/deployments/record_undeployment_spec.rb +0 -227
  47. data/spec/lib/pact_broker/client/environments/delete_environment_spec.rb +0 -120
  48. data/spec/lib/pact_broker/client/environments/describe_environment_spec.rb +0 -89
  49. data/spec/lib/pact_broker/client/environments/update_environment_spec.rb +0 -167
  50. data/spec/lib/pact_broker/client/generate_display_name_spec.rb +0 -39
  51. data/spec/lib/pact_broker/client/git_spec.rb +0 -159
  52. data/spec/lib/pact_broker/client/hal/authorization_header_redactor_spec.rb +0 -17
  53. data/spec/lib/pact_broker/client/hal/entity_spec.rb +0 -149
  54. data/spec/lib/pact_broker/client/hal/http_client_spec.rb +0 -238
  55. data/spec/lib/pact_broker/client/hal/link_spec.rb +0 -127
  56. data/spec/lib/pact_broker/client/matrix/abbreviate_version_number_spec.rb +0 -42
  57. data/spec/lib/pact_broker/client/matrix/resource_spec.rb +0 -70
  58. data/spec/lib/pact_broker/client/matrix/text_formatter_spec.rb +0 -63
  59. data/spec/lib/pact_broker/client/matrix_spec.rb +0 -17
  60. data/spec/lib/pact_broker/client/merge_pacts_spec.rb +0 -198
  61. data/spec/lib/pact_broker/client/pact_broker_client_spec.rb +0 -47
  62. data/spec/lib/pact_broker/client/pacticipants/create_spec.rb +0 -31
  63. data/spec/lib/pact_broker/client/pacticipants_spec.rb +0 -18
  64. data/spec/lib/pact_broker/client/publish_pacts_the_old_way_spec.rb +0 -272
  65. data/spec/lib/pact_broker/client/retry_spec.rb +0 -119
  66. data/spec/lib/pact_broker/client/tasks/publication_task_spec.rb +0 -231
  67. data/spec/lib/pact_broker/client/versions/create_spec.rb +0 -174
  68. data/spec/lib/pact_broker/client/versions/describe_spec.rb +0 -64
  69. data/spec/lib/pact_broker/client/versions_spec.rb +0 -34
  70. data/spec/lib/pact_broker/client/webhooks/create_spec.rb +0 -99
  71. data/spec/lib/pactflow/client/provider_contracts/publish_spec.rb +0 -179
  72. data/spec/pacts/pact_broker_client-pact_broker.json +0 -2969
  73. data/spec/pacts/pact_broker_client-pactflow.json +0 -288
  74. data/spec/readme_spec.rb +0 -16
  75. data/spec/service_providers/create_environment_spec.rb +0 -78
  76. data/spec/service_providers/delete_branch_spec.rb +0 -68
  77. data/spec/service_providers/extra_goodies_spec.rb +0 -108
  78. data/spec/service_providers/list_environments_spec.rb +0 -77
  79. data/spec/service_providers/list_latest_pact_versions_spec.rb.bak +0 -44
  80. data/spec/service_providers/pact_broker_client_matrix_ignore_spec.rb +0 -98
  81. data/spec/service_providers/pact_broker_client_matrix_spec.rb +0 -292
  82. data/spec/service_providers/pact_broker_client_pacticipant_version_spec.rb +0 -56
  83. data/spec/service_providers/pact_broker_client_publish_spec.rb +0 -135
  84. data/spec/service_providers/pact_broker_client_register_repository_spec.rb +0 -49
  85. data/spec/service_providers/pact_broker_client_retrieve_all_pacts_for_provider_spec.rb +0 -53
  86. data/spec/service_providers/pact_broker_client_retrieve_pact_spec.rb +0 -109
  87. data/spec/service_providers/pact_broker_client_tags_spec.rb +0 -101
  88. data/spec/service_providers/pact_broker_client_versions_spec.rb +0 -113
  89. data/spec/service_providers/pact_helper.rb +0 -136
  90. data/spec/service_providers/pactflow_publish_provider_contract_spec.rb +0 -137
  91. data/spec/service_providers/pactflow_publish_provider_contract_the_old_way_spec.rb +0 -129
  92. data/spec/service_providers/pactflow_webhooks_create_spec.rb +0 -86
  93. data/spec/service_providers/pacticipants_create_spec.rb +0 -119
  94. data/spec/service_providers/publish_pacts_spec.rb +0 -114
  95. data/spec/service_providers/record_deployment_spec.rb +0 -199
  96. data/spec/service_providers/record_release_spec.rb +0 -130
  97. data/spec/service_providers/record_undeployment_spec.rb +0 -164
  98. data/spec/service_providers/webhooks_create_spec.rb +0 -391
  99. data/spec/spec_helper.rb +0 -68
  100. data/spec/support/approvals.rb +0 -26
  101. data/spec/support/cli_test_pacts/bar.json +0 -0
  102. data/spec/support/cli_test_pacts/foo.json +0 -0
  103. data/spec/support/latest_pacts_for_provider.json +0 -15
  104. data/spec/support/matrix.json +0 -35
  105. data/spec/support/matrix.txt +0 -3
  106. data/spec/support/matrix_error.txt +0 -3
  107. data/spec/support/matrix_with_results.txt +0 -10
  108. data/spec/support/pacticipant_get.json +0 -18
  109. data/spec/support/pacticipants_list.json +0 -26
  110. data/spec/support/pacts_latest_list.json +0 -41
  111. data/spec/support/shared_context.rb +0 -25
  112. data/spec/support/ssl_server.rb +0 -42
@@ -1,231 +0,0 @@
1
- require 'spec_helper'
2
- require 'pact_broker/client/tasks/publication_task'
3
- require 'pact_broker/client/publish_pacts'
4
- require 'pact_broker/client/command_result'
5
-
6
- module PactBroker::Client
7
- describe PublicationTask do
8
- before do
9
- @consumer_version = "1.2.3"
10
- end
11
-
12
- let(:publish_pacts) { instance_double("PactBroker::ClientSupport::PublishPacts", call: result)}
13
- let(:pact_file_list) { ['spec/pact/consumer-provider.json'] }
14
- let(:success) { true }
15
- let(:result) { instance_double(PactBroker::Client::CommandResult, success: success, message: "message")}
16
-
17
- before do
18
- allow(PactBroker::Client::PublishPacts).to receive(:new).and_return(publish_pacts)
19
- allow(FileList).to receive(:[]).with(pattern).and_return(pact_file_list)
20
- allow(PactBroker::Client::Git).to receive(:branch).and_return('foo')
21
- allow(PactBroker::Client::Git).to receive(:commit).and_return('6.6.6')
22
- allow(PactBroker::Client::Git).to receive(:build_url).and_return("build_url")
23
- allow($stdout).to receive(:puts)
24
- end
25
-
26
- let(:pattern) { "spec/pacts/*.json" }
27
-
28
- describe "default task" do
29
- before :all do
30
- PactBroker::Client::PublicationTask.new do | task |
31
- task.consumer_version = '1.2.3'
32
- end
33
- end
34
-
35
- context "when pacts are succesfully published" do
36
- it "invokes PublishPacts with the default values" do
37
- expect(PactBroker::Client::PublishPacts).to receive(:new).with('http://pact-broker', pact_file_list, { number: '1.2.3', branch: "foo", tags: [] }, {}, {}).and_return(publish_pacts)
38
- expect(publish_pacts).to receive(:call).and_return(result)
39
- Rake::Task['pact:publish'].execute
40
- end
41
- end
42
-
43
- context "when a pact fails to be published" do
44
- let(:success) { false }
45
-
46
- it "raises an error" do
47
- expect { Rake::Task['pact:publish'].execute }.to raise_error("One or more pacts failed to be published")
48
- end
49
- end
50
- end
51
-
52
- describe "merge method configuration" do
53
- before :all do
54
- PactBroker::Client::PublicationTask.new(:merge) do | task |
55
- task.consumer_version = '1.2.3'
56
- task.write_method = :merge
57
- end
58
- end
59
-
60
- it "invokes PublishPacts with the write method set" do
61
- expect(PactBroker::Client::PublishPacts).to receive(:new).with('http://pact-broker', pact_file_list, { number: "1.2.3", branch: "foo", tags: [] }, {}, {write: :merge}).and_return(publish_pacts)
62
- expect(publish_pacts).to receive(:call).and_return(result)
63
- Rake::Task['pact:publish:merge'].execute
64
- end
65
- end
66
-
67
- context "when tag_with_git_branch is true" do
68
- before :all do
69
- PactBroker::Client::PublicationTask.new(:git_branch) do | task |
70
- task.consumer_version = '1.2.3'
71
- task.tag_with_git_branch = true
72
- task.auto_detect_version_properties = false
73
- task.tags = ['bar']
74
- end
75
- end
76
-
77
- it "gets the git branch name" do
78
- expect(PactBroker::Client::Git).to receive(:branch).with(raise_error: true)
79
- Rake::Task['pact:publish:git_branch'].execute
80
- end
81
-
82
- it "invokes PublishPacts with the git branch name as a tag" do
83
- expect(PactBroker::Client::PublishPacts).to receive(:new).with(anything, anything, hash_including(tags: ['bar', 'foo']), anything, anything).and_return(publish_pacts)
84
- Rake::Task['pact:publish:git_branch'].execute
85
- end
86
- end
87
-
88
- context "when auto_detect_version_properties is explicitly set to true" do
89
- before :all do
90
- PactBroker::Client::PublicationTask.new(:git_branch_auto_detect_true) do | task |
91
- task.auto_detect_version_properties = true
92
- end
93
- end
94
-
95
- # Don't usually put 3 expects into the one it block, but if I separate them,
96
- # only the first it block passes for some reason that I can't work out.
97
- it "gets the commit, build_url and branch" do
98
- expect(PactBroker::Client::Git).to receive(:commit).with(raise_error: true)
99
- expect(PactBroker::Client::Git).to receive(:build_url)
100
- expect(PactBroker::Client::Git).to receive(:branch).with(raise_error: true)
101
- Rake::Task['pact:publish:git_branch_auto_detect_true'].execute
102
- end
103
-
104
- it "invokes PublishPacts with the branch name and build URL" do
105
- expect(PactBroker::Client::PublishPacts).to receive(:new).with(anything, anything, hash_including(number: "6.6.6", branch: "foo", build_url: "build_url"), anything, anything).and_return(publish_pacts)
106
- Rake::Task['pact:publish:git_branch_auto_detect_true'].execute
107
- end
108
- end
109
-
110
- context "when auto_detect_version_properties is explicitly set to true and the auto detectable attributes are specified" do
111
- before :all do
112
- PactBroker::Client::PublicationTask.new(:auto_detect_true_with_attributes_specified) do | task |
113
- task.auto_detect_version_properties = true
114
- task.consumer_version = '1.2.3'
115
- task.branch = "feat/foo"
116
- task.consumer_version = "3"
117
- task.build_url = "some_build"
118
- end
119
- end
120
-
121
- it "does not get the commit, branch or build URL from Git" do
122
- expect(PactBroker::Client::Git).to_not receive(:commit)
123
- expect(PactBroker::Client::Git).to_not receive(:build_url)
124
- expect(PactBroker::Client::Git).to_not receive(:branch)
125
- Rake::Task['pact:publish:auto_detect_true_with_attributes_specified'].execute
126
- end
127
-
128
- it "invokes PublishPacts with the specified attributes" do
129
- expect(PactBroker::Client::PublishPacts).to receive(:new).with(anything, anything, hash_including(number: "3", branch: "feat/foo", build_url: "some_build"), anything, anything).and_return(publish_pacts)
130
- Rake::Task['pact:publish:auto_detect_true_with_attributes_specified'].execute
131
- end
132
- end
133
-
134
- context "when auto_detect_version_properties is explicitly set to false" do
135
- before :all do
136
- PactBroker::Client::PublicationTask.new(:auto_detect_false) do | task |
137
- task.auto_detect_version_properties = false
138
- task.consumer_version = '1.2.3'
139
- task.branch = "feat/foo"
140
- task.consumer_version = "3"
141
- task.build_url = "some_build"
142
- end
143
- end
144
-
145
- it "does not get the commit, branch or build URL from Git" do
146
- expect(PactBroker::Client::Git).to_not receive(:commit)
147
- expect(PactBroker::Client::Git).to_not receive(:build_url)
148
- expect(PactBroker::Client::Git).to_not receive(:branch)
149
- Rake::Task['pact:publish:auto_detect_false'].execute
150
- end
151
-
152
- it "invokes PublishPacts with the specified attributes" do
153
- expect(PactBroker::Client::PublishPacts).to receive(:new).with(anything, anything, hash_including(number: "3", branch: "feat/foo", build_url: "some_build"), anything, anything).and_return(publish_pacts)
154
- Rake::Task['pact:publish:auto_detect_false'].execute
155
- end
156
- end
157
-
158
- context "when auto_detect_version_properties is left as its default and the branch is not specified" do
159
- before :all do
160
- PactBroker::Client::PublicationTask.new(:auto_detect_default) do | task |
161
- task.consumer_version = '1.2.3'
162
- end
163
- end
164
-
165
- it "gets the git branch name but won't raise an error if it can't be determined" do
166
- expect(PactBroker::Client::Git).to receive(:branch).with(raise_error: false)
167
- Rake::Task['pact:publish:auto_detect_default'].execute
168
- end
169
-
170
- it "invokes PublishPacts with the branch name if found" do
171
- expect(PactBroker::Client::PublishPacts).to receive(:new).with(anything, anything, hash_including(branch: "foo"),anything, anything).and_return(publish_pacts)
172
- Rake::Task['pact:publish:auto_detect_default'].execute
173
- end
174
- end
175
-
176
- describe "custom task" do
177
- before :all do
178
- @pact_broker_base_url = "http://some-host"
179
- @pattern = "pact/*.json"
180
- @pact_broker_basic_auth = { username: 'user', password: 'pass' }
181
- @pact_broker_token = 'token'
182
- @tag = "dev"
183
- PactBroker::Client::PublicationTask.new(:custom) do | task |
184
- task.consumer_version = '1.2.3'
185
- task.tag = @tag
186
- task.pact_broker_base_url = @pact_broker_base_url
187
- task.pattern = @pattern
188
- task.pact_broker_basic_auth = @pact_broker_basic_auth
189
- task.pact_broker_token = @pact_broker_token
190
- end
191
- end
192
-
193
- let(:pattern) { @pattern }
194
-
195
- it "invokes PublishPacts with the customised values" do
196
- expect(PactBroker::Client::PublishPacts).to receive(:new).with(
197
- @pact_broker_base_url,
198
- pact_file_list,
199
- { number: "1.2.3", tags: [@tag], branch: "foo" },
200
- {},
201
- { basic_auth: @pact_broker_basic_auth, token: @pact_broker_token }
202
- )
203
- expect(publish_pacts).to receive(:call).and_return(result)
204
- Rake::Task['pact:publish:custom'].execute
205
- end
206
- end
207
-
208
- describe "with no consumer version" do
209
- before :all do
210
- PactBroker::Client::PublicationTask.new(:no_consumer_version) do
211
- end
212
- end
213
-
214
- it "raises an error" do
215
- expect { Rake::Task['pact:publish:no_consumer_version'].execute }.to raise_error PactBroker::Client::Error, /consumer version/
216
- end
217
- end
218
-
219
- describe "timing of block execution" do
220
- before :all do
221
- PactBroker::Client::PublicationTask.new(:exception) do | task |
222
- raise 'A contrived exception'
223
- end
224
- end
225
-
226
- it "does not execute the block passed to the publication task until the task is called" do
227
- expect{ Rake::Task['pact:publish:exception'].execute }.to raise_error 'A contrived exception'
228
- end
229
- end
230
- end
231
- end
@@ -1,174 +0,0 @@
1
- require "pact_broker/client/versions/create"
2
-
3
- module PactBroker
4
- module Client
5
- describe Versions::Create do
6
- describe "#call" do
7
- let(:index_body) do
8
- {
9
- "_links" => {
10
- "pb:pacticipant-branch-version" => {
11
- "href" => "http://broker/pacticipants/{pacticipant}/branches/{branch}/versions/{version}"
12
- },
13
- "pb:pacticipant-version-tag" => {
14
- "href" => "http://broker/pacticipants/{pacticipant}/versions/{version}/tags/{tag}"
15
- },
16
- "pb:pacticipant-version" => {
17
- "href" => "http://broker/pacticipants/{pacticipant}/versions/{version}"
18
- }
19
- }
20
- }
21
- end
22
-
23
- let!(:index_request) do
24
- stub_request(:get, "http://broker").to_return(status: 200, body: index_body.to_json, headers: { "Content-Type" => "application/hal+json" } )
25
- end
26
-
27
- let!(:branch_request) do
28
- stub_request(:put, "http://broker/pacticipants/Foo/branches/main/versions/1").to_return(status: 200, body: "{}", headers: { "Content-Type" => "application/hal+json" } )
29
- end
30
-
31
- let!(:tag_request) do
32
- stub_request(:put, "http://broker/pacticipants/Foo/versions/1/tags/dev").to_return(status: 200, body: "{}", headers: { "Content-Type" => "application/hal+json" } )
33
- end
34
-
35
- let!(:create_version_request) do
36
- stub_request(:put, "http://broker/pacticipants/Foo/versions/1").to_return(status: 200, body: { version: "created" }.to_json, headers: { "Content-Type" => "application/hal+json" } )
37
- end
38
-
39
- let!(:get_version_request) do
40
- stub_request(:get, "http://broker/pacticipants/Foo/versions/1").to_return(status: 200, body: { version: "got" }.to_json, headers: { "Content-Type" => "application/hal+json" } )
41
- end
42
-
43
- let(:params) do
44
- {
45
- pacticipant_name: "Foo",
46
- version_number: "1",
47
- branch_name: branch_name,
48
- tags: tags
49
- }
50
- end
51
-
52
- let(:branch_name) { "main" }
53
- let(:tags) { ["dev"] }
54
-
55
- let(:options) do
56
- {
57
- verbose: "verbose",
58
- output: output
59
- }
60
- end
61
-
62
- let(:output) { "text" }
63
-
64
- let(:pact_broker_client_options) do
65
- {
66
- token: "token",
67
- pact_broker_base_url: "http://broker"
68
- }
69
- end
70
-
71
- subject { PactBroker::Client::Versions::Create.call(params, options, pact_broker_client_options)}
72
-
73
- context "with a branch and tags" do
74
- it "creates a branch version" do
75
- subject
76
- expect(branch_request).to have_been_made
77
- end
78
-
79
- it "creates the tag" do
80
- subject
81
- expect(tag_request).to have_been_made
82
- end
83
-
84
- it "returns a message" do
85
- expect(subject.message).to include "Created/updated pacticipant version 1 with branch main and tag(s) dev in the Pact Broker"
86
- expect(subject.success).to be true
87
- end
88
-
89
- context "without output json" do
90
- let(:output) { "json" }
91
-
92
- it "returns a json message" do
93
- expect(subject.message).to eq({ version: "got" }.to_json)
94
- end
95
- end
96
- end
97
-
98
- context "with only tags" do
99
- let(:branch_name) { nil }
100
-
101
- it "returns a message" do
102
- expect(subject.message).to include "Created/updated pacticipant version 1 with tag(s) dev in the Pact Broker"
103
- expect(subject.success).to be true
104
- end
105
-
106
- context "without output json" do
107
- let(:output) { "json" }
108
-
109
- it "returns a json message" do
110
- expect(subject.message).to eq({ version: "got" }.to_json)
111
- end
112
- end
113
- end
114
-
115
- context "with only a branch" do
116
- let(:tags) { nil }
117
-
118
- it "returns a message" do
119
- expect(subject.message).to include "Created/updated pacticipant version 1 with branch main in the Pact Broker"
120
- expect(subject.success).to be true
121
- end
122
-
123
- context "without output json" do
124
- let(:output) { "json" }
125
-
126
- it "returns a json message" do
127
- expect(subject.message).to eq({ version: "got" }.to_json)
128
- end
129
- end
130
- end
131
-
132
- context "with no branch or tags" do
133
- let(:tags) { nil }
134
- let(:branch_name) { nil }
135
-
136
- it "creates a version" do
137
- subject
138
- expect(create_version_request).to have_been_made
139
- end
140
-
141
- it "returns a message" do
142
- expect(subject.message).to include "Created/updated pacticipant version 1 in the Pact Broker"
143
- expect(subject.success).to be true
144
- end
145
-
146
- context "without output json" do
147
- let(:output) { "json" }
148
-
149
- it "returns a json message" do
150
- expect(subject.message).to eq({ version: "created" }.to_json)
151
- end
152
- end
153
- end
154
-
155
- context "when the Pact Broker does not support branch versions" do
156
- before do
157
- index_body["_links"].delete("pb:pacticipant-branch-version")
158
- end
159
-
160
- let(:index_body) do
161
- {
162
- "_links" => {}
163
- }
164
- end
165
-
166
- it "returns an error" do
167
- expect(subject.message).to include "does not support branch versions"
168
- expect(subject.success).to be false
169
- end
170
- end
171
- end
172
- end
173
- end
174
- end
@@ -1,64 +0,0 @@
1
- require 'pact_broker/client/versions/describe'
2
-
3
- module PactBroker
4
- module Client
5
- class Versions
6
- describe Describe do
7
- describe ".call" do
8
- let(:versions_client) do
9
- instance_double('PactBroker::Client::Versions', latest: version_hash)
10
- end
11
-
12
- let(:pact_broker_base_url) { 'http://broker' }
13
- let(:pact_broker_client_options) { {} }
14
- let(:pact_broker_client) { instance_double('PactBroker::Client::PactBrokerClient')}
15
- let(:version_hash) do
16
- {
17
- foo: 'bar'
18
- }
19
- end
20
-
21
- let(:params) do
22
- {
23
- pacticipant: 'foo',
24
- latest: true,
25
- tag: 'bar'
26
- }
27
- end
28
-
29
- let(:options) do
30
- {
31
- output: 'someformat'
32
- }
33
- end
34
-
35
- before do
36
- allow(PactBroker::Client::PactBrokerClient).to receive(:new).and_return(pact_broker_client)
37
- allow(pact_broker_client).to receive_message_chain(:pacticipants, :versions).and_return(versions_client)
38
- allow(Formatter).to receive(:call).and_return('formatted_output')
39
- end
40
-
41
- subject { Describe.call(params, options, pact_broker_base_url, pact_broker_client_options) }
42
-
43
- it "invokes the versions client" do
44
- expect(versions_client).to receive(:latest).with(params)
45
- subject
46
- end
47
-
48
- it "formats the output" do
49
- expect(Formatter).to receive(:call).with(version_hash, 'someformat')
50
- subject
51
- end
52
-
53
- it "returns a successful result" do
54
- expect(subject.success).to be true
55
- end
56
-
57
- it "returns a result with the formatted output as the message" do
58
- expect(subject.message).to eq 'formatted_output'
59
- end
60
- end
61
- end
62
- end
63
- end
64
- end
@@ -1,34 +0,0 @@
1
- require 'pact_broker/client/versions'
2
- module PactBroker
3
- module Client
4
- describe Versions do
5
- let(:client_options) do
6
- { some_option: 'option value'}
7
- end
8
- let(:base_url) { 'http://blah' }
9
- let(:pacticipant_name) { 'Foo' }
10
- let(:version_number) { '1.2.3' }
11
-
12
- subject { Versions.new(base_url: base_url, client_options: client_options) }
13
-
14
- describe 'pacts' do
15
- it 'initializes versions with base url and client options' do
16
- expect(PactBroker::Client::Pacts).to receive(:new).with(base_url: base_url, client_options: client_options)
17
- subject.pacts
18
- end
19
- end
20
-
21
- describe 'tag' do
22
- context "when the tag has a / in it" do
23
- let(:tag) { 'feat/foo' }
24
- let!(:request) { stub_request(:put, "http://blah/pacticipants/Foo/versions/1.2.3/tags/feat%2Ffoo").to_return(status: 200) }
25
-
26
- it "URL encodes the /" do
27
- subject.tag(pacticipant: pacticipant_name, version: version_number, tag: tag)
28
- expect(request).to have_been_made
29
- end
30
- end
31
- end
32
- end
33
- end
34
- end
@@ -1,99 +0,0 @@
1
- require 'pact_broker/client/webhooks/create'
2
-
3
- module PactBroker
4
- module Client
5
- module Webhooks
6
- describe Create do
7
- describe ".call" do
8
- let(:index_body) do
9
- {
10
- "_links" => {
11
- "pb:webhooks" => {
12
- "href" => "http://broker/webhooks"
13
- }
14
- }
15
- }.to_json
16
- end
17
- let!(:index_request) do
18
- stub_request(:get, "http://broker").with(headers: { "Authorization" => /.*/}).to_return(status: 200, body: index_body, headers: { "Content-Type" => "application/hal+json" } )
19
- end
20
-
21
- let(:params) do
22
- {
23
- http_method: "POST",
24
- url: "https://webhook",
25
- headers: { "Foo" => "bar", "Bar" => "foo"},
26
- username: "username",
27
- password: "password",
28
- body: "body",
29
- events: ["contract_content_changed"]
30
- }.tap { |it| Pact::Fixture.add_fixture(:create_webhook_params, it) }
31
- end
32
-
33
- let(:pact_broker_client_options) do
34
- {
35
- token: 'token',
36
- verbose: 'verbose'
37
- }
38
- end
39
-
40
- subject { Create.call(params, "http://broker", pact_broker_client_options) }
41
-
42
- context "when a 405 is returned from the webhook creation request" do
43
- let!(:webhook_request) do
44
- stub_request(:post, "http://broker/webhooks").to_return(status: 405)
45
- end
46
-
47
- it "returns a result with success=false and a message" do
48
- expect(subject.success).to be false
49
- expect(subject.message).to eq Create::WEBHOOKS_WITH_OPTIONAL_PACTICICPANTS_NOT_SUPPORTED
50
- end
51
- end
52
-
53
- context "when a UUID is specified and index does not contain a pb:webhook relation" do
54
- subject { Create.call(params.merge(uuid: 'some-uuid'), "http://broker", pact_broker_client_options) }
55
-
56
- it "returns a result with success=false and a message" do
57
- expect(subject.success).to be false
58
- expect(subject.message).to eq Create::CREATING_WEBHOOK_WITH_UUID_NOT_SUPPORTED
59
- end
60
- end
61
-
62
- context "when a 400 is returned from the webhook creation request" do
63
- let!(:webhook_request) do
64
- stub_request(:post, "http://broker/webhooks").to_return(status: 400, body: '{"some":"error"}', headers: { "Content-Type" => "application/hal+json" })
65
- end
66
-
67
- it "returns a result with success=false" do
68
- expect(subject.success).to be false
69
- expect(subject.message).to match /400/
70
- expect(subject.message).to match /"some":"error"/
71
- end
72
- end
73
-
74
- context "when there is an empty description returned" do
75
- let!(:webhook_request) do
76
- stub_request(:post, "http://broker/webhooks").to_return(status: 200, body: response_body.to_json, headers: { "Content-Type" => "application/hal+json" })
77
- end
78
-
79
- let(:response_body) do
80
- {
81
- description: "",
82
- _links: {
83
- self: {
84
- href: "href",
85
- title: "the title"
86
- }
87
- }
88
- }
89
- end
90
-
91
- it "uses the self title in the message instead" do
92
- expect(subject.message).to include "the title"
93
- end
94
- end
95
- end
96
- end
97
- end
98
- end
99
- end