Skip to content

Commit

Permalink
feat(record deployment): require replacedPreviousDeployedVersion to b…
Browse files Browse the repository at this point in the history
…e set
  • Loading branch information
bethesque committed Mar 5, 2021
1 parent 310ede9 commit 7039806
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ def post_is_create?
true
end

def malformed_request?
if request.post?
malformed_post_request?
else
false
end
end

def create_path
deployed_version_url(OpenStruct.new(uuid: deployed_version_uuid), base_url)
end
Expand Down Expand Up @@ -67,12 +75,21 @@ def deployed_version_uuid
end

def replaced_previous_deployed_version
params[:replacedPreviousDeployedVersion] == true
params(default: {})[:replacedPreviousDeployedVersion]
end

def title
"Deployed versions for #{pacticipant_name} version #{pacticipant_version_number}"
end

def malformed_post_request?
if ![true, false].include?(replaced_previous_deployed_version)
set_json_validation_error_messages({ replacedPreviousDeployedVersion: ["must be one of true, false"] })
true
else
false
end
end
end
end
end
Expand Down
21 changes: 20 additions & 1 deletion spec/features/record_deployment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
.find{ |relation| relation["name"] == "test" }
.fetch("href")
end
let(:request_body) { { replacedPreviousDeployedVersion: replaced_previous }.to_json }

subject { post(path, { replacedPreviousDeployedVersion: replaced_previous }.to_json, headers) }
subject { post(path, request_body, headers) }

it { is_expected.to be_a_hal_json_created_response }

Expand All @@ -33,14 +34,32 @@
end

it "marks the previous deployment as not currently deployed" do
expect { subject }.to change { PactBroker::Deployments::DeployedVersion.currently_deployed.collect(&:uuid) }
end

it "does not change the overall count of currently deployed versions" do
expect { subject }.to_not change { PactBroker::Deployments::DeployedVersion.currently_deployed.count }
end

context "with an empty body" do
let(:request_body) { nil }

it { is_expected.to be_a_json_error_response("must be one of true, false") }

it "does not change the overall count of currently deployed versions" do
expect { subject }.to_not change { PactBroker::Deployments::DeployedVersion.currently_deployed.count }
end
end

context "when the deployment does not replace the previous deployed version" do
let(:replaced_previous) { false }

it "leaves the previous deployed version as currently deployed" do
expect { subject }.to change { PactBroker::Deployments::DeployedVersion.currently_deployed.count }.by(1)
end

it "increases the overall count of currently deployed versions" do
expect { subject }.to change { PactBroker::Deployments::DeployedVersion.currently_deployed.count }.by(1)
end
end
end

0 comments on commit 7039806

Please sign in to comment.