forked from pact-foundation/pact_broker
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add back support for GET requests to the 'pacts for verificatio…
…n' API with a deprecation notice in the response
- Loading branch information
Showing
7 changed files
with
223 additions
and
23 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
lib/pact_broker/api/contracts/verifiable_pacts_query_schema.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
require 'dry-validation' | ||
require 'pact_broker/api/contracts/dry_validation_workarounds' | ||
require 'pact_broker/api/contracts/dry_validation_predicates' | ||
|
||
module PactBroker | ||
module Api | ||
module Contracts | ||
class VerifiablePactsQuerySchema | ||
extend DryValidationWorkarounds | ||
using PactBroker::HashRefinements | ||
|
||
SCHEMA = Dry::Validation.Schema do | ||
configure do | ||
predicates(DryValidationPredicates) | ||
config.messages_file = File.expand_path("../../../locale/en.yml", __FILE__) | ||
end | ||
optional(:provider_version_tags).maybe(:array?) | ||
optional(:consumer_version_selectors).each do | ||
schema do | ||
required(:tag).filled(:str?) | ||
optional(:latest).filled(included_in?: ["true", "false"]) | ||
optional(:fallback_tag).filled(:str?) | ||
optional(:consumer).filled(:str?, :not_blank?) | ||
end | ||
end | ||
optional(:include_pending_status).filled(included_in?: ["true", "false"]) | ||
optional(:include_wip_pacts_since).filled(:date?) | ||
end | ||
|
||
def self.call(params) | ||
select_first_message(flatten_indexed_messages(SCHEMA.call(params&.symbolize_keys).messages(full: true))) | ||
end | ||
|
||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
spec/lib/pact_broker/api/contracts/verifiable_pacts_query_schema_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
require 'pact_broker/api/contracts/verifiable_pacts_query_schema' | ||
|
||
module PactBroker | ||
module Api | ||
module Contracts | ||
describe VerifiablePactsQuerySchema do | ||
let(:params) do | ||
{ | ||
provider_version_tags: provider_version_tags, | ||
consumer_version_selectors: consumer_version_selectors | ||
} | ||
end | ||
|
||
let(:provider_version_tags) { %w[master] } | ||
|
||
let(:consumer_version_selectors) do | ||
[{ | ||
tag: "master", | ||
latest: "true" | ||
}] | ||
end | ||
|
||
subject { VerifiablePactsQuerySchema.(params) } | ||
|
||
context "when the params are valid" do | ||
it "has no errors" do | ||
expect(subject).to eq({}) | ||
end | ||
end | ||
|
||
context "when provider_version_tags is not an array" do | ||
let(:provider_version_tags) { "foo" } | ||
|
||
it { is_expected.to have_key(:provider_version_tags) } | ||
end | ||
|
||
context "when the consumer_version_selector is missing a tag" do | ||
let(:consumer_version_selectors) do | ||
[{}] | ||
end | ||
|
||
it "flattens the messages" do | ||
expect(subject[:consumer_version_selectors].first).to eq "tag is missing at index 0" | ||
end | ||
end | ||
|
||
context "when the consumer_version_selectors is missing the latest" do | ||
let(:consumer_version_selectors) do | ||
[{ | ||
tag: "master" | ||
}] | ||
end | ||
|
||
it { is_expected.to be_empty } | ||
end | ||
|
||
context "when include_wip_pacts_since key exists" do | ||
let(:include_wip_pacts_since) { nil } | ||
let(:params) do | ||
{ | ||
include_wip_pacts_since: include_wip_pacts_since | ||
} | ||
end | ||
|
||
context "when it is nil" do | ||
it { is_expected.to have_key(:include_wip_pacts_since) } | ||
end | ||
|
||
context "when it is not a date" do | ||
let(:include_wip_pacts_since) { "foo" } | ||
|
||
it { is_expected.to have_key(:include_wip_pacts_since) } | ||
end | ||
|
||
context "when it is a valid date" do | ||
let(:include_wip_pacts_since) { "2013-02-13T20:04:45.000+11:00" } | ||
|
||
it { is_expected.to_not have_key(:include_wip_pacts_since) } | ||
end | ||
end | ||
|
||
context "when a blank consumer name is specified" do | ||
let(:consumer_version_selectors) do | ||
[{ | ||
tag: "feat-x", | ||
consumer: "" | ||
}] | ||
end | ||
|
||
it "has an error" do | ||
expect(subject[:consumer_version_selectors].first).to include "blank" | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters