Skip to content

Commit

Permalink
feat(dashboard): use 'refreshable' link for latest verification resul…
Browse files Browse the repository at this point in the history
…t so pact can be refreshed and display the latest result
  • Loading branch information
bethesque committed Sep 8, 2019
1 parent 0ec26e8 commit 1ab8a5d
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 9 deletions.
4 changes: 3 additions & 1 deletion lib/pact_broker/api/decorators/dashboard_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,15 @@ def pact_hash(index_item, base_url)
end

def verification_hash(index_item, base_url)
# Use the 'latest pact' URL instead of the permalink URL so that the page can be
# refreshed, and the latest verification result will be updated to the most recent
if index_item.latest_verification
{
success: index_item.latest_verification.success,
verifiedAt: format_date_time(index_item.latest_verification.created_at),
_links: {
self: {
href: verification_url(index_item.latest_verification, base_url)
href: latest_verification_for_pact_url(index_item.latest_pact, base_url, false)
}
}
}
Expand Down
44 changes: 38 additions & 6 deletions lib/pact_broker/api/pact_broker_urls.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,20 @@ def latest_verifications_for_consumer_version_url version, base_url
"#{base_url}/verification-results/consumer/#{url_encode(version.pacticipant.name)}/version/#{version.number}/latest"
end

def latest_verification_for_pact_url pact, base_url
verification_url_from_params(
provider_name: pact.provider_name,
consumer_name: pact.consumer_name,
pact_version_sha: pact.pact_version_sha,
verification_number: 'latest')
def latest_verification_for_pact_url pact, base_url, permalink = true
if permalink
verification_url_from_params(
{
provider_name: provider_name(pact),
consumer_name: consumer_name(pact),
pact_version_sha: pact.pact_version_sha,
verification_number: 'latest'
},
base_url
)
else
pact_url(base_url, pact) + "/verification-results/latest"
end
end

def verification_triggered_webhooks_url verification, base_url = ''
Expand Down Expand Up @@ -276,6 +284,30 @@ def pactigration_base_url_from_params base_url, params
'consumer', url_encode(params[:consumer_name])
].join('/')
end

def consumer_name(thing)
if thing.respond_to?(:consumer_name)
thing.consumer_name
elsif thing.respond_to?(:consumer)
thing.consumer.name
elsif thing.respond_to?(:[])
thing[:consumer_name]
else
nil
end
end

def provider_name(thing)
if thing.respond_to?(:provider_name)
thing.provider_name
elsif thing.respond_to?(:provider)
thing.provider.name
elsif thing.respond_to?(:[])
thing[:provider_name]
else
nil
end
end
end
end
end
2 changes: 1 addition & 1 deletion spec/fixtures/dashboard.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"latestVerificationResult": {
"_links": {
"self": {
"href": "verification_url"
"href": "latest_verification_url"
}
},
"success": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def in_utc

before do
allow_any_instance_of(DashboardDecorator).to receive(:pact_url).with(base_url, pact).and_return('pact_url')
allow_any_instance_of(DashboardDecorator).to receive(:verification_url).with(verification, base_url).and_return('verification_url')
allow_any_instance_of(DashboardDecorator).to receive(:latest_verification_for_pact_url).with(pact, base_url, false).and_return('latest_verification_url')
allow_any_instance_of(DashboardDecorator).to receive(:pacticipant_url).with(base_url, consumer).and_return('consumer_url')
allow_any_instance_of(DashboardDecorator).to receive(:pacticipant_url).with(base_url, provider).and_return('provider_url')
allow_any_instance_of(DashboardDecorator).to receive(:version_url).with(base_url, consumer_version).and_return('consumer_version_url')
Expand Down
14 changes: 14 additions & 0 deletions spec/lib/pact_broker/api/pact_broker_urls_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,20 @@ module Api
end
end
end

describe "latest_verification_for_pact_url" do
context "when permalink = true" do
subject { PactBrokerUrls.latest_verification_for_pact_url(pact, base_url, true) }

it { is_expected.to eq "http://example.org/pacts/provider/Bar%2FBar/consumer/Foo%2FFoo/pact-version/5hbfu/verification-results/latest" }
end

context "when permalink = false" do
subject { PactBrokerUrls.latest_verification_for_pact_url(pact, base_url, false) }

it { is_expected.to eq "http://example.org/pacts/provider/Bar%2FBar/consumer/Foo%2FFoo/version/123%2F456/verification-results/latest" }
end
end
end
end
end

0 comments on commit 1ab8a5d

Please sign in to comment.