-
-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(n4s): make sure oneOf correctly validates single case
- Loading branch information
Showing
2 changed files
with
45 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import enforce from 'enforce'; | ||
import * as ruleReturn from 'ruleReturn'; | ||
|
||
describe('enforce.oneOf', () => { | ||
it('Should fail when multiple enforcements are met', () => { | ||
expect( | ||
User.run({ | ||
id: 11, | ||
name: { | ||
first: 'John', | ||
last: 'Doe', | ||
}, | ||
}) | ||
).toEqual(ruleReturn.failing()); | ||
}); | ||
|
||
it('Should pass when only one enforcement is met', () => { | ||
expect( | ||
User.run({ | ||
name: { | ||
first: 'John', | ||
last: 'Doe', | ||
}, | ||
}) | ||
).toEqual(ruleReturn.passing()); | ||
expect(User.run({ id: 11 })).toEqual(ruleReturn.passing()); | ||
}); | ||
|
||
it('Should fail when no enforcement is met', () => { | ||
expect(User.run({})).toEqual(ruleReturn.failing()); | ||
}); | ||
}); | ||
|
||
const Entity = enforce.loose({ | ||
id: enforce.isNumber(), | ||
}); | ||
|
||
const Person = enforce.loose({ | ||
name: enforce.shape({ | ||
first: enforce.isString().longerThan(2), | ||
last: enforce.isString().longerThan(2), | ||
}), | ||
}); | ||
const User = enforce.oneOf(Entity, Person); |
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