Skip to content

Commit 1ab8a5d

Browse files
committed
feat(dashboard): use 'refreshable' link for latest verification result so pact can be refreshed and display the latest result
1 parent 0ec26e8 commit 1ab8a5d

File tree

5 files changed

+57
-9
lines changed

5 files changed

+57
-9
lines changed

lib/pact_broker/api/decorators/dashboard_decorator.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,15 @@ def pact_hash(index_item, base_url)
102102
end
103103

104104
def verification_hash(index_item, base_url)
105+
# Use the 'latest pact' URL instead of the permalink URL so that the page can be
106+
# refreshed, and the latest verification result will be updated to the most recent
105107
if index_item.latest_verification
106108
{
107109
success: index_item.latest_verification.success,
108110
verifiedAt: format_date_time(index_item.latest_verification.created_at),
109111
_links: {
110112
self: {
111-
href: verification_url(index_item.latest_verification, base_url)
113+
href: latest_verification_for_pact_url(index_item.latest_pact, base_url, false)
112114
}
113115
}
114116
}

lib/pact_broker/api/pact_broker_urls.rb

+38-6
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,20 @@ def latest_verifications_for_consumer_version_url version, base_url
157157
"#{base_url}/verification-results/consumer/#{url_encode(version.pacticipant.name)}/version/#{version.number}/latest"
158158
end
159159

160-
def latest_verification_for_pact_url pact, base_url
161-
verification_url_from_params(
162-
provider_name: pact.provider_name,
163-
consumer_name: pact.consumer_name,
164-
pact_version_sha: pact.pact_version_sha,
165-
verification_number: 'latest')
160+
def latest_verification_for_pact_url pact, base_url, permalink = true
161+
if permalink
162+
verification_url_from_params(
163+
{
164+
provider_name: provider_name(pact),
165+
consumer_name: consumer_name(pact),
166+
pact_version_sha: pact.pact_version_sha,
167+
verification_number: 'latest'
168+
},
169+
base_url
170+
)
171+
else
172+
pact_url(base_url, pact) + "/verification-results/latest"
173+
end
166174
end
167175

168176
def verification_triggered_webhooks_url verification, base_url = ''
@@ -276,6 +284,30 @@ def pactigration_base_url_from_params base_url, params
276284
'consumer', url_encode(params[:consumer_name])
277285
].join('/')
278286
end
287+
288+
def consumer_name(thing)
289+
if thing.respond_to?(:consumer_name)
290+
thing.consumer_name
291+
elsif thing.respond_to?(:consumer)
292+
thing.consumer.name
293+
elsif thing.respond_to?(:[])
294+
thing[:consumer_name]
295+
else
296+
nil
297+
end
298+
end
299+
300+
def provider_name(thing)
301+
if thing.respond_to?(:provider_name)
302+
thing.provider_name
303+
elsif thing.respond_to?(:provider)
304+
thing.provider.name
305+
elsif thing.respond_to?(:[])
306+
thing[:provider_name]
307+
else
308+
nil
309+
end
310+
end
279311
end
280312
end
281313
end

spec/fixtures/dashboard.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"latestVerificationResult": {
2727
"_links": {
2828
"self": {
29-
"href": "verification_url"
29+
"href": "latest_verification_url"
3030
}
3131
},
3232
"success": true,

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def in_utc
4949

5050
before do
5151
allow_any_instance_of(DashboardDecorator).to receive(:pact_url).with(base_url, pact).and_return('pact_url')
52-
allow_any_instance_of(DashboardDecorator).to receive(:verification_url).with(verification, base_url).and_return('verification_url')
52+
allow_any_instance_of(DashboardDecorator).to receive(:latest_verification_for_pact_url).with(pact, base_url, false).and_return('latest_verification_url')
5353
allow_any_instance_of(DashboardDecorator).to receive(:pacticipant_url).with(base_url, consumer).and_return('consumer_url')
5454
allow_any_instance_of(DashboardDecorator).to receive(:pacticipant_url).with(base_url, provider).and_return('provider_url')
5555
allow_any_instance_of(DashboardDecorator).to receive(:version_url).with(base_url, consumer_version).and_return('consumer_version_url')

spec/lib/pact_broker/api/pact_broker_urls_spec.rb

+14
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,20 @@ module Api
113113
end
114114
end
115115
end
116+
117+
describe "latest_verification_for_pact_url" do
118+
context "when permalink = true" do
119+
subject { PactBrokerUrls.latest_verification_for_pact_url(pact, base_url, true) }
120+
121+
it { is_expected.to eq "http://example.org/pacts/provider/Bar%2FBar/consumer/Foo%2FFoo/pact-version/5hbfu/verification-results/latest" }
122+
end
123+
124+
context "when permalink = false" do
125+
subject { PactBrokerUrls.latest_verification_for_pact_url(pact, base_url, false) }
126+
127+
it { is_expected.to eq "http://example.org/pacts/provider/Bar%2FBar/consumer/Foo%2FFoo/version/123%2F456/verification-results/latest" }
128+
end
129+
end
116130
end
117131
end
118132
end

0 commit comments

Comments
 (0)