Skip to content

Commit

Permalink
feat(pacts for verification): default latest to true when branch is s…
Browse files Browse the repository at this point in the history
…pecified and currentlyDeployed to true when an environment is specified
  • Loading branch information
bethesque committed Mar 8, 2021
1 parent 3cab7a0 commit 984320b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,21 @@ class VerifiablePactsQueryDecorator < BaseDecorator

collection :consumer_version_selectors, default: PactBroker::Pacts::Selectors.new, class: PactBroker::Pacts::Selector do
property :tag
property :branch
property :branch, setter: -> (fragment:, represented:, **) {
represented.branch = fragment
represented.latest = true
}
property :latest,
setter: ->(fragment:, represented:, **) {
represented.latest = (fragment == 'true' || fragment == true)
}
property :fallback_tag
property :fallback_branch
property :consumer
property :environment
property :environment, setter: -> (fragment:, represented:, **) {
represented.environment = fragment
represented.currently_deployed = true
}
property :currently_deployed
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,28 @@ module Decorators
expect(subject.provider_version_tags).to eq []
end
end

context "when a branch is specified but the latest is not specified" do
let(:consumer_version_selectors) do
[{ "branch" => "main" }]
end

it "defaults the latest to true" do
expect(subject.consumer_version_selectors.first.branch).to eq "main"
expect(subject.consumer_version_selectors.first.latest).to be true
end
end

context "when an environment is specified but currently_deployed is not specified" do
let(:consumer_version_selectors) do
[{ "environment" => "prod" }]
end

it "sets the currently_deployed to true" do
expect(subject.consumer_version_selectors.first.environment).to eq "prod"
expect(subject.consumer_version_selectors.first.currently_deployed).to be true
end
end
end

context "when parsing query string params" do
Expand Down

0 comments on commit 984320b

Please sign in to comment.