Skip to content

Commit 437ba76

Browse files
committed
feat(integrations): add verification status to integrations endpoint
1 parent a057427 commit 437ba76

File tree

9 files changed

+46
-8
lines changed

9 files changed

+46
-8
lines changed

lib/pact_broker/api/decorators/integration_decorator.rb

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ class IntegrationDecorator < BaseDecorator
1515
property :name
1616
end
1717

18+
property :verificationStatus, getter: ->(represented:, **) { represented.verification_status_for_latest_pact.to_s }
19+
1820
link "pb:dashboard" do | options |
1921
{
2022
title: "BETA: Pacts to show on the dashboard",

lib/pact_broker/doc/views/integrations.markdown

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
Allowed methods: `GET`
44

5-
Content types: `text/vnd.graphviz`
5+
Content types: `text/vnd.graphviz`, `application/hal+json`
66

77
A list of all the integrations (consumer/provider pairs) stored in the Pact Broker.

lib/pact_broker/index/service.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def self.find_index_items options = {}
4040
rows.sort.collect do | row |
4141
# The concept of "stale" (the pact used to be verified but then it changed and we haven't got
4242
# a new verification result yet) only really make sense if we're trying to summarise
43-
# the latest state of an integration. Once we start showing multiple pacts for each
43+
# the state of an integration. Once we start showing multiple pacts for each
4444
# integration (ie. the latest for each tag) then each pact version is either verified,
4545
# or it's not verified.
4646
# For backwards compatiblity with the existing UI, don't change the 'stale' concept for the OSS

lib/pact_broker/integrations/integration.rb

+6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
require 'pact_broker/db'
2+
require 'pact_broker/verifications/verification_status'
23

34
module PactBroker
45
module Integrations
56
class Integration < Sequel::Model
67
associate(:many_to_one, :consumer, :class => "PactBroker::Domain::Pacticipant", :key => :consumer_id, :primary_key => :id)
78
associate(:many_to_one, :provider, :class => "PactBroker::Domain::Pacticipant", :key => :provider_id, :primary_key => :id)
9+
associate(:one_to_one, :latest_pact, :class => "PactBroker::Pacts::LatestPactPublications", key: [:consumer_id, :provider_id], primary_key: [:consumer_id, :provider_id])
10+
11+
def verification_status_for_latest_pact
12+
@verification_status_for_latest_pact ||= PactBroker::Verifications::Status.new(latest_pact, latest_pact&.latest_verification)
13+
end
814
end
915
end
1016
end

lib/pact_broker/integrations/service.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class Service
1111
include PactBroker::Logging
1212

1313
def self.find_all
14-
PactBroker::Integrations::Integration.eager(:consumer).eager(:provider).all
14+
PactBroker::Integrations::Integration.eager(:consumer).eager(:provider).eager(latest_pact: :latest_verification).all
1515
end
1616

1717
def self.delete(consumer_name, provider_name)

lib/pact_broker/pacts/all_pact_publications.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
module PactBroker
88
module Pacts
9-
109
class AllPactPublications < Sequel::Model(:all_pact_publications)
1110

1211
extend Forwardable
@@ -16,6 +15,7 @@ class AllPactPublications < Sequel::Model(:all_pact_publications)
1615
set_primary_key :id
1716
associate(:one_to_many, :tags, :class => "PactBroker::Domain::Tag", :reciprocal => :version, :key => :version_id, :primary_key => :consumer_version_id)
1817
associate(:many_to_one, :pact_version, :key => :pact_version_id, :primary_key => :id)
18+
associate(:many_to_one, :latest_verification, :class => "PactBroker::Verifications::LatestVerificationForPactVersion", key: :pact_version_id, primary_key: :pact_version_id)
1919

2020
dataset_module do
2121
include PactBroker::Repositories::Helpers

lib/pact_broker/verifications/verification_status.rb

-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
module PactBroker
2-
32
module Verifications
4-
53
class Status
6-
74
def initialize latest_pact, latest_verification
85
@latest_pact = latest_pact
96
@latest_verification = latest_verification

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

+5-1
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,14 @@ module Decorators
1414
let(:integration) do
1515
instance_double(PactBroker::Integrations::Integration,
1616
consumer: consumer,
17-
provider: provider
17+
provider: provider,
18+
verification_status_for_latest_pact: verification_status
1819
)
1920
end
2021
let(:consumer) { double("consumer", name: "the consumer") }
2122
let(:provider) { double("provider", name: "the provider") }
23+
let(:verification_status) { double("verification_status", to_s: "some_status") }
24+
2225
let(:options) { { user_options: { base_url: 'http://example.org' } } }
2326
let(:expected_hash) do
2427
{
@@ -28,6 +31,7 @@ module Decorators
2831
"provider" => {
2932
"name" => "the provider"
3033
},
34+
"verificationStatus" => "some_status",
3135
"_links" => {
3236
"pb:dashboard" => {
3337
"href" => "/dashboard"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
require 'pact_broker/integrations/integration'
2+
3+
module PactBroker
4+
module Integrations
5+
describe Integration do
6+
before do
7+
td.create_pact_with_hierarchy("Foo", "1", "Bar")
8+
.create_consumer_version("2")
9+
.create_pact
10+
.create_verification(provider_version: "3")
11+
.create_verification(provider_version: "4", number: 2)
12+
end
13+
14+
it "has a relationship to the latest pact" do
15+
integration = Integration.eager(:latest_pact).all.first
16+
expect(integration.latest_pact.consumer_version_number).to eq "2"
17+
end
18+
19+
it "has a relationship to the latest verification via the latest pact" do
20+
integration = Integration.eager(latest_pact: :latest_verification).all.first
21+
expect(integration.latest_pact.latest_verification.provider_version_number).to eq "4"
22+
end
23+
24+
it "has a verification status" do
25+
expect(Integration.first.verification_status_for_latest_pact).to be_instance_of(PactBroker::Verifications::Status)
26+
end
27+
end
28+
end
29+
end

0 commit comments

Comments
 (0)