forked from pact-foundation/pact_broker
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add resource to get latest verification for a pact
- Loading branch information
Showing
12 changed files
with
116 additions
and
4 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
16 changes: 16 additions & 0 deletions
16
lib/pact_broker/api/decorators/extended_verification_decorator.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,16 @@ | ||
require 'pact_broker/api/decorators/verification_decorator' | ||
|
||
module PactBroker | ||
module Api | ||
module Decorators | ||
class ExtendedVerificationDecorator < VerificationDecorator | ||
class TagDecorator < BaseDecorator | ||
property :name | ||
property :latest?, as: :latest | ||
end | ||
|
||
collection :provider_version_tags, as: :tags, embedded: true, extend: TagDecorator | ||
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
19 changes: 19 additions & 0 deletions
19
lib/pact_broker/api/resources/latest_verification_for_pact.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,19 @@ | ||
require 'pact_broker/api/resources/verification' | ||
|
||
module PactBroker | ||
module Api | ||
module Resources | ||
class LatestVerificationForPact < Verification | ||
private | ||
|
||
def pact | ||
@pact ||= pact_service.find_pact(pact_params) | ||
end | ||
|
||
def verification | ||
@verification ||= pact && verification_service.find_latest_for_pact(pact) | ||
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
require 'spec/support/test_data_builder' | ||
|
||
describe "Get latest verification for pact" do | ||
before do | ||
td | ||
.create_consumer("Consumer") | ||
.create_consumer_version("1.2.3") | ||
.create_provider("Another provider") | ||
.create_pact | ||
.create_verification(number: 1, provider_version: "5") | ||
.create_provider("Provider") | ||
.create_pact | ||
.create_verification(number: 1, provider_version: "3") | ||
.create_verification(number: 2, provider_version: "4") | ||
end | ||
|
||
let(:last_response_body) { JSON.parse(subject.body, symbolize_names: true) } | ||
let(:content_type) { "application/vnd.pactbrokerextended.v1+json" } | ||
|
||
subject { get(path, nil, "HTTP_ACCEPT" => content_type) } | ||
|
||
context "by pact version" do | ||
let!(:path) { "/pacts/provider/Provider/consumer/Consumer/pact-version/#{td.pact.pact_version_sha}/verification-results/latest" } | ||
|
||
it "returns a 200 OK" do | ||
expect(subject.status).to eq 200 | ||
expect(subject.headers['Content-Type']).to include content_type | ||
end | ||
|
||
it "returns the verification" do | ||
expect(last_response_body[:providerApplicationVersion]).to eq "4" | ||
end | ||
end | ||
|
||
context "by consumer version" do | ||
let(:path) { "/pacts/provider/Provider/consumer/Consumer/version/1.2.3/verification-results/latest" } | ||
|
||
it "returns the verification" do | ||
expect(last_response_body[:providerApplicationVersion]).to eq "4" | ||
end | ||
end | ||
end |