pact_broker-client 1.59.0 → 1.61.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,174 @@
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
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pact_broker-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.59.0
4
+ version: 1.61.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Beth Skurrie
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-03-15 00:00:00.000000000 Z
11
+ date: 2022-05-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -176,14 +176,14 @@ dependencies:
176
176
  requirements:
177
177
  - - '='
178
178
  - !ruby/object:Gem::Version
179
- version: 0.0.24
179
+ version: 0.0.18
180
180
  type: :development
181
181
  prerelease: false
182
182
  version_requirements: !ruby/object:Gem::Requirement
183
183
  requirements:
184
184
  - - '='
185
185
  - !ruby/object:Gem::Version
186
- version: 0.0.24
186
+ version: 0.0.18
187
187
  - !ruby/object:Gem::Dependency
188
188
  name: rspec-its
189
189
  requirement: !ruby/object:Gem::Requirement
@@ -245,8 +245,10 @@ files:
245
245
  - lib/pact_broker/client/cli/deployment_commands.rb
246
246
  - lib/pact_broker/client/cli/environment_commands.rb
247
247
  - lib/pact_broker/client/cli/matrix_commands.rb
248
+ - lib/pact_broker/client/cli/pact_commands.rb
248
249
  - lib/pact_broker/client/cli/pacticipant_commands.rb
249
250
  - lib/pact_broker/client/cli/record_deployment_long_desc.txt
251
+ - lib/pact_broker/client/cli/version_commands.rb
250
252
  - lib/pact_broker/client/cli/version_selector_options_parser.rb
251
253
  - lib/pact_broker/client/cli/webhook_commands.rb
252
254
  - lib/pact_broker/client/colorize_notices.rb
@@ -304,6 +306,7 @@ files:
304
306
  - lib/pact_broker/client/verification_required.rb
305
307
  - lib/pact_broker/client/version.rb
306
308
  - lib/pact_broker/client/versions.rb
309
+ - lib/pact_broker/client/versions/create.rb
307
310
  - lib/pact_broker/client/versions/describe.rb
308
311
  - lib/pact_broker/client/versions/formatter.rb
309
312
  - lib/pact_broker/client/versions/json_formatter.rb
@@ -365,6 +368,7 @@ files:
365
368
  - spec/lib/pact_broker/client/publish_pacts_the_old_way_spec.rb
366
369
  - spec/lib/pact_broker/client/retry_spec.rb
367
370
  - spec/lib/pact_broker/client/tasks/publication_task_spec.rb
371
+ - spec/lib/pact_broker/client/versions/create_spec.rb
368
372
  - spec/lib/pact_broker/client/versions/describe_spec.rb
369
373
  - spec/lib/pact_broker/client/versions_spec.rb
370
374
  - spec/lib/pact_broker/client/webhooks/create_spec.rb
@@ -425,7 +429,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
425
429
  - !ruby/object:Gem::Version
426
430
  version: '0'
427
431
  requirements: []
428
- rubygems_version: 3.3.9
432
+ rubygems_version: 3.3.13
429
433
  signing_key:
430
434
  specification_version: 4
431
435
  summary: See description
@@ -472,6 +476,7 @@ test_files:
472
476
  - spec/lib/pact_broker/client/publish_pacts_the_old_way_spec.rb
473
477
  - spec/lib/pact_broker/client/retry_spec.rb
474
478
  - spec/lib/pact_broker/client/tasks/publication_task_spec.rb
479
+ - spec/lib/pact_broker/client/versions/create_spec.rb
475
480
  - spec/lib/pact_broker/client/versions/describe_spec.rb
476
481
  - spec/lib/pact_broker/client/versions_spec.rb
477
482
  - spec/lib/pact_broker/client/webhooks/create_spec.rb