-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from oesukam/ft-array-validation-164489344
#164489344 Add array's validation
- Loading branch information
Showing
16 changed files
with
99 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const notAllowed = require('../../src/messages/notAllowedMessage'); | ||
|
||
describe('not-an-array-message', () => { | ||
test('should return `users is not allowed.`', () => { | ||
expect(notAllowed('users')).toBe('users is not allowed.'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const notArray = require('../../src/messages/notArrayMessage'); | ||
|
||
describe('not-an-array-message', () => { | ||
test('should return `users must be an array.`', () => { | ||
expect(notArray('users')).toBe('users must be an array.'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
const array = require('../../src/validators/array'); | ||
|
||
describe('integer-validator', () => { | ||
test('should return `undefined must be an array.`', () => { | ||
expect(array()).toBe('undefined must be an array.'); | ||
}); | ||
|
||
test('should return `users must be an array.`', () => { | ||
expect(array({ | ||
value: 'not an array', | ||
label: 'users', | ||
}),).toBe('users must be an array.'); | ||
}); | ||
|
||
test('should return `users must be an array.`', () => { | ||
expect(array({ | ||
value: {}, | ||
label: 'users', | ||
}),).toBe('users must be an array.'); | ||
}); | ||
|
||
test('should return false', () => { | ||
expect(array({ | ||
value: [], | ||
label: 'users', | ||
}),).toBe(false); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports=a=>`${a} is not allowed.`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports=a=>`${a} must be an array.`; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = label => `${label} is not allowed.`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = label => `${label} must be an array.`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
const notArrayMessage = require('../messages/notArrayMessage'); | ||
|
||
module.exports = ({ value, label } = {}) => { | ||
if (value instanceof Array) return false; | ||
return notArrayMessage(label); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
const numberMessage = require('../messages/notNumberMessage'); | ||
|
||
module.exports = ({ value, label } = {}) => | ||
typeof value === 'number' ? false : numberMessage(label); | ||
module.exports = ({ value, label, path } = {}) => { | ||
if (path === 'query' || path === 'params') { | ||
return !Number.isNaN(Number(value)) ? false : numberMessage(label); | ||
} | ||
return typeof value === 'number' ? false : numberMessage(label); | ||
}; |