-
-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: use the consumer version number in the metadata to select the c…
…orrect consumer version for a pact version resource Fixes: pact-foundation/pact-jvm#1249
- Loading branch information
Showing
11 changed files
with
160 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
lib/pact_broker/api/resources/metadata_resource_methods.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
require 'pact_broker/hash_refinements' | ||
|
||
module PactBroker | ||
module Api | ||
module Resources | ||
module MetadataResourceMethods | ||
using PactBroker::HashRefinements | ||
|
||
def pact_params | ||
@pact_params ||= PactBroker::Pacts::PactParams.from_request(request, maybe_params_with_consumer_version_number.merge(path_info)) | ||
end | ||
|
||
def maybe_params_with_consumer_version_number | ||
metadata.slice(:consumer_version_number) | ||
end | ||
|
||
def metadata | ||
@metadata ||= PactBrokerUrls.decode_pact_metadata(identifier_from_path[:metadata]) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,36 @@ | ||
describe "retrieving a pact" do | ||
subject { get path; last_response } | ||
RSpec.describe "retrieving a pact" do | ||
subject { get(path) } | ||
|
||
context "when differing case is used in the consumer and provider names" do | ||
let(:td) { TestDataBuilder.new } | ||
let(:pact) { td.create_pact_with_hierarchy("Foo", "1", "Bar").and_return(:pact) } | ||
let!(:path) { "/pacts/provider/Bar/consumer/Foo/pact-version/#{pact.pact_version_sha}" } | ||
|
||
it "returns a 200 Success" do | ||
expect(subject.status).to be 200 | ||
end | ||
end | ||
|
||
context "when there are multiple consumer versions for the same sha" do | ||
before do | ||
td.create_pact_with_hierarchy("Foo", "1", "Bar") | ||
.create_consumer_version("2") | ||
.republish_same_pact | ||
end | ||
|
||
let(:pact) { PactBroker::Pacts::PactPublication.order(:id).first.to_domain } | ||
let(:path) { PactBroker::Api::PactBrokerUrls.pact_version_url(pact) } | ||
|
||
it "returns the latest" do | ||
expect(JSON.parse(subject.body)['_links']['pb:consumer-version']['name']).to eq "2" | ||
end | ||
|
||
context "when there is metadata specifying the consumer version number" do | ||
let(:pact) { PactBroker::Pacts::PactPublication.order(:id).first.to_domain } | ||
let(:path) { PactBroker::Api::PactBrokerUrls.pact_version_url_with_webhook_metadata(pact) } | ||
|
||
it "returns the pact with the matching consumer version number" do | ||
expect(JSON.parse(subject.body)['_links']['pb:consumer-version']['name']).to eq "1" | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters