Skip to content
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

Merged
merged 1 commit into from
Sep 26, 2016
Merged

feat: Add new rule sumArray #51

merged 1 commit into from
Sep 26, 2016

Conversation

relekang
Copy link
Contributor

Usage examples:

{ listOfNumbers: { sumArray: { min: 100, max: 200 } } }
{ listOfObjects: { sumArray: { exact: 100, field: 'percentage' } } }

Fixes #28

Copy link
Contributor

@rapasoft rapasoft left a 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 => {
Copy link
Contributor

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 => {
Copy link
Contributor

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;
Copy link
Contributor

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 :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed it

@relekang
Copy link
Contributor Author

@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
@relekang relekang merged commit eec4db4 into master Sep 26, 2016
@relekang relekang deleted the feat/sumArray branch September 26, 2016 13:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants