Skip to content

Commit

Permalink
Fix/no method for pacticipant patch (#704)
Browse files Browse the repository at this point in the history
* test: update pacticipant with embedded labels

* fix: added writeable false to pacticipant labels

* test: ensuring labels collection is not modified
  • Loading branch information
prateek0411999 authored Jul 11, 2024
1 parent ff3f84e commit cb9c668
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/pact_broker/api/decorators/pacticipant_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class PacticipantDecorator < BaseDecorator
property :main_branch

property :latest_version, as: :latestVersion, :class => PactBroker::Domain::Version, extend: PactBroker::Api::Decorators::EmbeddedVersionDecorator, embedded: true, writeable: false
collection :labels, :class => PactBroker::Domain::Label, extend: PactBroker::Api::Decorators::EmbeddedLabelDecorator, embedded: true
collection :labels, :class => PactBroker::Domain::Label, extend: PactBroker::Api::Decorators::EmbeddedLabelDecorator, embedded: true, writeable: false

include Timestamps

Expand Down
29 changes: 29 additions & 0 deletions spec/features/update_pacticipant_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,35 @@
it "returns a json body with the updated pacticipant" do
expect(subject.headers["Content-Type"]).to eq "application/hal+json;charset=utf-8"
end

context "when request body contains embedded labels" do
context "when labels has values" do
let(:request_body) { { "displayName": "Updated Consumer Name", "_embedded": { "labels": [{ "name": "ios" }, { "name": "consumer" }] } } }

it "returns a 200 response" do
expect(subject.status).to be 200
end

it "should not create the labels for the pacticipant" do
expect(response_body_hash[:_embedded][:labels]).to be_empty
end

it "only updates pacticipant attribute ignoring the labels" do
expect(response_body_hash[:displayName]).to eq "Updated Consumer Name"
expect{ subject }.to change {
PactBroker::Domain::Label.where(name: "ios").count
}.by(0)
end
end

context "when labels is empty" do
let(:request_body) {{"displayName": "Updated Consumer Name", "_embedded": { "labels": []}}}

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

context "with application/merge-patch+json" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,26 @@ module Decorators
end

describe "from_json" do
let(:pacticipant) { OpenStruct.new }
let(:pacticipant) { OpenStruct.new(labels: [OpenStruct.new(name: "existing_label")]) }
let(:decorator) { PacticipantDecorator.new(pacticipant) }
let(:hash) do
{
name: "Foo",
mainBranch: "main"
mainBranch: "main",
labels: [
{name: "new_label"}
]
}
end

subject { decorator.from_json(hash.to_json) }

its(:name) { is_expected.to eq "Foo" }
its(:main_branch) { is_expected.to eq "main" }

it "does not modify the labels collection" do
expect(subject.labels.map(&:name)).to contain_exactly("existing_label")
end
end

describe "to_json" do
Expand Down

0 comments on commit cb9c668

Please sign in to comment.