Skip to content

Commit

Permalink
feat: add tags to verification resource
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Aug 26, 2019
1 parent 7666863 commit 830632a
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 5 deletions.
3 changes: 3 additions & 0 deletions lib/pact_broker/api/decorators/extended_pact_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
module PactBroker
module Api
module Decorators
# Make a different content type for adding extra information for the UI, as
# some pact parsing tools blow up when there are unexpected keys :|

class ExtendedPactDecorator < PactDecorator
class TagDecorator < BaseDecorator
property :name
Expand Down
5 changes: 5 additions & 0 deletions lib/pact_broker/api/decorators/verification_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@ module PactBroker
module Api
module Decorators
class VerificationDecorator < BaseDecorator
class TagDecorator < BaseDecorator
property :name
property :latest?, as: :latest
end

property :provider_name, as: :providerName, writeable: false
property :provider_version_number, as: :providerApplicationVersion, writeable: false
property :success
property :execution_date, as: :verificationDate
property :build_url, as: :buildUrl
property :test_results, as: :testResults
collection :provider_version_tags, as: :tags, embedded: true, extend: TagDecorator

link :self do | options |
{
Expand Down
2 changes: 1 addition & 1 deletion lib/pact_broker/api/resources/pact.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def content_types_provided
[["application/hal+json", :to_json],
["application/json", :to_json],
["text/html", :to_html],
["application/vnd.pactbroker.pact.v1+json", :to_extended_json]
["application/vnd.pactbroker.v1+json", :to_extended_json]
]
end

Expand Down
8 changes: 5 additions & 3 deletions lib/pact_broker/domain/verification.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
require 'pact_broker/db'
require 'pact_broker/repositories/helpers'
require 'json'
require 'sequel'
require 'pact_broker/repositories/helpers'
require 'pact_broker/tags/tag_with_latest_flag'

module PactBroker

module PactBroker
module Domain
class Verification < Sequel::Model

Expand All @@ -12,6 +13,7 @@ class Verification < Sequel::Model
associate(:many_to_one, :provider_version, class: "PactBroker::Domain::Version", key: :provider_version_id, primary_key: :id)
associate(:many_to_one, :provider, class: "PactBroker::Domain::Pacticipant", key: :provider_id, primary_key: :id)
associate(:many_to_one, :consumer, class: "PactBroker::Domain::Pacticipant", key: :consumer_id, primary_key: :id)
associate(:one_to_many, :provider_version_tags, :class => "PactBroker::Tags::TagWithLatestFlag", primary_key: :provider_version_id, key: :version_id)
plugin :serialization, :json, :test_results

def before_create
Expand Down
2 changes: 2 additions & 0 deletions lib/pact_broker/pacts/pact_publication.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ def before_create
self.revision_number ||= 1
end

# The names of the tags for which this pact is the latest pact with that tag
# (ie. it is not necessarily the pact for the latest consumer version with the given tag)
def head_tag_names
LatestTaggedPactPublications.where(id: id).select(:tag_name).collect{|t| t[:tag_name]}
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ module Decorators
build_url: 'http://build-url',
pact_version_sha: '1234',
latest_pact_publication: pact_publication,
execution_date: DateTime.now)
execution_date: DateTime.now,
provider_version_tags: provider_version_tags)
end

let(:pact_publication) do
Expand All @@ -31,6 +32,8 @@ module Decorators
)
end

let(:provider_version_tags) { [instance_double(PactBroker::Tags::TagWithLatestFlag, name: 'prod', latest?: true)] }

let(:options) { { user_options: { base_url: 'http://example.org' } } }

let(:json) { VerificationDecorator.new(verification).to_json(options) }
Expand Down Expand Up @@ -64,6 +67,10 @@ module Decorators
it "includes a link to the triggered webhooks" do
expect(subject[:_links][:'pb:triggered-webhooks'][:href]).to eq "http://triggered-webhooks"
end

it "includes the provider version tags" do
expect(subject[:_embedded][:tags].first).to eq name: 'prod', latest: true
end
end
end
end
Expand Down

0 comments on commit 830632a

Please sign in to comment.