Skip to content

Commit 830632a

Browse files
committed
feat: add tags to verification resource
1 parent 7666863 commit 830632a

File tree

6 files changed

+24
-5
lines changed

6 files changed

+24
-5
lines changed

lib/pact_broker/api/decorators/extended_pact_decorator.rb

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
module PactBroker
44
module Api
55
module Decorators
6+
# Make a different content type for adding extra information for the UI, as
7+
# some pact parsing tools blow up when there are unexpected keys :|
8+
69
class ExtendedPactDecorator < PactDecorator
710
class TagDecorator < BaseDecorator
811
property :name

lib/pact_broker/api/decorators/verification_decorator.rb

+5
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,18 @@ module PactBroker
44
module Api
55
module Decorators
66
class VerificationDecorator < BaseDecorator
7+
class TagDecorator < BaseDecorator
8+
property :name
9+
property :latest?, as: :latest
10+
end
711

812
property :provider_name, as: :providerName, writeable: false
913
property :provider_version_number, as: :providerApplicationVersion, writeable: false
1014
property :success
1115
property :execution_date, as: :verificationDate
1216
property :build_url, as: :buildUrl
1317
property :test_results, as: :testResults
18+
collection :provider_version_tags, as: :tags, embedded: true, extend: TagDecorator
1419

1520
link :self do | options |
1621
{

lib/pact_broker/api/resources/pact.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def content_types_provided
2828
[["application/hal+json", :to_json],
2929
["application/json", :to_json],
3030
["text/html", :to_html],
31-
["application/vnd.pactbroker.pact.v1+json", :to_extended_json]
31+
["application/vnd.pactbroker.v1+json", :to_extended_json]
3232
]
3333
end
3434

lib/pact_broker/domain/verification.rb

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
require 'pact_broker/db'
2-
require 'pact_broker/repositories/helpers'
31
require 'json'
2+
require 'sequel'
3+
require 'pact_broker/repositories/helpers'
4+
require 'pact_broker/tags/tag_with_latest_flag'
45

5-
module PactBroker
66

7+
module PactBroker
78
module Domain
89
class Verification < Sequel::Model
910

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

1719
def before_create

lib/pact_broker/pacts/pact_publication.rb

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ def before_create
3131
self.revision_number ||= 1
3232
end
3333

34+
# The names of the tags for which this pact is the latest pact with that tag
35+
# (ie. it is not necessarily the pact for the latest consumer version with the given tag)
3436
def head_tag_names
3537
LatestTaggedPactPublications.where(id: id).select(:tag_name).collect{|t| t[:tag_name]}
3638
end

spec/lib/pact_broker/api/decorators/verification_decorator_spec.rb

+8-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ module Decorators
1919
build_url: 'http://build-url',
2020
pact_version_sha: '1234',
2121
latest_pact_publication: pact_publication,
22-
execution_date: DateTime.now)
22+
execution_date: DateTime.now,
23+
provider_version_tags: provider_version_tags)
2324
end
2425

2526
let(:pact_publication) do
@@ -31,6 +32,8 @@ module Decorators
3132
)
3233
end
3334

35+
let(:provider_version_tags) { [instance_double(PactBroker::Tags::TagWithLatestFlag, name: 'prod', latest?: true)] }
36+
3437
let(:options) { { user_options: { base_url: 'http://example.org' } } }
3538

3639
let(:json) { VerificationDecorator.new(verification).to_json(options) }
@@ -64,6 +67,10 @@ module Decorators
6467
it "includes a link to the triggered webhooks" do
6568
expect(subject[:_links][:'pb:triggered-webhooks'][:href]).to eq "http://triggered-webhooks"
6669
end
70+
71+
it "includes the provider version tags" do
72+
expect(subject[:_embedded][:tags].first).to eq name: 'prod', latest: true
73+
end
6774
end
6875
end
6976
end

0 commit comments

Comments
 (0)