-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Add choice_rule payload validation #187
base: master
Are you sure you want to change the base?
Conversation
|
||
def initialize(*) | ||
super | ||
@compare_key = payload.keys.detect { |key| key.match?(/^(#{COMPARE_KEYS.join("|")})/) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO I don't like the regular expression matcher here because it actually matches on typos like "StringEqualz" (this was my first spec). This is fine when we have the big case compare_key
in true?
since the else raises an exception but I want it to be stricter in the payload initialize validation.
0b56c03
to
88457eb
Compare
a8e11cd
to
da2c0c7
Compare
da2c0c7
to
fef939e
Compare
Checked commit agrare@fef939e with ruby 2.7.8, rubocop 1.56.3, haml-lint 0.51.0, and yamllint lib/floe/workflow/choice_rule/data.rb
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the attr_reader approach. very nice
it "raises an exception" do | ||
expect { subject }.to raise_exception(Floe::InvalidWorkflowError, "Data-test Expression Choice Rule must have a compare key") | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
context "with an invalid compare key" do
let(:payload) { {"Variable" => "$.foo", "InvalidCompare" => "$.bar", "Next" => "FirstMatchState"} }
let(:input) { {"foo" => 0, "bar" => 1} }
it "fails" do
expect { subject }.to raise_exception(Floe::InvalidWorkflowError)
end
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 yeah I added two more tests one with a typo'd key which would have succeeded on the prior regex approach, and one testing if you have multiple compare keys
COMPARE_KEYS = ( | ||
%w[IsNull IsPresent IsNumeric IsString IsBoolean IsTimestamp StringMatches] + | ||
%w[String Numeric Boolean Timestamp].flat_map { |k| ["#{k}Equals", "#{k}EqualsPath"] } + | ||
%w[String Numeric Timestamp].flat_map { |k| %w[LessThan GreaterThan LessThanEquals GreaterThanEquals].flat_map { |x| ["#{k}#{x}", "#{k}#{x}Path"] } } | ||
).freeze |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would have preferred using a hash mapping the string to the operation.
Then we could drop the switch
But this is good for now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good idea let me give that a shot
This pull request is not mergeable. Please rebase and repush. |
This pull request has been automatically marked as stale because it has not been updated for at least 3 months. If these changes are still valid, please remove the |
No description provided.