pact_broker-client 1.23.0 → 1.24.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -27,6 +27,12 @@ module PactBroker::Client::CLI
27
27
  Delegate.call(options)
28
28
  end
29
29
 
30
+ desc '', ''
31
+ ignored_and_hidden_potential_options_from_environment_variables
32
+ def test_without_parameters
33
+ Delegate.call(options)
34
+ end
35
+
30
36
  default_command :test_default
31
37
  end
32
38
 
@@ -65,6 +71,11 @@ module PactBroker::Client::CLI
65
71
  end
66
72
  TestThor.start(%w{test_using_env_vars --broker-base-url http://bar})
67
73
  end
74
+
75
+ it "allows commands to be called that don't use the environment variables" do
76
+ expect(Delegate).to receive(:call)
77
+ TestThor.start(%w{test_without_parameters})
78
+ end
68
79
  end
69
80
 
70
81
  describe ".turn_muliple_tag_options_into_array" do
@@ -18,10 +18,6 @@ module PactBroker
18
18
  stub_request(:get, "http://broker").with(headers: { "Authorization" => /.*/}).to_return(status: 200, body: index_body, headers: { "Content-Type" => "application/hal+json" } )
19
19
  end
20
20
 
21
- let!(:webhook_request) do
22
- stub_request(:post, "http://broker/webhooks").to_return(status: 405)
23
- end
24
-
25
21
  let(:params) do
26
22
  {
27
23
  http_method: "POST",
@@ -44,8 +40,22 @@ module PactBroker
44
40
  subject { Create.call(params, "http://broker", pact_broker_client_options) }
45
41
 
46
42
  context "when a 405 is returned from the webhook creation request" do
47
- it "raises an error with a message to upgrade the Pact Broker" do
48
- expect { subject }.to raise_error PactBroker::Client::Error, /This version of the Pact Broker/
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
49
59
  end
50
60
  end
51
61
 
@@ -1260,6 +1260,7 @@
1260
1260
  "Accept": "application/hal+json"
1261
1261
  },
1262
1262
  "body": {
1263
+ "description": "a webhook",
1263
1264
  "events": [
1264
1265
  {
1265
1266
  "name": "contract_content_changed"
@@ -1304,6 +1305,74 @@
1304
1305
  }
1305
1306
  }
1306
1307
  },
1308
+ {
1309
+ "description": "a request to create a webhook with every possible event type",
1310
+ "providerState": "the 'Pricing Service' and 'Condor' already exist in the pact-broker",
1311
+ "request": {
1312
+ "method": "post",
1313
+ "path": "/webhooks/provider/Pricing%20Service/consumer/Condor",
1314
+ "headers": {
1315
+ "Content-Type": "application/json",
1316
+ "Accept": "application/hal+json"
1317
+ },
1318
+ "body": {
1319
+ "description": "a webhook",
1320
+ "events": [
1321
+ {
1322
+ "name": "contract_content_changed"
1323
+ },
1324
+ {
1325
+ "name": "contract_published"
1326
+ },
1327
+ {
1328
+ "name": "provider_verification_published"
1329
+ },
1330
+ {
1331
+ "name": "provider_verification_succeeded"
1332
+ },
1333
+ {
1334
+ "name": "provider_verification_failed"
1335
+ }
1336
+ ],
1337
+ "request": {
1338
+ "url": "https://webhook",
1339
+ "method": "POST",
1340
+ "headers": {
1341
+ "Foo": "bar",
1342
+ "Bar": "foo"
1343
+ },
1344
+ "body": {
1345
+ "some": "body"
1346
+ },
1347
+ "username": "username",
1348
+ "password": "password"
1349
+ }
1350
+ }
1351
+ },
1352
+ "response": {
1353
+ "status": 201,
1354
+ "headers": {
1355
+ "Content-Type": "application/hal+json;charset=utf-8"
1356
+ },
1357
+ "body": {
1358
+ "_links": {
1359
+ "self": {
1360
+ "href": "http://localhost:1234/some-url",
1361
+ "title": "A title"
1362
+ }
1363
+ }
1364
+ },
1365
+ "matchingRules": {
1366
+ "$.body._links.self.href": {
1367
+ "match": "regex",
1368
+ "regex": "http:\\/\\/.*"
1369
+ },
1370
+ "$.body._links.self.title": {
1371
+ "match": "type"
1372
+ }
1373
+ }
1374
+ }
1375
+ },
1307
1376
  {
1308
1377
  "description": "a request to create a webhook with a non-JSON body for a consumer and provider",
1309
1378
  "providerState": "the 'Pricing Service' and 'Condor' already exist in the pact-broker",
@@ -1315,6 +1384,7 @@
1315
1384
  "Accept": "application/hal+json"
1316
1385
  },
1317
1386
  "body": {
1387
+ "description": "a webhook",
1318
1388
  "events": [
1319
1389
  {
1320
1390
  "name": "contract_content_changed"
@@ -1368,6 +1438,7 @@
1368
1438
  "Accept": "application/hal+json"
1369
1439
  },
1370
1440
  "body": {
1441
+ "description": "a webhook",
1371
1442
  "events": [
1372
1443
  {
1373
1444
  "name": "contract_content_changed"
@@ -1421,6 +1492,7 @@
1421
1492
  "Accept": "application/hal+json"
1422
1493
  },
1423
1494
  "body": {
1495
+ "description": "a webhook",
1424
1496
  "events": [
1425
1497
  {
1426
1498
  "name": "contract_content_changed"
@@ -1488,6 +1560,7 @@
1488
1560
  "Accept": "application/hal+json"
1489
1561
  },
1490
1562
  "body": {
1563
+ "description": "a webhook",
1491
1564
  "events": [
1492
1565
  {
1493
1566
  "name": "contract_content_changed"
@@ -1545,6 +1618,7 @@
1545
1618
  "Accept": "application/hal+json"
1546
1619
  },
1547
1620
  "body": {
1621
+ "description": "a webhook",
1548
1622
  "events": [
1549
1623
  {
1550
1624
  "name": "contract_content_changed"
@@ -1601,6 +1675,7 @@
1601
1675
  "Accept": "application/hal+json"
1602
1676
  },
1603
1677
  "body": {
1678
+ "description": "a webhook",
1604
1679
  "events": [
1605
1680
  {
1606
1681
  "name": "contract_content_changed"
@@ -1658,6 +1733,7 @@
1658
1733
  "Accept": "application/hal+json"
1659
1734
  },
1660
1735
  "body": {
1736
+ "description": "a webhook",
1661
1737
  "events": [
1662
1738
  {
1663
1739
  "name": "contract_content_changed"
@@ -1701,6 +1777,98 @@
1701
1777
  }
1702
1778
  }
1703
1779
  }
1780
+ },
1781
+ {
1782
+ "description": "a request for the index resource with the webhook relation",
1783
+ "request": {
1784
+ "method": "get",
1785
+ "path": "/",
1786
+ "headers": {
1787
+ "Accept": "application/hal+json"
1788
+ }
1789
+ },
1790
+ "response": {
1791
+ "status": 200,
1792
+ "headers": {
1793
+ "Content-Type": "application/hal+json;charset=utf-8"
1794
+ },
1795
+ "body": {
1796
+ "_links": {
1797
+ "pb:webhook": {
1798
+ "href": "http://localhost:1234/webhooks/{uuid}",
1799
+ "templated": true
1800
+ }
1801
+ }
1802
+ },
1803
+ "matchingRules": {
1804
+ "$.body._links.pb:webhook.href": {
1805
+ "match": "regex",
1806
+ "regex": "http:\\/\\/.*\\/webhooks\\/{uuid}"
1807
+ }
1808
+ }
1809
+ }
1810
+ },
1811
+ {
1812
+ "description": "a request to create a webhook with a JSON body and a uuid",
1813
+ "providerState": "the 'Pricing Service' and 'Condor' already exist in the pact-broker",
1814
+ "request": {
1815
+ "method": "put",
1816
+ "path": "/webhooks/696c5f93-1b7f-44bc-8d03-59440fcaa9a0",
1817
+ "headers": {
1818
+ "Content-Type": "application/json",
1819
+ "Accept": "application/hal+json"
1820
+ },
1821
+ "body": {
1822
+ "description": "a webhook",
1823
+ "events": [
1824
+ {
1825
+ "name": "contract_content_changed"
1826
+ }
1827
+ ],
1828
+ "request": {
1829
+ "url": "https://webhook",
1830
+ "method": "POST",
1831
+ "headers": {
1832
+ "Foo": "bar",
1833
+ "Bar": "foo"
1834
+ },
1835
+ "body": {
1836
+ "some": "body"
1837
+ },
1838
+ "username": "username",
1839
+ "password": "password"
1840
+ },
1841
+ "provider": {
1842
+ "name": "Pricing Service"
1843
+ },
1844
+ "consumer": {
1845
+ "name": "Condor"
1846
+ }
1847
+ }
1848
+ },
1849
+ "response": {
1850
+ "status": 201,
1851
+ "headers": {
1852
+ "Content-Type": "application/hal+json;charset=utf-8"
1853
+ },
1854
+ "body": {
1855
+ "_links": {
1856
+ "self": {
1857
+ "href": "http://localhost:1234/some-url",
1858
+ "title": "A title"
1859
+ }
1860
+ }
1861
+ },
1862
+ "matchingRules": {
1863
+ "$.body._links.self.href": {
1864
+ "match": "regex",
1865
+ "regex": "http:\\/\\/.*"
1866
+ },
1867
+ "$.body._links.self.title": {
1868
+ "match": "type"
1869
+ }
1870
+ }
1871
+ }
1704
1872
  }
1705
1873
  ],
1706
1874
  "metadata": {
@@ -63,4 +63,25 @@ module PactBrokerPactHelperMethods
63
63
  }
64
64
  )
65
65
  end
66
+
67
+ def mock_pact_broker_index_with_webhook_relation(context)
68
+ pact_broker
69
+ .upon_receiving("a request for the index resource with the webhook relation")
70
+ .with(
71
+ method: :get,
72
+ path: '/',
73
+ headers: context.get_request_headers).
74
+ will_respond_with(
75
+ status: 200,
76
+ headers: context.pact_broker_response_headers,
77
+ body: {
78
+ _links: {
79
+ :'pb:webhook' => {
80
+ href: Pact.term(pact_broker.mock_service_base_url + "/webhooks/{uuid}", %r{http://.*/webhooks/{uuid}}),
81
+ templated: true
82
+ }
83
+ }
84
+ }
85
+ )
86
+ end
66
87
  end
@@ -6,8 +6,12 @@ RSpec.describe "creating a webhook", pact: true do
6
6
  include_context "pact broker"
7
7
  include PactBrokerPactHelperMethods
8
8
 
9
+ let(:event_names) { %w{contract_content_changed contract_published provider_verification_published provider_verification_succeeded provider_verification_failed} }
10
+
9
11
  let(:params) do
10
12
  {
13
+ description: "a webhook",
14
+ events: %w{contract_content_changed},
11
15
  http_method: "POST",
12
16
  url: "https://webhook",
13
17
  headers: { "Foo" => "bar", "Bar" => "foo"},
@@ -15,8 +19,7 @@ RSpec.describe "creating a webhook", pact: true do
15
19
  password: "password",
16
20
  body: body,
17
21
  consumer: "Condor",
18
- provider: "Pricing Service",
19
- events: ["contract_content_changed"]
22
+ provider: "Pricing Service"
20
23
  }.tap { |it| Pact::Fixture.add_fixture(:create_webhook_params, it) }
21
24
  end
22
25
 
@@ -24,10 +27,9 @@ RSpec.describe "creating a webhook", pact: true do
24
27
 
25
28
  let(:request_body) do
26
29
  {
30
+ "description" => "a webhook",
27
31
  "events" => [
28
- {
29
- "name" => "contract_content_changed"
30
- }
32
+ "name" => "contract_content_changed"
31
33
  ],
32
34
  "request" => {
33
35
  "url" => "https://webhook",
@@ -84,6 +86,27 @@ RSpec.describe "creating a webhook", pact: true do
84
86
  end
85
87
  end
86
88
 
89
+ context "when a valid webhook with every possible event type is sumbitted" do
90
+ before do
91
+ params.merge!(events: event_names)
92
+ request_body.merge!("events" => event_names.map{ |event_name| { "name" => event_name } })
93
+
94
+ pact_broker
95
+ .given("the 'Pricing Service' and 'Condor' already exist in the pact-broker")
96
+ .upon_receiving("a request to create a webhook with every possible event type")
97
+ .with(
98
+ method: :post,
99
+ path: '/webhooks/provider/Pricing%20Service/consumer/Condor',
100
+ headers: post_request_headers,
101
+ body: request_body)
102
+ .will_respond_with(success_response)
103
+ end
104
+
105
+ it "returns a CommandResult with success = true" do
106
+ expect(subject.success).to be true
107
+ end
108
+ end
109
+
87
110
  context "when a valid webhook with an XML body is submitted" do
88
111
  before do
89
112
  request_body["request"]["body"] = body
@@ -252,4 +275,30 @@ RSpec.describe "creating a webhook", pact: true do
252
275
  expect(subject.success).to be true
253
276
  end
254
277
  end
278
+
279
+ context "when a uuid is specified" do
280
+ before do
281
+ params.merge!(uuid: uuid)
282
+ request_body["provider"] = { "name" => "Pricing Service" }
283
+ request_body["consumer"] = { "name" => "Condor" }
284
+ mock_pact_broker_index_with_webhook_relation(self)
285
+
286
+ pact_broker
287
+ .upon_receiving("a request to create a webhook with a JSON body and a uuid")
288
+ .given("the 'Pricing Service' and 'Condor' already exist in the pact-broker")
289
+ .with(
290
+ method: :put,
291
+ path: "/webhooks/#{uuid}",
292
+ headers: put_request_headers,
293
+ body: request_body)
294
+ .will_respond_with(success_response)
295
+ end
296
+ let(:uuid) { '696c5f93-1b7f-44bc-8d03-59440fcaa9a0' }
297
+
298
+ it "returns a CommandResult with success = true" do
299
+ expect(subject).to be_a PactBroker::Client::CommandResult
300
+ expect(subject.success).to be true
301
+ expect(subject.message).to eq "Webhook \"A title\" created"
302
+ end
303
+ end
255
304
  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.23.0
4
+ version: 1.24.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: 2020-01-21 00:00:00.000000000 Z
11
+ date: 2020-02-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -199,6 +199,7 @@ files:
199
199
  - lib/pact_broker/client/can_i_deploy.rb
200
200
  - lib/pact_broker/client/cli/broker.rb
201
201
  - lib/pact_broker/client/cli/can_i_deploy_long_desc.txt
202
+ - lib/pact_broker/client/cli/create_or_update_webhook_long_desc.txt
202
203
  - lib/pact_broker/client/cli/create_webhook_long_desc.txt
203
204
  - lib/pact_broker/client/cli/custom_thor.rb
204
205
  - lib/pact_broker/client/cli/version_selector_options_parser.rb
@@ -244,8 +245,10 @@ files:
244
245
  - spec/lib/pact_broker/client/base_client_spec.rb
245
246
  - spec/lib/pact_broker/client/can_i_deploy_spec.rb
246
247
  - spec/lib/pact_broker/client/cli/broker_can_i_deploy_spec.rb
248
+ - spec/lib/pact_broker/client/cli/broker_create_or_update_webhook_spec.rb
247
249
  - spec/lib/pact_broker/client/cli/broker_create_webhook_spec.rb
248
250
  - spec/lib/pact_broker/client/cli/broker_publish_spec.rb
251
+ - spec/lib/pact_broker/client/cli/broker_run_webhook_commands_spec.rb
249
252
  - spec/lib/pact_broker/client/cli/custom_thor_spec.rb
250
253
  - spec/lib/pact_broker/client/cli/version_selector_options_parser_spec.rb
251
254
  - spec/lib/pact_broker/client/git_spec.rb
@@ -309,7 +312,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
309
312
  version: '0'
310
313
  requirements: []
311
314
  rubyforge_project:
312
- rubygems_version: 2.6.14.3
315
+ rubygems_version: 2.7.6
313
316
  signing_key:
314
317
  specification_version: 4
315
318
  summary: See description
@@ -319,8 +322,10 @@ test_files:
319
322
  - spec/lib/pact_broker/client/base_client_spec.rb
320
323
  - spec/lib/pact_broker/client/can_i_deploy_spec.rb
321
324
  - spec/lib/pact_broker/client/cli/broker_can_i_deploy_spec.rb
325
+ - spec/lib/pact_broker/client/cli/broker_create_or_update_webhook_spec.rb
322
326
  - spec/lib/pact_broker/client/cli/broker_create_webhook_spec.rb
323
327
  - spec/lib/pact_broker/client/cli/broker_publish_spec.rb
328
+ - spec/lib/pact_broker/client/cli/broker_run_webhook_commands_spec.rb
324
329
  - spec/lib/pact_broker/client/cli/custom_thor_spec.rb
325
330
  - spec/lib/pact_broker/client/cli/version_selector_options_parser_spec.rb
326
331
  - spec/lib/pact_broker/client/git_spec.rb