Skip to content

Commit

Permalink
chore: fix target paramater parsing when querying deployed versions
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Jun 9, 2021
1 parent 7132e60 commit 6636056
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,13 @@ def environment_uuid
end

def query_params
# Webmachine request.query drops parameters with blank values, and we need to know if
# a blank target was specified.
query = Rack::Utils.parse_query(request.env["QUERY_STRING"])
q = {}
if request.query["pacticipant"]
q[:pacticipant_name] = request.query["pacticipant"]
end
if request.query["target"]
q[:target] = request.query["target"].blank? ? nil : request.query["target"]
q[:pacticipant_name] = request.query["pacticipant"] if query["pacticipant"]
if query["target"]
q[:target] = query["target"].blank? ? nil : query["target"]
end
q
end
Expand Down
4 changes: 2 additions & 2 deletions lib/pact_broker/deployments/deployed_version_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ def self.find_currently_deployed_version_for_version_and_environment_and_target(
.single_record
end

def self.find_currently_deployed_versions_for_environment(environment, pacticipant_name: nil, target: nil)
def self.find_currently_deployed_versions_for_environment(environment, pacticipant_name: nil, target: :unspecified)
query = scope_for(DeployedVersion)
.currently_deployed
.for_environment(environment)
.order_by_date_desc

query = query.for_pacticipant_name(pacticipant_name) if pacticipant_name
query = query.for_target(target) if target
query = query.for_target(target) if target != :unspecified
query.all
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
.create_provider_version("4")
.create_deployed_version_for_provider_version(environment_name: "test", target: "customer-1")
.create_provider_version("5")
.create_deployed_version_for_provider_version(environment_name: "test", target: "customer-2")
.create_deployed_version_for_provider_version(environment_name: "test")

end

Expand All @@ -19,9 +19,10 @@
)
end

let(:query_params) { {} }
let(:response_body_hash) { JSON.parse(subject.body, symbolize_names: true) }

subject { get(path, nil, { "HTTP_ACCEPT" => "application/hal+json" }) }
subject { get(path, query_params, { "HTTP_ACCEPT" => "application/hal+json" }) }

it "returns a list of deployed versions" do
expect(response_body_hash[:_embedded][:deployedVersions]).to be_a(Array)
Expand All @@ -31,11 +32,31 @@
end

context "with query params" do
subject { get(path, { pacticipant: "Bar", target: "customer-1" }, { "HTTP_ACCEPT" => "application/hal+json" }) }

it "returns a list of matching deployed versions" do
expect(response_body_hash[:_embedded][:deployedVersions].size).to eq 1
expect(response_body_hash[:_embedded][:deployedVersions].first[:_embedded][:version][:number]).to eq "4"
context "with a pacticipant name and target" do
let(:query_params) { { pacticipant: "Bar", target: "customer-1" } }

it "returns a list of matching deployed versions" do
expect(response_body_hash[:_embedded][:deployedVersions].size).to eq 1
expect(response_body_hash[:_embedded][:deployedVersions].first[:_embedded][:version][:number]).to eq "4"
end
end

context "with pacticipant name and a blank target" do
let(:query_params) { { pacticipant: "Bar", target: "" } }

it "returns a list of matching deployed versions" do
expect(response_body_hash[:_embedded][:deployedVersions].size).to eq 1
expect(response_body_hash[:_embedded][:deployedVersions].first[:_embedded][:version][:number]).to eq "5"
end
end

context "with pacticipant name and no target" do
let(:query_params) { { pacticipant: "Bar" } }

it "returns a list of matching deployed versions" do
expect(response_body_hash[:_embedded][:deployedVersions].size).to eq 2
end
end
end
end

0 comments on commit 6636056

Please sign in to comment.