Skip to content

Commit

Permalink
feat: show more helpful error message if pb:environments not availabl…
Browse files Browse the repository at this point in the history
…e for pactflow
  • Loading branch information
bethesque committed Oct 13, 2021
1 parent 86caf7e commit 1bf38e3
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
6 changes: 5 additions & 1 deletion lib/pact_broker/client/deployments/record_release.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ def action_relation_name
end

def not_supported_message
"This version of the Pact Broker does not support recording #{action}s. Please upgrade to version 2.80.0 or later."
if is_pactflow?
"This version of Pactflow does not support recording #{action}s, or you do not have the required permission to read environments. Please upgrade to the latest version if using Pactflow On-Premises, and ensure the user has the environment read permission."
else
"This version of the Pact Broker does not support recording #{action}s. Please upgrade to version 2.80.0 or later."
end
end

def environment_exists?
Expand Down
7 changes: 6 additions & 1 deletion lib/pact_broker/client/environments/environment_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module Client
module Environments
class EnvironmentCommand < PactBroker::Client::BaseCommand
NOT_SUPPORTED_MESSAGE = "This version of the Pact Broker does not support environments. Please upgrade to version 2.80.0 or later."
PACTFLOW_NOT_SUPPORTED_MESSAGE = "This version of Pactflow does not support environments or you do not have the required permission to read them. Please upgrade to the latest version if using Pactflow On-Premises and ensure the user has the environment read permission."

private

Expand Down Expand Up @@ -57,7 +58,11 @@ def contacts

def check_if_command_supported
unless index_resource.can?("pb:environments")
raise PactBroker::Client::Error.new(NOT_SUPPORTED_MESSAGE)
if is_pactflow?
raise PactBroker::Client::Error.new(PACTFLOW_NOT_SUPPORTED_MESSAGE)
else
raise PactBroker::Client::Error.new(NOT_SUPPORTED_MESSAGE)
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ module Deployments
let(:record_deployment_body_hash) do
{ "some" => "response" }
end
let(:index_headers) { { "Content-Type" => "application/hal+json" } }
let!(:index_request) do
stub_request(:get, broker_base_url).to_return(status: 200, body: index_body_hash.to_json, headers: { "Content-Type" => "application/hal+json" } )
stub_request(:get, broker_base_url).to_return(status: 200, body: index_body_hash.to_json, headers: index_headers )
end
let!(:version_request) do
stub_request(:get, broker_base_url + "/pacticipants/Foo/versions/1").to_return(status: 200, body: version_body_hash.to_json, headers: { "Content-Type" => "application/hal+json" } )
Expand Down Expand Up @@ -89,10 +90,20 @@ module Deployments
"_links" => {}
}
end

it "returns an error response" do
expect(subject.success).to be false
expect(subject.message).to include "does not support"
end

context "when the server is Pactflow" do
let(:index_headers) { { "Content-Type" => "application/hal+json", "Pactflow-Something" => "foo" } }

it "returns an error response" do
expect(subject.message).to include "permission"
expect(subject.message).to include "does not support"
end
end
end

context "when the specified version does not exist" do
Expand Down

0 comments on commit 1bf38e3

Please sign in to comment.