diff --git a/lib/pact_broker/api.rb b/lib/pact_broker/api.rb index 3d35b0c71..c2f0bafa2 100644 --- a/lib/pact_broker/api.rb +++ b/lib/pact_broker/api.rb @@ -30,6 +30,8 @@ module PactBroker add ['pacts', 'provider', :provider_name, 'consumer', :consumer_name, 'pact-version', :pact_version_sha, 'verification-results', 'latest'], Api::Resources::LatestVerificationForPact, {resource_name: "latest_verification_results_for_pact_version"} add ['pacts', 'provider', :provider_name, 'consumer', :consumer_name, 'pact-version', :pact_version_sha, 'verification-results', :verification_number], Api::Resources::Verification, {resource_name: "verification_result"} add ['pacts', 'provider', :provider_name, 'consumer', :consumer_name, 'pact-version', :pact_version_sha, 'verification-results', :verification_number, 'triggered-webhooks'], Api::Resources::VerificationTriggeredWebhooks, {resource_name: "verification_result_triggered_webhooks"} + add ['pacts', 'provider', :provider_name, 'consumer', :consumer_name, 'latest', 'verification-results','latest'], Api::Resources::LatestVerificationForLatestPact, {resource_name: "latest_verification_results_for_latest_pact_publication"} + add ['pacts', 'provider', :provider_name, 'consumer', :consumer_name, 'latest', :tag, 'verification-results','latest'], Api::Resources::LatestVerificationForLatestPact, {resource_name: "latest_verification_results_for_latest_tagged_pact_publication"} add ['verification-results', 'consumer', :consumer_name, 'version', :consumer_version_number,'latest'], Api::Resources::LatestVerificationsForConsumerVersion, {resource_name: "verification_results_for_consumer_version"} # Badges diff --git a/lib/pact_broker/api/resources/latest_verification_for_latest_pact.rb b/lib/pact_broker/api/resources/latest_verification_for_latest_pact.rb new file mode 100644 index 000000000..02bab4908 --- /dev/null +++ b/lib/pact_broker/api/resources/latest_verification_for_latest_pact.rb @@ -0,0 +1,19 @@ +require 'pact_broker/api/resources/verification' + +module PactBroker + module Api + module Resources + class LatestVerificationForLatestPact < Verification + private + + def pact + @pact ||= pact_service.find_latest_pact(pact_params) + end + + def verification + @verification ||= pact && verification_service.find_latest_for_pact(pact) + end + end + end + end +end diff --git a/spec/features/get_latest_verification_for_pact_spec.rb b/spec/features/get_latest_verification_for_pact_spec.rb index cd3705db0..c1a1f9b4a 100644 --- a/spec/features/get_latest_verification_for_pact_spec.rb +++ b/spec/features/get_latest_verification_for_pact_spec.rb @@ -5,6 +5,7 @@ td .create_consumer("Consumer") .create_consumer_version("1.2.3") + .create_consumer_version_tag("master") .create_provider("Another provider") .create_pact .create_verification(number: 1, provider_version: "5") @@ -39,4 +40,20 @@ expect(last_response_body[:providerApplicationVersion]).to eq "4" end end + + context "for latest pact" do + let(:path) { "/pacts/provider/Provider/consumer/Consumer/latest/verification-results/latest" } + + it "returns the verification" do + expect(last_response_body[:providerApplicationVersion]).to eq "4" + end + end + + context "for latest pact for tag" do + let(:path) { "/pacts/provider/Provider/consumer/Consumer/latest/master/verification-results/latest" } + + it "returns the verification" do + expect(last_response_body[:providerApplicationVersion]).to eq "4" + end + end end