Skip to content

Commit

Permalink
feat: support PATCH for pacticipant with application/merge-patch+json
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed May 30, 2021
1 parent ab1cd01 commit 404e14c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lib/pact_broker/api/resources/pacticipant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ def content_types_provided
end

def content_types_accepted
[["application/json", :from_json]]
[
["application/json", :from_json],
["application/merge-patch+json", :from_merge_patch_json]
]
end

def allowed_methods
Expand Down Expand Up @@ -44,6 +47,14 @@ def from_json
response.body = to_json
end

def from_merge_patch_json
if request.patch?
from_json
else
415
end
end

def resource_exists?
!!pacticipant
end
Expand Down
28 changes: 28 additions & 0 deletions spec/features/update_pacticipant_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@
context "when the pacticipant does not exist" do
it { is_expected.to be_a_404_response }
end

context "with application/merge-patch+json" do
subject { put(path, request_body.to_json, {'CONTENT_TYPE' => 'application/merge-patch+json' }) }

its(:status) { is_expected.to eq 415 }
end

end

context "with a PATCH" do
Expand All @@ -66,5 +73,26 @@
expect(subject.headers['Content-Type']).to eq "application/hal+json;charset=utf-8"
end
end

context "with application/merge-patch+json" do
before do
td.create_pacticipant("Some Consumer", repository_name: "existing")
end

subject { patch(path, request_body.to_json, {'CONTENT_TYPE' => 'application/merge-patch+json' }) }

it "returns a 200 OK" do
puts subject.body unless subject.status == 200
expect(subject.status).to be 200
end

it "leaves any existing properties that were not defined" do
expect(response_body_hash[:repositoryName]).to eq "existing"
end

it "returns a json body with the updated pacticipant" do
expect(subject.headers['Content-Type']).to eq "application/hal+json;charset=utf-8"
end
end
end
end

0 comments on commit 404e14c

Please sign in to comment.