Skip to content

Commit

Permalink
fix: add endpoints to get latest verification for latest pact
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Sep 30, 2019
1 parent 476ff59 commit 7341372
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/pact_broker/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
17 changes: 17 additions & 0 deletions spec/features/get_latest_verification_for_pact_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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

0 comments on commit 7341372

Please sign in to comment.