Skip to content

Commit 8f0f16a

Browse files
committed
feat(pacticipant): expose repositoryUrl in resource
1 parent 6da6e02 commit 8f0f16a

File tree

8 files changed

+39
-28
lines changed

8 files changed

+39
-28
lines changed

lib/pact_broker/api/resources/pacticipant.rb

+2-4
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ def known_methods
3232

3333
def from_json
3434
if pacticipant
35-
@pacticipant = pacticipant_service.update params.merge(name: pacticipant_name)
35+
@pacticipant = pacticipant_service.update params_with_string_keys.merge('name' => pacticipant_name)
3636
else
37-
@pacticipant = pacticipant_service.create params.merge(name: pacticipant_name)
37+
@pacticipant = pacticipant_service.create params_with_string_keys.merge('name' => pacticipant_name)
3838
response.headers["Location"] = pacticipant_url(base_url, pacticipant)
3939
end
4040
response.body = to_json
@@ -62,9 +62,7 @@ def pacticipant
6262
def pacticipant_name
6363
identifier_from_path[:name]
6464
end
65-
6665
end
6766
end
68-
6967
end
7068
end

lib/pact_broker/api/resources/pacticipants.rb

+1-3
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def post_is_create?
3232
end
3333

3434
def from_json
35-
created_model = pacticipant_service.create params
35+
created_model = pacticipant_service.create params_with_string_keys
3636
response.body = decorator_for(created_model).to_json(user_options: decorator_context)
3737
end
3838

@@ -55,9 +55,7 @@ def decorator_for model
5555
def new_model
5656
@new_model ||= decorator_for(PactBroker::Domain::Pacticipant.new).from_json(request.body.to_s)
5757
end
58-
5958
end
6059
end
61-
6260
end
6361
end

lib/pact_broker/pacticipants/service.rb

+8-4
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,17 @@ def self.find_relationships
7070
end
7171

7272
def self.update params
73-
pacticipant = pacticipant_repository.find_by_name(params.fetch(:name))
74-
pacticipant.update(params)
75-
pacticipant_repository.find_by_name(params.fetch(:name))
73+
pacticipant = pacticipant_repository.find_by_name(params.fetch('name'))
74+
PactBroker::Api::Decorators::PacticipantDecorator.new(pacticipant).from_hash(params)
75+
pacticipant.save
76+
pacticipant_repository.find_by_name(params.fetch('name'))
7677
end
7778

7879
def self.create params
79-
pacticipant_repository.create(params)
80+
pacticipant = PactBroker::Domain::Pacticipant.new
81+
PactBroker::Api::Decorators::PacticipantDecorator.new(pacticipant).from_hash(params)
82+
pacticipant.save
83+
pacticipant
8084
end
8185

8286
def self.delete name

spec/features/create_pacticipant_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
let(:path) { "/pacticipants" }
55
let(:headers) { {'CONTENT_TYPE' => 'application/json'} }
66
let(:response_body) { JSON.parse(last_response.body, symbolize_names: true)}
7-
let(:pacticipant_hash) { {name: 'Foo Thing'}}
7+
let(:pacticipant_hash) { { name: 'Foo Thing' } }
88

99
subject { post path, pacticipant_hash.to_json, headers; last_response }
1010

+10-12
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,23 @@
1-
xdescribe "Publishing a pact" do
1+
describe "Publishing a pact" do
22

3-
let(:request_body) { load_fixture('update_pacticipant.json') }
3+
let(:request_body) { {'repositoryUrl' => 'http://foo'} }
44
let(:path) { "/pacticipants/Some%20Consumer" }
55
let(:response_body_json) { JSON.parse(subject.body) }
66

7-
subject { patch path, request_body, {'CONTENT_TYPE' => 'application/json-patch+json' }; last_response }
7+
subject { patch path, request_body.to_json, {'CONTENT_TYPE' => 'application/json' }; last_response }
88

99
context "when the pacticipant exists" do
10+
11+
before do
12+
TestDataBuilder.new.create_pacticipant("Some Consumer")
13+
end
1014
it "returns a 200 OK" do
11-
expect(subject.status).to be 201
15+
puts subject.body unless subject.status == 200
16+
expect(subject.status).to be 200
1217
end
1318

1419
it "returns a json body with the updated pacticipant" do
15-
expect(subject.headers['Content-Type']).to eq "application/json"
16-
end
17-
18-
end
19-
20-
context "when the pacticipant does not exist" do
21-
it "returns a 404" do
22-
expect(subject.status).to be 404
20+
expect(subject.headers['Content-Type']).to eq "application/hal+json;charset=utf-8"
2321
end
2422
end
2523
end

spec/lib/pact_broker/api/resources/pacticipant_spec.rb

-2
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,6 @@ module Resources
6464
end
6565
end
6666
end
67-
6867
end
6968
end
70-
7169
end

spec/lib/pact_broker/api/resources/pacticipants_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ module Resources
4747

4848
context "with valid JSON" do
4949
it "creates the pacticipant" do
50-
expect(PactBroker::Pacticipants::Service).to receive(:create).with(params)
50+
expect(PactBroker::Pacticipants::Service).to receive(:create).with('name' => 'New Consumer')
5151
subject
5252
end
5353

spec/lib/pact_broker/pacticipants/service_spec.rb

+16-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,22 @@ module Pacticipants
1010

1111
subject{ Service }
1212

13+
let(:td) { TestDataBuilder.new }
14+
15+
describe ".update" do
16+
before do
17+
td.create_pacticipant("Foo")
18+
end
19+
20+
let(:params) { { 'name' => 'Foo', 'repositoryUrl' => 'http://foo' } }
21+
22+
subject { Service.update(params) }
23+
24+
it "updates the repositoryUrl" do
25+
expect(subject.repository_url).to eq 'http://foo'
26+
end
27+
end
28+
1329
describe ".messages_for_potential_duplicate_pacticipants" do
1430

1531
let(:base_url) { 'http://example.org' }
@@ -126,7 +142,6 @@ module Pacticipants
126142
it "returns a list of relationships" do
127143
expect(subject.find_relationships).to eq([PactBroker::Domain::Relationship.create(consumer, provider, pact, verification, webhooks)])
128144
end
129-
130145
end
131146

132147
describe "delete" do

0 commit comments

Comments
 (0)