Skip to content

Commit

Permalink
fix: validate matrix query limit
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Aug 18, 2021
1 parent aaffe71 commit ac5e089
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/pact_broker/locale/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ en:
invalid_content_for_content_type: "The content could not be parsed as %{content_type}"
cannot_set_currently_deployed_true: The currentlyDeployed property cannot be set back to true. Please record a new deployment.
cannot_set_currently_supported_true: The currentlySupported property cannot be set back to true. Please record a new deployment.
invalid_limit: The limit must be 1 or greater.
duplicate_pacticipant: |
This is the first time a pact has been published for "%{new_name}".
The name "%{new_name}" is very similar to the following existing consumers/providers:
Expand Down
4 changes: 4 additions & 0 deletions lib/pact_broker/matrix/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ def validate_selectors selectors, options = {}
error_messages << message("errors.validation.environment_with_name_not_found", name: options[:environment_name])
end

if options[:limit] && options[:limit].to_i < 1
error_messages << message("errors.validation.invalid_limit")
end

error_messages
end
# rubocop: enable Metrics/CyclomaticComplexity, Metrics/MethodLength
Expand Down
11 changes: 10 additions & 1 deletion spec/lib/pact_broker/matrix/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module Matrix

subject { Service.validate_selectors(selectors, options) }

let(:options) { {} }
let(:options) { { limit: "1" } }

context "when there are no selectors" do
let(:selectors) { [] }
Expand Down Expand Up @@ -145,6 +145,15 @@ module Matrix
expect(subject.last).to include "Please specify the pacticipant name to ignore"
end
end

context "with an invalid limit" do
let(:options) { { limit: "limit" } }
let(:selectors) { [] }

it "returns an error message" do
expect(subject.last).to include "The limit"
end
end
end

describe "find_for_consumer_and_provider_with_tags integration test" do
Expand Down

0 comments on commit ac5e089

Please sign in to comment.