forked from ealush/vest
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Your Name
committed
Nov 29, 2020
1 parent
7412129
commit 819ab2f
Showing
9 changed files
with
93 additions
and
3 deletions.
There are no files selected for viewing
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
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
62 changes: 62 additions & 0 deletions
62
packages/n4s/src/enforce/compounds/__tests__/allOf.test.js
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,62 @@ | ||
import allOf from 'allOf'; | ||
import enforce from 'enforce'; | ||
|
||
describe('allOf validation', () => { | ||
describe('Base behavior', () => { | ||
it('Should fail when at least one rule fail', () => { | ||
expect(allOf('test', enforce.isString(), enforce.longerThan(10))).toBe( | ||
false | ||
); | ||
}); | ||
it('Should succeed when all of the rules applies', () => { | ||
expect( | ||
allOf('test', enforce.isString(), enforce.longerThan(3)) | ||
).toBe(true); | ||
}); | ||
it('Should fail with no rules', () => { | ||
expect(allOf(3)).toBe(true); | ||
}); | ||
}); | ||
|
||
describe('As part of enforce', () => { | ||
const User = enforce.template( | ||
enforce.loose({ | ||
id: enforce.isNumber(), | ||
name: enforce.shape({ | ||
first: enforce.isString(), | ||
last: enforce.isString(), | ||
middle: enforce.optional(enforce.isString()), | ||
}), | ||
}) | ||
); | ||
|
||
const DisabledAccount = enforce.template( | ||
enforce.loose({ | ||
disabled: enforce.equals(true) | ||
}) | ||
) | ||
|
||
it('Should validate allof the rules correctly', () => { | ||
enforce(value).allOf( | ||
{ id: 123, name : { first: 'Albert', last: 'Einstein' } }, | ||
{ disabled: true } | ||
); | ||
}); | ||
|
||
it('Should throw if one of the rules fail', () =>{ | ||
expect( () => { | ||
enforce(value).allOf( | ||
{ id: 123, name : { first: 'Albert', last: 0 } }, | ||
{ disabled: true } | ||
); | ||
}).toThrow(); | ||
|
||
expect( () => { | ||
enforce(value).allOf( | ||
{ id: 123, name : { first: 'Albert', last: 'Einstein' } }, | ||
{ disabled: false } | ||
); | ||
}).toThrow(); | ||
} ) | ||
}); | ||
}); |
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,10 @@ | ||
import runLazyRules from 'runLazyRules'; | ||
import { withFirst } from 'withArgs'; | ||
|
||
function allOf(value, rules) { | ||
return ( | ||
!rules.length || rules.every(ruleGroup => runLazyRules(ruleGroup, value)) | ||
); | ||
} | ||
|
||
export default withFirst(anyOf); |
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