5353 expect { validator . call ( params ) } . to_not raise_error
5454 end
5555
56+ it 'should raise on missing nested required params' do
57+ schema = TypedParams ::Schema . new ( type : :hash ) do
58+ param :foo , type : :hash do
59+ param :bar , type : :hash do
60+ param :baz , type : :string
61+ end
62+ end
63+ end
64+
65+ params = TypedParams ::Parameterizer . new ( schema :) . call ( value : { foo : { } } )
66+ validator = TypedParams ::Validator . new ( schema :)
67+
68+ expect { validator . call ( params ) } . to raise_error TypedParams ::InvalidParameterError
69+ end
70+
5671 it 'should not raise on missing nested optional params' do
5772 schema = TypedParams ::Schema . new ( type : :hash ) do
5873 param :foo , type : :hash do
6883 expect { validator . call ( params ) } . to_not raise_error
6984 end
7085
86+ it 'should raise on missing nested nilable params' do
87+ schema = TypedParams ::Schema . new ( type : :hash ) do
88+ param :foo , type : :hash do
89+ param :bar , type : :hash , allow_nil : true do
90+ param :baz , type : :string
91+ end
92+ end
93+ end
94+
95+ params = TypedParams ::Parameterizer . new ( schema :) . call ( value : { foo : { } } )
96+ validator = TypedParams ::Validator . new ( schema :)
97+
98+ expect { validator . call ( params ) } . to raise_error TypedParams ::InvalidParameterError
99+ end
100+
71101 it 'should raise on missing required param' do
72102 schema = TypedParams ::Schema . new ( type : :hash ) { param :foo , type : :string , optional : false }
73103 params = TypedParams ::Parameterizer . new ( schema :) . call ( value : { } )
377407 expect { validator . call ( params ) } . to_not raise_error
378408 end
379409
410+ it 'should not raise on empty array' do
411+ schema = TypedParams ::Schema . new ( type : :array )
412+ params = TypedParams ::Parameterizer . new ( schema :) . call ( value : [ ] )
413+ validator = TypedParams ::Validator . new ( schema :)
414+
415+ expect { validator . call ( params ) } . to_not raise_error
416+ end
417+
380418 it 'should raise on array of non-scalar values' do
381419 schema = TypedParams ::Schema . new ( type : :array )
382420 params = TypedParams ::Parameterizer . new ( schema :) . call ( value : [ 1 , 2 , [ 3 ] ] )
393431 expect { validator . call ( params ) } . to_not raise_error
394432 end
395433
434+ it 'should not raise on array of objects' do
435+ schema = TypedParams ::Schema . new type : :array do
436+ items type : :hash do
437+ param :key , type : :string
438+ end
439+ end
440+
441+ params = TypedParams ::Parameterizer . new ( schema :) . call ( value : [ key : 'value' ] )
442+ validator = TypedParams ::Validator . new ( schema :)
443+
444+ expect { validator . call ( params ) } . to_not raise_error
445+ end
446+
447+ it 'should not raise on empty array of objects' do
448+ schema = TypedParams ::Schema . new type : :array do
449+ items type : :hash do
450+ param :key , type : :string
451+ end
452+ end
453+
454+ params = TypedParams ::Parameterizer . new ( schema :) . call ( value : [ ] )
455+ validator = TypedParams ::Validator . new ( schema :)
456+
457+ expect { validator . call ( params ) } . to_not raise_error
458+ end
459+
396460 context 'with config to not ignore optional nils' do
397461 before do
398462 @ignore_nil_optionals_was = TypedParams . config . ignore_nil_optionals
521585 expect { validator . call ( params ) } . to raise_error TypedParams ::InvalidParameterError
522586 end
523587 end
524- end
588+ end
0 commit comments