pact_broker-client 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md ADDED
@@ -0,0 +1,13 @@
1
+ Do this to generate your change history
2
+
3
+ $ git log --date=relative --pretty=format:' * %h - %s (%an, %ad)' 'package/pact_broker-client-0.0.PRODVERSION'..'package/pact_broker-client-0.0.NEWVERSION'
4
+
5
+ #### 0.0.3 (2013-11-13)
6
+
7
+ * a3488bd - Fixing application/json+hal to application/hal+json (Beth, 2 days ago)
8
+ * 0fa89ef - Updating content type to match new Webmachine implementation. Removing redundant repository_url interaction. (Beth, 2 days ago)
9
+ * 9e1539e - Redoing the URLs yet again (Beth, 3 days ago)
10
+ * 9067b83 - Working on list latest pacts (Beth, 3 days ago)
11
+ * 3ba218a - Specifying pact/latest response (Beth, 6 days ago)
12
+ * b746f23 - Changing to new /pacts/latest URL format (Beth, 6 days ago)
13
+ * 39f52cf - Working on expected 'pacts/latest' response (Beth, 6 days ago)
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pact_broker-client (0.0.2)
4
+ pact_broker-client (0.0.3)
5
5
  httparty
6
6
  json
7
7
  pact
@@ -19,7 +19,7 @@ GEM
19
19
  debugger-ruby_core_source (~> 1.2.3)
20
20
  debugger-linecache (1.2.0)
21
21
  debugger-ruby_core_source (1.2.3)
22
- diff-lcs (1.2.4)
22
+ diff-lcs (1.2.5)
23
23
  eventmachine (1.0.3)
24
24
  fakefs (0.4.2)
25
25
  find_a_port (1.0.1)
@@ -52,7 +52,7 @@ GEM
52
52
  rspec-expectations (~> 2.14.0)
53
53
  rspec-mocks (~> 2.14.0)
54
54
  rspec-core (2.14.7)
55
- rspec-expectations (2.14.3)
55
+ rspec-expectations (2.14.4)
56
56
  diff-lcs (>= 1.1.3, < 2.0)
57
57
  rspec-fire (1.2.0)
58
58
  rspec (~> 2.11)
@@ -42,7 +42,7 @@ module PactBroker
42
42
  end
43
43
 
44
44
  def default_patch_headers
45
- default_request_headers.merge('Content-Type' => 'application/json+patch')
45
+ default_request_headers.merge('Content-Type' => 'application/json')
46
46
  end
47
47
 
48
48
  def default_put_headers
@@ -25,6 +25,10 @@ module PactBroker
25
25
  PactBroker::Client::Pacticipants.new base_url: base_url
26
26
  end
27
27
 
28
+ def pacts
29
+ PactBroker::Client::Pacts.new base_url: base_url
30
+ end
31
+
28
32
  end
29
33
  end
30
34
 
@@ -19,14 +19,14 @@ module PactBroker
19
19
  def get1 options
20
20
  response = get(pacticipant_base_url(options), headers: default_get_headers)
21
21
  handle_response(response) do
22
- response.to_hash
22
+ JSON.parse(response.body)
23
23
  end
24
24
  end
25
25
 
26
26
  def list
27
27
  response = get("/pacticipants", headers: default_get_headers)
28
28
  handle_response(response) do
29
- response.to_hash
29
+ JSON.parse(response.body)
30
30
  end
31
31
  end
32
32
 
@@ -17,10 +17,24 @@ module PactBroker
17
17
  end
18
18
  end
19
19
 
20
+ def get options
21
+ url = get_consumer_contract_url(options)
22
+ response = self.class.get(url, headers: default_get_headers)
23
+ handle_response(response) do
24
+ response.body
25
+ end
26
+ end
27
+
28
+ def latest
29
+ response = self.class.get("/pacts/latest", headers: default_get_headers)
30
+ handle_response(response) do
31
+ map_pact_list_do_hash JSON.parse(response.body)["pacts"]
32
+ end
33
+ end
34
+
20
35
  def last options
21
- url = find_last_consumer_contract_url options
22
- query = options[:tag] ? {tag: options[:tag]} : {}
23
- response = self.class.get(url, headers: default_get_headers, query: query)
36
+ url = get_latest_consumer_contract_url(options)
37
+ response = self.class.get(url, headers: default_get_headers)
24
38
  handle_response(response) do
25
39
  response.body
26
40
  end
@@ -28,17 +42,48 @@ module PactBroker
28
42
 
29
43
  private
30
44
 
31
- def find_last_consumer_contract_url options
45
+ #TODO Move into mapper class
46
+ def map_pact_list_do_hash pacts_list
47
+ pacts_list.collect do | pact_hash |
48
+ {
49
+ consumer: {
50
+ name: pact_hash["_embedded"]["consumer"]["name"],
51
+ version: {
52
+ number: pact_hash["_embedded"]["consumer"]["_embedded"]["version"]["number"]
53
+ }
54
+ },
55
+ provider: {
56
+ name: pact_hash["_embedded"]["provider"]["name"]
57
+ }
58
+ }
59
+ end
60
+ end
61
+
62
+ def find_last_consumer_contract_query options
63
+ query = {:consumer => options[:consumer], :provider => options[:provider]}
64
+ query[:tag] = options[:tag] if options[:tag]
65
+ query
66
+ end
67
+
68
+ def get_latest_consumer_contract_url options
69
+ consumer_name = encode_param(options[:consumer])
70
+ provider_name = encode_param(options[:provider])
71
+ tag = options[:tag] ? "/#{options[:tag]}" : ""
72
+ "/pact/provider/#{provider_name}/consumer/#{consumer_name}/latest#{tag}"
73
+ end
74
+
75
+ def get_consumer_contract_url options
32
76
  consumer_name = encode_param(options[:consumer])
33
77
  provider_name = encode_param(options[:provider])
34
- "/pacticipants/#{consumer_name}/versions/last/pacts/#{provider_name}"
78
+ consumer_version = encode_param(options[:consumer_version])
79
+ "/pact/provider/#{provider_name}/consumer/#{consumer_name}/version/#{consumer_version}"
35
80
  end
36
81
 
37
82
  def save_consumer_contract_url consumer_contract, consumer_version
38
83
  consumer_name = encode_param(consumer_contract.consumer.name)
39
84
  provider_name = encode_param(consumer_contract.provider.name)
40
85
  version = encode_param(consumer_version)
41
- "/pacticipants/#{consumer_name}/versions/#{version}/pacts/#{provider_name}"
86
+ "/pact/provider/#{provider_name}/consumer/#{consumer_name}/version/#{version}"
42
87
  end
43
88
  end
44
89
  end
@@ -1,5 +1,5 @@
1
1
  module PactBroker
2
2
  module Client
3
- VERSION = '0.0.2'
3
+ VERSION = '0.0.3'
4
4
  end
5
5
  end
@@ -6,6 +6,61 @@
6
6
  "name": "Pact Broker Client"
7
7
  },
8
8
  "interactions": [
9
+ {
10
+ "description": "a request to list the latest pacts",
11
+ "provider_state": "a pact between Condor and the Pricing Service exists",
12
+ "request": {
13
+ "method": "get",
14
+ "path": "/pacts/latest",
15
+ "headers": {
16
+ }
17
+ },
18
+ "response": {
19
+ "headers": {
20
+ "Content-Type": "application/hal+json"
21
+ },
22
+ "status": 200,
23
+ "body": {
24
+ "_links": {
25
+ "self": {
26
+ "href": "http://localhost:1234/pacts/latest"
27
+ }
28
+ },
29
+ "pacts": [
30
+ {
31
+ "_links": {
32
+ "self": {
33
+ "href": "http://localhost:1234/pacticipants/Condor/versions/1.3.0/pacts/Pricing%20Service"
34
+ }
35
+ },
36
+ "_embedded": {
37
+ "consumer": {
38
+ "name": "Condor",
39
+ "_links": {
40
+ "self": {
41
+ "href": "http://localhost:1234/pacticipants/Condor"
42
+ }
43
+ },
44
+ "_embedded": {
45
+ "version": {
46
+ "number": "1.3.0"
47
+ }
48
+ }
49
+ },
50
+ "provider": {
51
+ "_links": {
52
+ "self": {
53
+ "href": "http://localhost:1234/pacticipants/Pricing%20Service"
54
+ }
55
+ },
56
+ "name": "Pricing Service"
57
+ }
58
+ }
59
+ }
60
+ ]
61
+ }
62
+ }
63
+ },
9
64
  {
10
65
  "description": "a request to list pacticipants",
11
66
  "provider_state": "'Condor' exists in the pact-broker",
@@ -17,7 +72,7 @@
17
72
  },
18
73
  "response": {
19
74
  "headers": {
20
- "Content-Type": "application/json+hal;charset=utf-8"
75
+ "Content-Type": "application/hal+json"
21
76
  },
22
77
  "status": 200,
23
78
  "body": {
@@ -66,7 +121,7 @@
66
121
  },
67
122
  "response": {
68
123
  "headers": {
69
- "Content-Type": "application/json+hal;charset=utf-8"
124
+ "Content-Type": "application/hal+json"
70
125
  },
71
126
  "status": 200,
72
127
  "body": {
@@ -114,7 +169,7 @@
114
169
  "provider_state": "the 'Pricing Service' already exists in the pact-broker",
115
170
  "request": {
116
171
  "method": "put",
117
- "path": "/pacticipants/Condor/versions/1.3.0/pacts/Pricing%20Service",
172
+ "path": "/pact/provider/Pricing%20Service/consumer/Condor/version/1.3.0",
118
173
  "body": {
119
174
  "consumer": {
120
175
  "name": "Condor"
@@ -141,7 +196,7 @@
141
196
  "provider_state": "the 'Pricing Service' and 'Condor' already exist in the pact-broker, and Condor already has a pact published for version 1.3.0",
142
197
  "request": {
143
198
  "method": "put",
144
- "path": "/pacticipants/Condor/versions/1.3.0/pacts/Pricing%20Service",
199
+ "path": "/pact/provider/Pricing%20Service/consumer/Condor/version/1.3.0",
145
200
  "body": {
146
201
  "consumer": {
147
202
  "name": "Condor"
@@ -168,7 +223,7 @@
168
223
  "provider_state": "'Condor' already exist in the pact-broker, but the 'Pricing Service' does not",
169
224
  "request": {
170
225
  "method": "put",
171
- "path": "/pacticipants/Condor/versions/1.3.0/pacts/Pricing%20Service",
226
+ "path": "/pact/provider/Pricing%20Service/consumer/Condor/version/1.3.0",
172
227
  "body": {
173
228
  "consumer": {
174
229
  "name": "Condor"
@@ -195,7 +250,7 @@
195
250
  "provider_state": "an error occurs while publishing a pact",
196
251
  "request": {
197
252
  "method": "put",
198
- "path": "/pacticipants/Condor/versions/1.3.0/pacts/Pricing%20Service",
253
+ "path": "/pact/provider/Pricing%20Service/consumer/Condor/version/1.3.0",
199
254
  "body": {
200
255
  "consumer": {
201
256
  "name": "Condor"
@@ -214,6 +269,7 @@
214
269
  "response": {
215
270
  "status": 500,
216
271
  "headers": {
272
+ "Content-Type": "application/json"
217
273
  },
218
274
  "body": {
219
275
  "message": {
@@ -236,7 +292,7 @@
236
292
  "repository_url": "git@git.realestate.com.au:business-systems/pricing-service"
237
293
  },
238
294
  "headers": {
239
- "Content-Type": "application/json+patch"
295
+ "Content-Type": "application/json"
240
296
  }
241
297
  },
242
298
  "response": {
@@ -255,7 +311,7 @@
255
311
  "repository_url": "git@git.realestate.com.au:business-systems/pricing-service"
256
312
  },
257
313
  "headers": {
258
- "Content-Type": "application/json+patch"
314
+ "Content-Type": "application/json"
259
315
  }
260
316
  },
261
317
  "response": {
@@ -264,40 +320,6 @@
264
320
  }
265
321
  }
266
322
  },
267
- {
268
- "description": "a request to retrieve the repository URL of the 'Pricing Service'",
269
- "provider_state": "the 'Pricing Service' does not exist in the pact-broker",
270
- "request": {
271
- "method": "get",
272
- "path": "/pacticipants/Pricing%20Service/repository_url",
273
- "headers": {
274
- "Accept": "text/plain"
275
- }
276
- },
277
- "response": {
278
- "status": 404,
279
- "headers": {
280
- }
281
- }
282
- },
283
- {
284
- "description": "a request to retrieve the repository URL of the 'Pricing Service'",
285
- "provider_state": "the 'Pricing Service' already exists in the pact-broker",
286
- "request": {
287
- "method": "get",
288
- "path": "/pacticipants/Pricing%20Service/repository_url",
289
- "headers": {
290
- "Accept": "text/plain"
291
- }
292
- },
293
- "response": {
294
- "status": 200,
295
- "headers": {
296
- "Content-Type": "text/plain;charset=utf-8"
297
- },
298
- "body": "git@git.realestate.com.au:business-systems/pricing-service"
299
- }
300
- },
301
323
  {
302
324
  "description": "a request to tag the production version of Condor",
303
325
  "provider_state": "'Condor' exists in the pact-broker",
@@ -311,7 +333,7 @@
311
333
  "repository_ref": "packages/condor-1.3.0"
312
334
  },
313
335
  "headers": {
314
- "Content-Type": "application/json+patch"
336
+ "Content-Type": "application/json"
315
337
  }
316
338
  },
317
339
  "response": {
@@ -333,7 +355,7 @@
333
355
  "repository_ref": "packages/condor-1.3.0"
334
356
  },
335
357
  "headers": {
336
- "Content-Type": "application/json+patch"
358
+ "Content-Type": "application/json"
337
359
  }
338
360
  },
339
361
  "response": {
@@ -342,19 +364,45 @@
342
364
  }
343
365
  }
344
366
  },
367
+ {
368
+ "description": "a request retrieve a pact for a specific version",
369
+ "provider_state": "the 'Pricing Service' and 'Condor' already exist in the pact-broker, and Condor already has a pact published for version 1.3.0",
370
+ "request": {
371
+ "method": "get",
372
+ "path": "/pact/provider/Pricing%20Service/consumer/Condor/version/1.3.0",
373
+ "headers": {
374
+ }
375
+ },
376
+ "response": {
377
+ "headers": {
378
+ },
379
+ "status": 200,
380
+ "body": {
381
+ "consumer": {
382
+ "name": "Condor"
383
+ },
384
+ "provider": {
385
+ "name": "Pricing Service"
386
+ },
387
+ "interactions": [
388
+
389
+ ]
390
+ }
391
+ }
392
+ },
345
393
  {
346
394
  "description": "a request to retrieve the latest pact between Condor and the Pricing Service",
347
395
  "provider_state": "a pact between Condor and the Pricing Service exists",
348
396
  "request": {
349
397
  "method": "get",
350
- "path": "/pacticipants/Condor/versions/last/pacts/Pricing%20Service",
398
+ "path": "/pact/provider/Pricing%20Service/consumer/Condor/latest",
351
399
  "headers": {
352
400
  }
353
401
  },
354
402
  "response": {
355
403
  "status": 200,
356
404
  "headers": {
357
- "Content-Type": "application/json;charset=utf-8",
405
+ "Content-Type": "application/json",
358
406
  "X-Pact-Consumer-Version": "1.3.0"
359
407
  },
360
408
  "body": {
@@ -375,7 +423,7 @@
375
423
  "provider_state": "no pact between Condor and the Pricing Service exists",
376
424
  "request": {
377
425
  "method": "get",
378
- "path": "/pacticipants/Condor/versions/last/pacts/Pricing%20Service",
426
+ "path": "/pact/provider/Pricing%20Service/consumer/Condor/latest",
379
427
  "headers": {
380
428
  }
381
429
  },
@@ -390,11 +438,10 @@
390
438
  "provider_state": "a pact between Condor and the Pricing Service exists for the production version of Condor",
391
439
  "request": {
392
440
  "method": "get",
393
- "path": "/pacticipants/Condor/versions/last/pacts/Pricing%20Service",
441
+ "path": "/pact/provider/Pricing%20Service/consumer/Condor/latest/prod",
394
442
  "headers": {
395
443
  "Accept": "application/json"
396
- },
397
- "query": "tag=prod"
444
+ }
398
445
  },
399
446
  "response": {
400
447
  "status": 200,
@@ -427,7 +474,7 @@
427
474
  "response": {
428
475
  "status": 200,
429
476
  "headers": {
430
- "Content-Type": "application/json;charset=utf-8"
477
+ "Content-Type": "application/json"
431
478
  },
432
479
  "body": {
433
480
  "number": "1.2.3",
@@ -1,5 +1,6 @@
1
1
  require 'spec_helper'
2
2
  require_relative 'pact_helper'
3
+ require 'pact_broker/client/pact_broker_client'
3
4
 
4
5
 
5
6
  module PactBroker::Client
@@ -7,6 +8,42 @@ module PactBroker::Client
7
8
 
8
9
  let(:pact_broker_client) { PactBrokerClient.new(base_url: 'http://localhost:1234') }
9
10
 
11
+ describe "listing pacts" do
12
+ context "when pacts exist" do
13
+ let(:response_body) { JSON.parse(File.read("./spec/support/pacts_latest_list.json"))}
14
+ let(:expected_pacts) do
15
+ [{
16
+ :consumer => {
17
+ :name => 'Condor',
18
+ :version => {
19
+ :number => '1.3.0'
20
+ }
21
+ },
22
+ :provider => {
23
+ :name => 'Pricing Service'
24
+ }
25
+ }
26
+ ]
27
+ end
28
+ before do
29
+ pact_broker.
30
+ given("a pact between Condor and the Pricing Service exists").
31
+ upon_receiving("a request to list the latest pacts").
32
+ with(
33
+ method: :get,
34
+ path: '/pacts/latest',
35
+ headers: {} ).
36
+ will_respond_with( headers: {'Content-Type' => 'application/hal+json'},
37
+ status: 200,
38
+ body: response_body
39
+ )
40
+ end
41
+ it "returns the response body" do
42
+ expect(pact_broker_client.pacts.latest).to eq(expected_pacts)
43
+ end
44
+ end
45
+ end
46
+
10
47
  describe "listing pacticipants" do
11
48
  context "when a pacticipant exists" do
12
49
  let(:response_body) { JSON.parse(File.read("./spec/support/pacticipants_list.json"))}
@@ -18,7 +55,7 @@ module PactBroker::Client
18
55
  method: :get,
19
56
  path: '/pacticipants',
20
57
  headers: {} ).
21
- will_respond_with( headers: {'Content-Type' => 'application/json+hal;charset=utf-8'},
58
+ will_respond_with( headers: {'Content-Type' => 'application/hal+json'},
22
59
  status: 200,
23
60
  body: response_body
24
61
  )
@@ -41,7 +78,7 @@ module PactBroker::Client
41
78
  method: :get,
42
79
  path: '/pacticipants/Pricing%20Service',
43
80
  headers: {} ).
44
- will_respond_with( headers: {'Content-Type' => 'application/json+hal;charset=utf-8'},
81
+ will_respond_with( headers: {'Content-Type' => 'application/hal+json'},
45
82
  status: 200,
46
83
  body: response_body
47
84
  )
@@ -26,7 +26,7 @@ module PactBroker::Client
26
26
  let(:pact_broker_version) { Pact::Term.new(:matcher => /\d+\.\d+\.\d+/, :generate => '1.0.0') }
27
27
  let(:pact_broker_response_headers) { {} }
28
28
  let(:default_request_headers) { { 'Content-Type' => 'application/json'} }
29
- let(:patch_request_headers) { { 'Content-Type' => 'application/json+patch'} }
29
+ let(:patch_request_headers) { { 'Content-Type' => 'application/json'} }
30
30
  let(:get_request_headers) { { 'Accept' => 'application/json'} }
31
31
 
32
32
  describe "publishing a pact" do
@@ -40,7 +40,7 @@ module PactBroker::Client
40
40
  upon_receiving("a request to publish a pact").
41
41
  with({
42
42
  method: :put,
43
- path: '/pacticipants/Condor/versions/1.3.0/pacts/Pricing%20Service',
43
+ path: '/pact/provider/Pricing%20Service/consumer/Condor/version/1.3.0',
44
44
  headers: default_request_headers,
45
45
  body: pact_hash }).
46
46
  will_respond_with( headers: pact_broker_response_headers,
@@ -59,7 +59,7 @@ module PactBroker::Client
59
59
  upon_receiving("a request to publish a pact").
60
60
  with({
61
61
  method: :put,
62
- path: '/pacticipants/Condor/versions/1.3.0/pacts/Pricing%20Service',
62
+ path: '/pact/provider/Pricing%20Service/consumer/Condor/version/1.3.0',
63
63
  headers: default_request_headers,
64
64
  body: pact_hash }).
65
65
  will_respond_with( headers: pact_broker_response_headers,
@@ -78,7 +78,7 @@ module PactBroker::Client
78
78
  upon_receiving("a request to publish a pact").
79
79
  with({
80
80
  method: :put,
81
- path: '/pacticipants/Condor/versions/1.3.0/pacts/Pricing%20Service',
81
+ path: '/pact/provider/Pricing%20Service/consumer/Condor/version/1.3.0',
82
82
  headers: default_request_headers,
83
83
  body: pact_hash }).
84
84
  will_respond_with( headers: pact_broker_response_headers,
@@ -97,12 +97,12 @@ module PactBroker::Client
97
97
  upon_receiving("a request to publish a pact").
98
98
  with({
99
99
  method: :put,
100
- path: '/pacticipants/Condor/versions/1.3.0/pacts/Pricing%20Service',
100
+ path: '/pact/provider/Pricing%20Service/consumer/Condor/version/1.3.0',
101
101
  headers: default_request_headers,
102
102
  body: pact_hash }).
103
103
  will_respond_with({
104
104
  status: 500,
105
- headers: pact_broker_response_headers,
105
+ headers: {'Content-Type' => 'application/json'},
106
106
  body: {
107
107
  message: Pact::Term.new(matcher: /.*/, generate: 'An error occurred')
108
108
  }
@@ -158,46 +158,6 @@ module PactBroker::Client
158
158
  end
159
159
  end
160
160
 
161
- describe "retrieving a repository url" do
162
- context "where the pacticipant does not already exist in the pact-broker" do
163
- before do
164
- pact_broker.
165
- given("the 'Pricing Service' does not exist in the pact-broker").
166
- upon_receiving("a request to retrieve the repository URL of the 'Pricing Service'").
167
- with(
168
- method: :get,
169
- path: '/pacticipants/Pricing%20Service/repository_url',
170
- headers: get_request_headers.merge({'Accept' => 'text/plain'})).
171
- will_respond_with(
172
- status: 404,
173
- headers: pact_broker_response_headers
174
- )
175
- end
176
- it "returns nil" do
177
- expect(pact_broker_client.pacticipants.repository_url({:pacticipant => 'Pricing Service'})).to eq(nil)
178
- end
179
- end
180
- context "where the 'Pricing Service' exists in the pact-broker" do
181
- before do
182
- pact_broker.
183
- given("the 'Pricing Service' already exists in the pact-broker").
184
- upon_receiving("a request to retrieve the repository URL of the 'Pricing Service'").
185
- with(
186
- method: :get,
187
- path: '/pacticipants/Pricing%20Service/repository_url',
188
- headers: get_request_headers.merge({'Accept' => 'text/plain'})).
189
- will_respond_with(
190
- status: 200,
191
- headers: pact_broker_response_headers.merge({'Content-Type' => 'text/plain;charset=utf-8'}),
192
- body: repository_url
193
- )
194
- end
195
- it "returns the URL" do
196
- expect(pact_broker_client.pacticipants.repository_url({:pacticipant => 'Pricing Service'})).to eq repository_url
197
- end
198
- end
199
- end
200
-
201
161
  describe "tagging a version with prod details" do
202
162
  let(:repository_ref) { "packages/condor-#{version}" }
203
163
 
@@ -243,17 +203,37 @@ module PactBroker::Client
243
203
  end
244
204
 
245
205
  describe "retrieving a pact" do
206
+ describe "retriving a specific version" do
207
+ before do
208
+ pact_broker.
209
+ given("the 'Pricing Service' and 'Condor' already exist in the pact-broker, and Condor already has a pact published for version 1.3.0").
210
+ upon_receiving("a request retrieve a pact for a specific version").
211
+ with(
212
+ method: :get,
213
+ path: '/pact/provider/Pricing%20Service/consumer/Condor/version/1.3.0',
214
+ headers: {} ).
215
+ will_respond_with( headers: pact_broker_response_headers,
216
+ status: 200,
217
+ body: pact_hash
218
+ )
219
+ end
220
+ it "returns the pact json" do
221
+ response = pact_broker_client.pacticipants.versions.pacts.get consumer: 'Condor', provider: 'Pricing Service', consumer_version: '1.3.0'
222
+ expect(response).to eq(pact_json)
223
+ end
224
+ end
225
+
246
226
  describe "finding the latest version" do
247
227
  context "when a pact is found" do
248
228
 
249
- let(:response_headers) { pact_broker_response_headers.merge({'Content-Type' => 'application/json;charset=utf-8', 'X-Pact-Consumer-Version' => consumer_version}) }
229
+ let(:response_headers) { pact_broker_response_headers.merge({'Content-Type' => 'application/json', 'X-Pact-Consumer-Version' => consumer_version}) }
250
230
  before do
251
231
  pact_broker.
252
232
  given("a pact between Condor and the Pricing Service exists").
253
233
  upon_receiving("a request to retrieve the latest pact between Condor and the Pricing Service").
254
234
  with({
255
235
  method: :get,
256
- path: '/pacticipants/Condor/versions/last/pacts/Pricing%20Service',
236
+ path: '/pact/provider/Pricing%20Service/consumer/Condor/latest',
257
237
  headers: {}
258
238
  }).
259
239
  will_respond_with({
@@ -276,7 +256,7 @@ module PactBroker::Client
276
256
  upon_receiving("a request to retrieve the latest pact between Condor and the Pricing Service").
277
257
  with({
278
258
  method: :get,
279
- path: '/pacticipants/Condor/versions/last/pacts/Pricing%20Service',
259
+ path: '/pact/provider/Pricing%20Service/consumer/Condor/latest',
280
260
  headers: {}
281
261
  }).
282
262
  will_respond_with({
@@ -298,13 +278,12 @@ module PactBroker::Client
298
278
  upon_receiving("a request to retrieve the pact between the production verison of Condor and the Pricing Service").
299
279
  with({
300
280
  method: :get,
301
- path: '/pacticipants/Condor/versions/last/pacts/Pricing%20Service',
302
- query: 'tag=prod',
281
+ path: '/pact/provider/Pricing%20Service/consumer/Condor/latest/prod',
303
282
  headers: get_request_headers
304
283
  }).
305
284
  will_respond_with({
306
285
  status: 200,
307
- headers: {'Content-Type' => 'application/json;charset=utf-8', 'X-Pact-Consumer-Version' => consumer_version},
286
+ headers: {'Content-Type' => 'application/json', 'X-Pact-Consumer-Version' => consumer_version},
308
287
  body: pact_hash,
309
288
  headers: pact_broker_response_headers
310
289
  })
@@ -328,9 +307,13 @@ module PactBroker::Client
328
307
  pact_broker.
329
308
  given("a version with production details exists for the Pricing Service").
330
309
  upon_receiving("a request for the latest version tagged with 'prod'").
331
- with(method: :get, path: '/pacticipants/Pricing%20Service/versions/last', query: 'tag=prod', headers: get_request_headers).
310
+ with(
311
+ method: :get,
312
+ path: '/pacticipants/Pricing%20Service/versions/last',
313
+ query: 'tag=prod',
314
+ headers: get_request_headers).
332
315
  will_respond_with( status: 200,
333
- headers: pact_broker_response_headers.merge({'Content-Type' => 'application/json;charset=utf-8'}),
316
+ headers: pact_broker_response_headers.merge({'Content-Type' => 'application/json'}),
334
317
  body: body )
335
318
  end
336
319
  it 'returns the version details' do
@@ -2,6 +2,10 @@ require 'spec_helper'
2
2
  require 'pact/consumer/rspec'
3
3
 
4
4
 
5
+ Pact.configure do | config |
6
+ config.logger.level = Logger::DEBUG
7
+ end
8
+
5
9
  Pact.service_consumer 'Pact Broker Client' do
6
10
 
7
11
  has_pact_with "Pact Broker" do
@@ -0,0 +1,39 @@
1
+ {
2
+ "_links": {
3
+ "self": {
4
+ "href": "http://localhost:1234/pacts/latest"
5
+ }
6
+ },
7
+ "pacts": [
8
+ {
9
+ "_links": {
10
+ "self": {
11
+ "href": "http://localhost:1234/pacticipants/Condor/versions/1.3.0/pacts/Pricing%20Service"
12
+ }
13
+ },
14
+ "_embedded": {
15
+ "consumer": {
16
+ "name": "Condor",
17
+ "_links": {
18
+ "self": {
19
+ "href": "http://localhost:1234/pacticipants/Condor"
20
+ }
21
+ },
22
+ "_embedded": {
23
+ "version": {
24
+ "number": "1.3.0"
25
+ }
26
+ }
27
+ },
28
+ "provider": {
29
+ "_links": {
30
+ "self": {
31
+ "href": "http://localhost:1234/pacticipants/Pricing%20Service"
32
+ }
33
+ },
34
+ "name": "Pricing Service"
35
+ }
36
+ }
37
+ }
38
+ ]
39
+ }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pact_broker-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-11-05 00:00:00.000000000 Z
12
+ date: 2013-11-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: pact
@@ -148,6 +148,7 @@ extra_rdoc_files: []
148
148
  files:
149
149
  - .gitignore
150
150
  - .rspec
151
+ - CHANGELOG.md
151
152
  - Gemfile
152
153
  - Gemfile.lock
153
154
  - README.md
@@ -175,6 +176,7 @@ files:
175
176
  - spec/spec_helper.rb
176
177
  - spec/support/pacticipant_get.json
177
178
  - spec/support/pacticipants_list.json
179
+ - spec/support/pacts_latest_list.json
178
180
  - tasks/pact.rake
179
181
  homepage: https://github.com/bethesque/pact_broker-client.git
180
182
  licenses:
@@ -191,7 +193,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
191
193
  version: '0'
192
194
  segments:
193
195
  - 0
194
- hash: -1865173993885174069
196
+ hash: 931028457925136727
195
197
  required_rubygems_version: !ruby/object:Gem::Requirement
196
198
  none: false
197
199
  requirements:
@@ -200,7 +202,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
200
202
  version: '0'
201
203
  segments:
202
204
  - 0
203
- hash: -1865173993885174069
205
+ hash: 931028457925136727
204
206
  requirements: []
205
207
  rubyforge_project:
206
208
  rubygems_version: 1.8.23
@@ -218,3 +220,4 @@ test_files:
218
220
  - spec/spec_helper.rb
219
221
  - spec/support/pacticipant_get.json
220
222
  - spec/support/pacticipants_list.json
223
+ - spec/support/pacts_latest_list.json