pact_broker-client 1.36.0 → 1.37.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1550,6 +1550,187 @@
1550
1550
  }
1551
1551
  }
1552
1552
  },
1553
+ {
1554
+ "description": "a request for the index resource",
1555
+ "providerState": "the pb:pacticipant-version and pb:environments relations exist in the index resource",
1556
+ "request": {
1557
+ "method": "GET",
1558
+ "path": "/",
1559
+ "headers": {
1560
+ "Accept": "application/hal+json"
1561
+ }
1562
+ },
1563
+ "response": {
1564
+ "status": 200,
1565
+ "headers": {
1566
+ "Content-Type": "application/hal+json;charset=utf-8"
1567
+ },
1568
+ "body": {
1569
+ "_links": {
1570
+ "pb:pacticipant-version": {
1571
+ "href": "http://localhost:1234/HAL-REL-PLACEHOLDER-PB-PACTICIPANT-VERSION-{pacticipant}-{version}"
1572
+ },
1573
+ "pb:environments": {
1574
+ "href": "http://localhost:1234/HAL-REL-PLACEHOLDER-PB-ENVIRONMENTS"
1575
+ }
1576
+ }
1577
+ },
1578
+ "matchingRules": {
1579
+ "$.body._links.pb:pacticipant-version.href": {
1580
+ "match": "regex",
1581
+ "regex": "http:\\/\\/.*{pacticipant}.*{version}"
1582
+ },
1583
+ "$.body._links.pb:environments.href": {
1584
+ "match": "regex",
1585
+ "regex": "http:\\/\\/.*"
1586
+ }
1587
+ }
1588
+ }
1589
+ },
1590
+ {
1591
+ "description": "a request for a pacticipant version",
1592
+ "providerState": "version 5556b8149bf8bac76bc30f50a8a2dd4c22c85f30 of pacticipant Foo exists with a test environment available for deployment",
1593
+ "request": {
1594
+ "method": "GET",
1595
+ "path": "/HAL-REL-PLACEHOLDER-PB-PACTICIPANT-VERSION-Foo-5556b8149bf8bac76bc30f50a8a2dd4c22c85f30",
1596
+ "headers": {
1597
+ "Accept": "application/hal+json"
1598
+ }
1599
+ },
1600
+ "response": {
1601
+ "status": 200,
1602
+ "headers": {
1603
+ "Content-Type": "application/hal+json;charset=utf-8"
1604
+ },
1605
+ "body": {
1606
+ "_links": {
1607
+ "pb:record-deployment": [
1608
+ {
1609
+ "name": "test",
1610
+ "href": "http://localhost:1234/HAL-REL-PLACEHOLDER-PB-RECORD-DEPLOYMENT-FOO-5556B8149BF8BAC76BC30F50A8A2DD4C22C85F30-TEST"
1611
+ }
1612
+ ]
1613
+ }
1614
+ },
1615
+ "matchingRules": {
1616
+ "$.body._links.pb:record-deployment[0].href": {
1617
+ "match": "regex",
1618
+ "regex": "http:\\/\\/.*"
1619
+ }
1620
+ }
1621
+ }
1622
+ },
1623
+ {
1624
+ "description": "a request to record a deployment",
1625
+ "providerState": "version 5556b8149bf8bac76bc30f50a8a2dd4c22c85f30 of pacticipant Foo exists with a test environment available for deployment",
1626
+ "request": {
1627
+ "method": "POST",
1628
+ "path": "/HAL-REL-PLACEHOLDER-PB-RECORD-DEPLOYMENT-FOO-5556B8149BF8BAC76BC30F50A8A2DD4C22C85F30-TEST",
1629
+ "headers": {
1630
+ "Content-Type": "application/json",
1631
+ "Accept": "application/hal+json"
1632
+ },
1633
+ "body": {
1634
+ "replacedPreviousDeployedVersion": true
1635
+ }
1636
+ },
1637
+ "response": {
1638
+ "status": 201,
1639
+ "headers": {
1640
+ "Content-Type": "application/hal+json;charset=utf-8"
1641
+ },
1642
+ "body": {
1643
+ "replacedPreviousDeployedVersion": true
1644
+ }
1645
+ }
1646
+ },
1647
+ {
1648
+ "description": "a request for a pacticipant version",
1649
+ "providerState": "version 5556b8149bf8bac76bc30f50a8a2dd4c22c85f30 of pacticipant Foo does not exist",
1650
+ "request": {
1651
+ "method": "GET",
1652
+ "path": "/HAL-REL-PLACEHOLDER-PB-PACTICIPANT-VERSION-Foo-5556b8149bf8bac76bc30f50a8a2dd4c22c85f30",
1653
+ "headers": {
1654
+ "Accept": "application/hal+json"
1655
+ }
1656
+ },
1657
+ "response": {
1658
+ "status": 404,
1659
+ "headers": {
1660
+ }
1661
+ }
1662
+ },
1663
+ {
1664
+ "description": "a request for a pacticipant version",
1665
+ "providerState": "version 5556b8149bf8bac76bc30f50a8a2dd4c22c85f30 of pacticipant Foo exists with 2 environments that aren't test available for deployment",
1666
+ "request": {
1667
+ "method": "GET",
1668
+ "path": "/HAL-REL-PLACEHOLDER-PB-PACTICIPANT-VERSION-Foo-5556b8149bf8bac76bc30f50a8a2dd4c22c85f30",
1669
+ "headers": {
1670
+ "Accept": "application/hal+json"
1671
+ }
1672
+ },
1673
+ "response": {
1674
+ "status": 200,
1675
+ "headers": {
1676
+ "Content-Type": "application/hal+json;charset=utf-8"
1677
+ },
1678
+ "body": {
1679
+ "_links": {
1680
+ "pb:record-deployment": [
1681
+ {
1682
+ "name": "prod",
1683
+ "href": "href"
1684
+ },
1685
+ {
1686
+ "name": "dev",
1687
+ "href": "href"
1688
+ }
1689
+ ]
1690
+ }
1691
+ },
1692
+ "matchingRules": {
1693
+ "$.body._links.pb:record-deployment[0]": {
1694
+ "match": "type"
1695
+ },
1696
+ "$.body._links.pb:record-deployment[1]": {
1697
+ "match": "type"
1698
+ }
1699
+ }
1700
+ }
1701
+ },
1702
+ {
1703
+ "description": "a request for the environments",
1704
+ "providerState": "an environment with name test exists",
1705
+ "request": {
1706
+ "method": "GET",
1707
+ "path": "/HAL-REL-PLACEHOLDER-PB-ENVIRONMENTS",
1708
+ "headers": {
1709
+ "Accept": "application/hal+json"
1710
+ }
1711
+ },
1712
+ "response": {
1713
+ "status": 200,
1714
+ "headers": {
1715
+ "Content-Type": "application/hal+json;charset=utf-8"
1716
+ },
1717
+ "body": {
1718
+ "_links": {
1719
+ "pb:environments": [
1720
+ {
1721
+ "name": "test",
1722
+ "href": "href"
1723
+ }
1724
+ ]
1725
+ }
1726
+ },
1727
+ "matchingRules": {
1728
+ "$.body._links.pb:environments[0].href": {
1729
+ "match": "type"
1730
+ }
1731
+ }
1732
+ }
1733
+ },
1553
1734
  {
1554
1735
  "description": "a request to create a webhook with a JSON body for a consumer and provider",
1555
1736
  "providerState": "the 'Pricing Service' and 'Condor' already exist in the pact-broker",
@@ -0,0 +1,219 @@
1
+ require 'service_providers/pact_helper'
2
+ require 'pact_broker/client/versions/record_deployment'
3
+
4
+ RSpec.describe "recording a deployment", pact: true do
5
+
6
+ include_context "pact broker"
7
+ include PactBrokerPactHelperMethods
8
+
9
+ let(:pacticipant_name) { "Foo" }
10
+ let(:version_number) { "5556b8149bf8bac76bc30f50a8a2dd4c22c85f30" }
11
+ let(:environment_name) { "test" }
12
+ let(:output) { "text" }
13
+ let(:replaced_previous_deployed_version) { true }
14
+ let(:params) do
15
+ {
16
+ pacticipant_name: pacticipant_name,
17
+ version_number: version_number,
18
+ environment_name: environment_name,
19
+ replaced_previous_deployed_version: replaced_previous_deployed_version,
20
+ output: output
21
+ }
22
+ end
23
+ let(:pact_broker_client_options) { {} }
24
+
25
+ subject { PactBroker::Client::Versions::RecordDeployment.call(params, broker_base_url, pact_broker_client_options) }
26
+
27
+ def mock_index
28
+ pact_broker
29
+ .given("the pb:pacticipant-version and pb:environments relations exist in the index resource")
30
+ .upon_receiving("a request for the index resource")
31
+ .with(
32
+ method: "GET",
33
+ path: '/',
34
+ headers: get_request_headers).
35
+ will_respond_with(
36
+ status: 200,
37
+ headers: pact_broker_response_headers,
38
+ body: {
39
+ _links: {
40
+ :'pb:pacticipant-version' => {
41
+ href: placeholder_url_term("pb:pacticipant-version", ["pacticipant", "version"])
42
+ },
43
+ :'pb:environments' => {
44
+ href: placeholder_url_term("pb:environments")
45
+ }
46
+ }
47
+ }
48
+ )
49
+ end
50
+
51
+ def mock_pacticipant_version_with_test_environment_available_for_deployment
52
+ pact_broker
53
+ .given("version 5556b8149bf8bac76bc30f50a8a2dd4c22c85f30 of pacticipant Foo exists with a test environment available for deployment")
54
+ .upon_receiving("a request for a pacticipant version")
55
+ .with(
56
+ method: "GET",
57
+ path: "/HAL-REL-PLACEHOLDER-PB-PACTICIPANT-VERSION-Foo-5556b8149bf8bac76bc30f50a8a2dd4c22c85f30",
58
+ headers: get_request_headers
59
+ )
60
+ .will_respond_with(
61
+ status: 200,
62
+ headers: pact_broker_response_headers,
63
+ body: {
64
+ _links: {
65
+ "pb:record-deployment" => [
66
+ {
67
+ name: "test",
68
+ href: placeholder_url_term("pb:record-deployment-#{pacticipant_name}-#{version_number}-#{environment_name}")
69
+ }
70
+ ]
71
+ }
72
+ }
73
+ )
74
+ end
75
+
76
+ def mock_pacticipant_version_without_test_environment_available_for_deployment
77
+ pact_broker
78
+ .given("version 5556b8149bf8bac76bc30f50a8a2dd4c22c85f30 of pacticipant Foo exists with 2 environments that aren't test available for deployment")
79
+ .upon_receiving("a request for a pacticipant version")
80
+ .with(
81
+ method: "GET",
82
+ path: "/HAL-REL-PLACEHOLDER-PB-PACTICIPANT-VERSION-Foo-5556b8149bf8bac76bc30f50a8a2dd4c22c85f30",
83
+ headers: get_request_headers
84
+ )
85
+ .will_respond_with(
86
+ status: 200,
87
+ headers: pact_broker_response_headers,
88
+ body: {
89
+ _links: {
90
+ "pb:record-deployment" => [
91
+ Pact.like(
92
+ name: "prod",
93
+ href: "href"
94
+ ),
95
+ Pact.like(
96
+ name: "dev",
97
+ href: "href"
98
+ ),
99
+ ]
100
+ }
101
+ }
102
+ )
103
+ end
104
+
105
+ def mock_pacticipant_version_not_found
106
+ pact_broker
107
+ .given("version 5556b8149bf8bac76bc30f50a8a2dd4c22c85f30 of pacticipant Foo does not exist")
108
+ .upon_receiving("a request for a pacticipant version")
109
+ .with(
110
+ method: "GET",
111
+ path: "/HAL-REL-PLACEHOLDER-PB-PACTICIPANT-VERSION-Foo-5556b8149bf8bac76bc30f50a8a2dd4c22c85f30",
112
+ headers: get_request_headers
113
+ )
114
+ .will_respond_with(status: 404)
115
+ end
116
+
117
+ def mock_environments
118
+ pact_broker
119
+ .given("an environment with name test exists")
120
+ .upon_receiving("a request for the environments")
121
+ .with(
122
+ method: "GET",
123
+ path: "/HAL-REL-PLACEHOLDER-PB-ENVIRONMENTS",
124
+ headers: get_request_headers
125
+ )
126
+ .will_respond_with(
127
+ status: 200,
128
+ headers: pact_broker_response_headers,
129
+ body: {
130
+ _links: {
131
+ "pb:environments" => [
132
+ {
133
+ name: "test",
134
+ href: Pact.like("href")
135
+ }
136
+ ]
137
+ }
138
+ }
139
+ )
140
+ end
141
+
142
+ def mock_record_deployment
143
+ pact_broker
144
+ .given("version 5556b8149bf8bac76bc30f50a8a2dd4c22c85f30 of pacticipant Foo exists with a test environment available for deployment")
145
+ .upon_receiving("a request to record a deployment")
146
+ .with(
147
+ method: "POST",
148
+ path: "/HAL-REL-PLACEHOLDER-PB-RECORD-DEPLOYMENT-FOO-5556B8149BF8BAC76BC30F50A8A2DD4C22C85F30-TEST",
149
+ headers: post_request_headers,
150
+ body: {
151
+ replacedPreviousDeployedVersion: replaced_previous_deployed_version
152
+ }
153
+ )
154
+ .will_respond_with(
155
+ status: 201,
156
+ headers: pact_broker_response_headers,
157
+ body: {
158
+ replacedPreviousDeployedVersion: replaced_previous_deployed_version
159
+ }
160
+ )
161
+ end
162
+
163
+ context "when the deployment is recorded successfully" do
164
+ before do
165
+ mock_index
166
+ mock_pacticipant_version_with_test_environment_available_for_deployment
167
+ mock_record_deployment
168
+ end
169
+
170
+ it "returns a success message" do
171
+ expect(subject.success).to be true
172
+ expect(subject.message).to eq "Recorded deployment of Foo version 5556b8149bf8bac76bc30f50a8a2dd4c22c85f30 to test in the Pact Broker. Marked previous deployed version as undeployed."
173
+ end
174
+
175
+ context "when the output is json" do
176
+ let(:output) { "json" }
177
+
178
+ it "returns the JSON payload" do
179
+ expect(JSON.parse(subject.message)).to eq "replacedPreviousDeployedVersion" => replaced_previous_deployed_version
180
+ end
181
+ end
182
+ end
183
+
184
+ context "when the specified version does not exist" do
185
+ before do
186
+ mock_index
187
+ mock_pacticipant_version_not_found
188
+ end
189
+
190
+ it "returns an error response" do
191
+ expect(subject.success).to be false
192
+ expect(subject.message).to include "Foo version 5556b8149bf8bac76bc30f50a8a2dd4c22c85f30 not found"
193
+ end
194
+ end
195
+
196
+ context "when the specified environment is not available for recording a deployment" do
197
+ before do
198
+ mock_index
199
+ mock_pacticipant_version_without_test_environment_available_for_deployment
200
+ mock_environments
201
+ end
202
+
203
+ context "when the specified environment does not exist" do
204
+ let(:environment_name) { "foo" }
205
+
206
+ it "returns an error response" do
207
+ expect(subject.success).to be false
208
+ expect(subject.message).to eq "No environment found with name 'foo'. Available options: test"
209
+ end
210
+ end
211
+
212
+ context "when the specified environment does exist" do
213
+ it "returns an error response" do
214
+ expect(subject.success).to be false
215
+ expect(subject.message).to eq "Environment 'test' is not an available option for recording a deployment of Foo. Available options: prod, dev"
216
+ end
217
+ end
218
+ end
219
+ 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.36.0
4
+ version: 1.37.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Beth Skurrie
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-02-26 00:00:00.000000000 Z
11
+ date: 2021-02-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -204,6 +204,7 @@ files:
204
204
  - example/scripts/publish-verification.sh
205
205
  - example/scripts/verification.json
206
206
  - lib/pact_broker/client.rb
207
+ - lib/pact_broker/client/backports.rb
207
208
  - lib/pact_broker/client/base_client.rb
208
209
  - lib/pact_broker/client/can_i_deploy.rb
209
210
  - lib/pact_broker/client/cli/broker.rb
@@ -222,7 +223,9 @@ files:
222
223
  - lib/pact_broker/client/hal/entry_point.rb
223
224
  - lib/pact_broker/client/hal/http_client.rb
224
225
  - lib/pact_broker/client/hal/link.rb
226
+ - lib/pact_broker/client/hal/links.rb
225
227
  - lib/pact_broker/client/hal_client_methods.rb
228
+ - lib/pact_broker/client/hash_refinements.rb
226
229
  - lib/pact_broker/client/matrix.rb
227
230
  - lib/pact_broker/client/matrix/formatter.rb
228
231
  - lib/pact_broker/client/matrix/json_formatter.rb
@@ -245,6 +248,7 @@ files:
245
248
  - lib/pact_broker/client/versions/describe.rb
246
249
  - lib/pact_broker/client/versions/formatter.rb
247
250
  - lib/pact_broker/client/versions/json_formatter.rb
251
+ - lib/pact_broker/client/versions/record_deployment.rb
248
252
  - lib/pact_broker/client/versions/text_formatter.rb
249
253
  - lib/pact_broker/client/webhooks/create.rb
250
254
  - lib/pact_broker/client/webhooks/test.rb
@@ -282,6 +286,7 @@ files:
282
286
  - spec/lib/pact_broker/client/retry_spec.rb
283
287
  - spec/lib/pact_broker/client/tasks/publication_task_spec.rb
284
288
  - spec/lib/pact_broker/client/versions/describe_spec.rb
289
+ - spec/lib/pact_broker/client/versions/record_deployment_spec.rb
285
290
  - spec/lib/pact_broker/client/versions_spec.rb
286
291
  - spec/lib/pact_broker/client/webhooks/create_spec.rb
287
292
  - spec/pacts/pact_broker_client-pact_broker.json
@@ -298,6 +303,7 @@ files:
298
303
  - spec/service_providers/pact_broker_client_versions_spec.rb
299
304
  - spec/service_providers/pact_helper.rb
300
305
  - spec/service_providers/pacticipants_create_spec.rb
306
+ - spec/service_providers/record_deployment_spec.rb
301
307
  - spec/service_providers/webhooks_create_spec.rb
302
308
  - spec/spec_helper.rb
303
309
  - spec/support/cli_test_pacts/bar.json
@@ -363,6 +369,7 @@ test_files:
363
369
  - spec/lib/pact_broker/client/retry_spec.rb
364
370
  - spec/lib/pact_broker/client/tasks/publication_task_spec.rb
365
371
  - spec/lib/pact_broker/client/versions/describe_spec.rb
372
+ - spec/lib/pact_broker/client/versions/record_deployment_spec.rb
366
373
  - spec/lib/pact_broker/client/versions_spec.rb
367
374
  - spec/lib/pact_broker/client/webhooks/create_spec.rb
368
375
  - spec/pacts/pact_broker_client-pact_broker.json
@@ -379,6 +386,7 @@ test_files:
379
386
  - spec/service_providers/pact_broker_client_versions_spec.rb
380
387
  - spec/service_providers/pact_helper.rb
381
388
  - spec/service_providers/pacticipants_create_spec.rb
389
+ - spec/service_providers/record_deployment_spec.rb
382
390
  - spec/service_providers/webhooks_create_spec.rb
383
391
  - spec/spec_helper.rb
384
392
  - spec/support/cli_test_pacts/bar.json