File tree Expand file tree Collapse file tree 3 files changed +26
-9
lines changed
src/validation/drivers/validators
tests/validation/drivers/validators Expand file tree Collapse file tree 3 files changed +26
-9
lines changed Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " strontium" ,
3
- "version" : " 2.3.3 " ,
3
+ "version" : " 2.3.4 " ,
4
4
"description" : " Strontium is a TypeScript toolkit for High Performance API servers built for Production not Projects." ,
5
5
"main" : " lib/src/index.js" ,
6
6
"types" : " lib/src/index.d.ts" ,
Original file line number Diff line number Diff line change @@ -16,14 +16,18 @@ export const isObject = <V extends ObjectValidator>(validator: V) => async (
16
16
let response : Partial < ValidatedObject < V > > = { }
17
17
18
18
for ( let p in validator ) {
19
- if ( validator . hasOwnProperty ( p ) && i . hasOwnProperty ( p ) ) {
19
+ if ( validator . hasOwnProperty ( p ) ) {
20
20
// Sadly ts-ignore this as TS doesn't understand that we have strongly ensured
21
21
// that this property is present.
22
22
// @ts -ignore
23
23
let rawValue = i [ p ]
24
24
25
25
try {
26
- response [ p ] = await validator [ p ] ( rawValue )
26
+ let validatedOutput = await validator [ p ] ( rawValue )
27
+
28
+ if ( validatedOutput !== undefined ) {
29
+ response [ p ] = validatedOutput
30
+ }
27
31
} catch ( e ) {
28
32
if ( e instanceof ValidationError ) {
29
33
// Append the path to the error message
Original file line number Diff line number Diff line change 1
1
import { expect } from "chai"
2
2
import { combineValidators } from "../../../../src/validation/drivers/helpers/combineValidators"
3
3
import {
4
- ValidationError ,
5
- isISOAlpha2CountryCode ,
6
- isObject ,
7
- isString ,
8
- } from "../../../../src"
4
+ ValidationError ,
5
+ isISOAlpha2CountryCode ,
6
+ isObject ,
7
+ isString , isUndefined
8
+ } from "../../../../src" ;
9
+ import { either } from "../../../../src/validation/drivers/helpers/either" ;
9
10
10
11
describe ( "isNull" , ( ) => {
11
12
const objectFilter = isObject ( {
12
- test : isString ,
13
+ test : either ( isString , isUndefined ) ,
13
14
otherTest : combineValidators ( isString , isISOAlpha2CountryCode ) ,
14
15
} )
15
16
@@ -55,4 +56,16 @@ describe("isNull", () => {
55
56
expect ( e . constraintName ) . to . equal ( "IS_STRING" )
56
57
}
57
58
} )
59
+
60
+ it ( "should return a required validation error if a key is absent" , async ( ) => {
61
+ try {
62
+ await objectFilter ( {
63
+ test : "Test Value"
64
+ } )
65
+ expect ( false ) . to . equal ( true )
66
+ } catch ( e ) {
67
+ expect ( e ) . to . be . instanceOf ( ValidationError )
68
+ expect ( e . constraintName ) . to . equal ( "IS_STRING" )
69
+ }
70
+ } )
58
71
} )
You can’t perform that action at this time.
0 commit comments