-
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
feat: Add new rule sumArray #51
Conversation
41517f4
to
9a1fb94
Compare
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.
Please fix tests
t.is(sumArray('field', {}, { exact: 100 }), null); | ||
}); | ||
|
||
test('rules.sumArray should return null for valid exact', t => { |
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.
This is the same test as on line 5
), null); | ||
}); | ||
|
||
test('rules.sumArray should return "sumArray.min" for invalid max', t => { |
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 think this is a copy/paste type, should be .max
|
||
export default function sumArray(field, value, options) { | ||
if (!isArray(value)) { | ||
return null; |
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.
If value is not an array, shouldn't be returned string sumArray
as on the line 30? From my point of view, when a variable number
is not float, that means, we have some corrupted value... the same could be valid for this line :)
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.
Good point 👍
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.
Changed it
9a1fb94
to
6702d81
Compare
@rapasoft Fixed up the test, went a bit fast there. |
Usage examples: { listOfNumbers: { sumArray: { min: 100, max: 200 } } } { listOfObjects: { sumArray: { exact: 100, field: 'percentage' } } } Fixes #28
6702d81
to
5c508f2
Compare
Usage examples:
Fixes #28