Skip to content

Commit

Permalink
feat(integrations): add verification status to integrations endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Oct 4, 2019
1 parent a057427 commit 437ba76
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 8 deletions.
2 changes: 2 additions & 0 deletions lib/pact_broker/api/decorators/integration_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class IntegrationDecorator < BaseDecorator
property :name
end

property :verificationStatus, getter: ->(represented:, **) { represented.verification_status_for_latest_pact.to_s }

link "pb:dashboard" do | options |
{
title: "BETA: Pacts to show on the dashboard",
Expand Down
2 changes: 1 addition & 1 deletion lib/pact_broker/doc/views/integrations.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

Allowed methods: `GET`

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

A list of all the integrations (consumer/provider pairs) stored in the Pact Broker.
2 changes: 1 addition & 1 deletion lib/pact_broker/index/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def self.find_index_items options = {}
rows.sort.collect do | row |
# The concept of "stale" (the pact used to be verified but then it changed and we haven't got
# a new verification result yet) only really make sense if we're trying to summarise
# the latest state of an integration. Once we start showing multiple pacts for each
# the state of an integration. Once we start showing multiple pacts for each
# integration (ie. the latest for each tag) then each pact version is either verified,
# or it's not verified.
# For backwards compatiblity with the existing UI, don't change the 'stale' concept for the OSS
Expand Down
6 changes: 6 additions & 0 deletions lib/pact_broker/integrations/integration.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
require 'pact_broker/db'
require 'pact_broker/verifications/verification_status'

module PactBroker
module Integrations
class Integration < Sequel::Model
associate(:many_to_one, :consumer, :class => "PactBroker::Domain::Pacticipant", :key => :consumer_id, :primary_key => :id)
associate(:many_to_one, :provider, :class => "PactBroker::Domain::Pacticipant", :key => :provider_id, :primary_key => :id)
associate(:one_to_one, :latest_pact, :class => "PactBroker::Pacts::LatestPactPublications", key: [:consumer_id, :provider_id], primary_key: [:consumer_id, :provider_id])

def verification_status_for_latest_pact
@verification_status_for_latest_pact ||= PactBroker::Verifications::Status.new(latest_pact, latest_pact&.latest_verification)
end
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/pact_broker/integrations/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Service
include PactBroker::Logging

def self.find_all
PactBroker::Integrations::Integration.eager(:consumer).eager(:provider).all
PactBroker::Integrations::Integration.eager(:consumer).eager(:provider).eager(latest_pact: :latest_verification).all
end

def self.delete(consumer_name, provider_name)
Expand Down
2 changes: 1 addition & 1 deletion lib/pact_broker/pacts/all_pact_publications.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

module PactBroker
module Pacts

class AllPactPublications < Sequel::Model(:all_pact_publications)

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

dataset_module do
include PactBroker::Repositories::Helpers
Expand Down
3 changes: 0 additions & 3 deletions lib/pact_broker/verifications/verification_status.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
module PactBroker

module Verifications

class Status

def initialize latest_pact, latest_verification
@latest_pact = latest_pact
@latest_verification = latest_verification
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@ module Decorators
let(:integration) do
instance_double(PactBroker::Integrations::Integration,
consumer: consumer,
provider: provider
provider: provider,
verification_status_for_latest_pact: verification_status
)
end
let(:consumer) { double("consumer", name: "the consumer") }
let(:provider) { double("provider", name: "the provider") }
let(:verification_status) { double("verification_status", to_s: "some_status") }

let(:options) { { user_options: { base_url: 'http://example.org' } } }
let(:expected_hash) do
{
Expand All @@ -28,6 +31,7 @@ module Decorators
"provider" => {
"name" => "the provider"
},
"verificationStatus" => "some_status",
"_links" => {
"pb:dashboard" => {
"href" => "/dashboard"
Expand Down
29 changes: 29 additions & 0 deletions spec/lib/pact_broker/integrations/integration_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require 'pact_broker/integrations/integration'

module PactBroker
module Integrations
describe Integration do
before do
td.create_pact_with_hierarchy("Foo", "1", "Bar")
.create_consumer_version("2")
.create_pact
.create_verification(provider_version: "3")
.create_verification(provider_version: "4", number: 2)
end

it "has a relationship to the latest pact" do
integration = Integration.eager(:latest_pact).all.first
expect(integration.latest_pact.consumer_version_number).to eq "2"
end

it "has a relationship to the latest verification via the latest pact" do
integration = Integration.eager(latest_pact: :latest_verification).all.first
expect(integration.latest_pact.latest_verification.provider_version_number).to eq "4"
end

it "has a verification status" do
expect(Integration.first.verification_status_for_latest_pact).to be_instance_of(PactBroker::Verifications::Status)
end
end
end
end

0 comments on commit 437ba76

Please sign in to comment.