Skip to content

Commit

Permalink
feat: remove use of 'stale' for dashboard resource
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Aug 25, 2019
1 parent 6e67d3a commit e173f5c
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 8 deletions.
4 changes: 1 addition & 3 deletions lib/pact_broker/api/resources/dashboard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
module PactBroker
module Api
module Resources

class Dashboard < BaseResource

def content_types_provided
[
["application/hal+json", :to_json],
Expand All @@ -30,7 +28,7 @@ def to_text
private

def index_items
index_service.find_index_items(identifier_from_path.merge(tags: true))
index_service.find_index_items(identifier_from_path.merge(tags: true, dashboard: true))
end
end
end
Expand Down
17 changes: 16 additions & 1 deletion lib/pact_broker/index/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,29 @@ def self.find_index_items options = {}
end
rows = rows.all.group_by(&:pact_publication_id).values.collect{ | rows| Matrix::AggregatedRow.new(rows) }



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
# 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
# UI - just ensure we don't use it for the new dashboard endpoint with the consumer/provider specified.
latest_verification = if options[:dashboard]
row.latest_verification_for_pact_version
else
row.latest_verification_for_pseudo_branch
end

# TODO simplify. Do we really need 3 layers of abstraction?
PactBroker::Domain::IndexItem.create(
row.consumer,
row.provider,
row.pact,
row.overall_latest?,
row.latest_verification_for_pseudo_branch,
latest_verification,
row.webhooks,
row.latest_triggered_webhooks,
options[:tags] ? row.consumer_head_tag_names : [],
Expand Down
8 changes: 8 additions & 0 deletions lib/pact_broker/matrix/aggregated_row.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ def latest_verification_for_pseudo_branch
end
end

def latest_verification_for_pact_version
@latest_verificaton_for_pact_version ||= begin
matrix_rows.collect do | row|
row.verification
end.compact.sort{ |v1, v2| v1.id <=> v2.id }.last
end
end

# The list of tag names for which this pact publication is the most recent with that tag
# There could, however, be a later consumer version that does't have a pact (perhaps because it was deleted)
# that has the same tag.
Expand Down
33 changes: 29 additions & 4 deletions spec/lib/pact_broker/index/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,35 @@ module Index

let(:options) { { tags: true } }

it "returns the latest of the feat-x and feat-y verifications" do
expect(rows.last.consumer_version_number).to eq "3"
expect(rows.last.tag_names.sort).to eq ["feat-x", "feat-y"]
expect(rows.last.provider_version_number).to eq "2"
context "with tags=true" do
it "returns the tags for the pacts" do
expect(rows.last.tag_names.sort).to eq ["feat-x", "feat-y"]
end
end

context "with tags=false" do
let(:options) { { tags: false } }

it "does not return the tags for the pacts" do
expect(rows.last.tag_names.sort).to eq []
end
end

context "with dashboard=true" do
let(:options) { { dashboard: true } }

it "returns the latest verification as nil as the pact version itself has not been verified" do
expect(rows.last.provider_version_number).to be nil
end
end

context "with dashboard=false" do
let(:options) { { } }

it "returns the latest of the feat-x and feat-y verifications because we are summarising the entire integration (backwards compat for OSS index)" do
expect(rows.last.consumer_version_number).to eq "4"
expect(rows.last.provider_version_number).to eq "2"
end
end
end
end
Expand Down
21 changes: 21 additions & 0 deletions spec/lib/pact_broker/matrix/aggregated_row_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,27 @@ module Matrix
end
end
end

describe "latest_verification_for_pact_version" do
let(:row_1) do
instance_double('PactBroker::Matrix::HeadRow',
verification: verification_1)
end
let(:row_2) do
instance_double('PactBroker::Matrix::HeadRow',
verification: verification_2)
end
let(:verification_1) { instance_double('PactBroker::Domain::Verification', id: 2) }
let(:verification_2) { instance_double('PactBroker::Domain::Verification', id: 1) }
let(:rows) { [row_1, row_2] }
let(:aggregated_row) { AggregatedRow.new(rows) }

subject { aggregated_row.latest_verification_for_pact_version }

it "returns the verification with the largest id" do
expect(subject.id).to eq 2
end
end
end
end
end

0 comments on commit e173f5c

Please sign in to comment.