2019-07-30 21:29:24 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-06-12 20:03:43 +00:00
|
|
|
# License: AGPL-3.0-or-later WITH WTO-AP-3.0-or-later
|
|
|
|
# Full license explanation at https://github.com/houdiniproject/houdini/blob/master/LICENSE
|
2018-03-25 17:30:42 +00:00
|
|
|
module Expect
|
2019-07-30 21:29:24 +00:00
|
|
|
def expect_validation_errors(list_of_errors, validators, error_validator_length_should_match = true)
|
|
|
|
if list_of_errors.is_a?(ParamValidation::ValidationError)
|
2018-03-25 17:30:42 +00:00
|
|
|
|
|
|
|
list_of_errors = list_of_errors.data
|
|
|
|
end
|
2019-07-30 21:29:24 +00:00
|
|
|
list_of_errors = [list_of_errors] if list_of_errors.is_a?(Hash)
|
|
|
|
validators = [validators] if validators.is_a?(Hash)
|
|
|
|
if error_validator_length_should_match
|
2018-03-25 17:30:42 +00:00
|
|
|
expect(list_of_errors.length).to eq(validators.length)
|
|
|
|
end
|
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
validators.each do |i|
|
|
|
|
expect(list_of_errors.any? { |e| e[:key].to_s == i[:key].to_s && e[:name].to_s == i[:name].to_s }).to eq(true), "#{i[:key]} should have existed for #{i[:name]}"
|
|
|
|
end
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
2021-02-02 21:04:53 +00:00
|
|
|
|
|
|
|
def match_houid(prefix)
|
|
|
|
match(/#{prefix}_[a-zA-Z0-9]{22}/)
|
|
|
|
end
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|