From 23b02c80a10db5ceb04ece20c23555a4a53f7fd4 Mon Sep 17 00:00:00 2001 From: Beth Skurrie Date: Wed, 25 Mar 2020 17:05:23 +1100 Subject: [PATCH] feat(pact ui): update matrix URL to specify the latest provider version --- lib/pact_broker/api/pact_broker_urls.rb | 11 +++++++++++ lib/pact_broker/api/renderers/html_pact_renderer.rb | 2 +- .../api/renderers/html_pact_renderer_spec.rb | 3 ++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/pact_broker/api/pact_broker_urls.rb b/lib/pact_broker/api/pact_broker_urls.rb index 6f6fc9caa..6beb80d51 100644 --- a/lib/pact_broker/api/pact_broker_urls.rb +++ b/lib/pact_broker/api/pact_broker_urls.rb @@ -261,6 +261,17 @@ def matrix_for_pacticipant_version_url(version, base_url = '') "#{base_url}/matrix?#{Rack::Utils.build_nested_query(query)}" end + def matrix_for_pact_url(pact, base_url = '') + query = { + q: [ + { pacticipant: pact.consumer_name, version: pact.consumer_version_number }, + { pacticipant: pact.provider_name, latest: true } + ], + latestby: 'cvpv' + } + "#{base_url}/matrix?#{Rack::Utils.build_nested_query(query)}" + end + def matrix_url_from_params params, base_url = '' matrix_url(params.fetch(:consumer_name), params.fetch(:provider_name), base_url) end diff --git a/lib/pact_broker/api/renderers/html_pact_renderer.rb b/lib/pact_broker/api/renderers/html_pact_renderer.rb index 929597020..d520bf833 100644 --- a/lib/pact_broker/api/renderers/html_pact_renderer.rb +++ b/lib/pact_broker/api/renderers/html_pact_renderer.rb @@ -137,7 +137,7 @@ def pact_url end def matrix_url - PactBroker::Api::PactBrokerUrls.matrix_for_pacticipant_version_url(@pact.consumer_version, base_url) + PactBroker::Api::PactBrokerUrls.matrix_for_pact_url(@pact, base_url) end def latest_pact_url diff --git a/spec/lib/pact_broker/api/renderers/html_pact_renderer_spec.rb b/spec/lib/pact_broker/api/renderers/html_pact_renderer_spec.rb index a9b9cfccb..fde9fc078 100644 --- a/spec/lib/pact_broker/api/renderers/html_pact_renderer_spec.rb +++ b/spec/lib/pact_broker/api/renderers/html_pact_renderer_spec.rb @@ -12,7 +12,7 @@ module Renderers ENV['TZ'] = "Australia/Melbourne" PactBroker.configuration.enable_public_badge_access = true allow(PactBroker::Api::PactBrokerUrls).to receive(:pact_url).with('http://base', pact).and_return(pact_url) - allow(PactBroker::Api::PactBrokerUrls).to receive(:matrix_for_pacticipant_version_url).with(consumer_version, 'http://base').and_return(matrix_url) + allow(PactBroker::Api::PactBrokerUrls).to receive(:matrix_for_pact_url).with(pact, 'http://base').and_return(matrix_url) allow_any_instance_of(HtmlPactRenderer).to receive(:logger).and_return(logger) Timecop.freeze(created_at + 3) @@ -95,6 +95,7 @@ module Renderers before do allow(pact).to receive(:content_hash).and_return(content_hash) end + let(:json_content) { '[1]' } let(:content_hash) { [1] }