@@ -400,4 +400,109 @@ describe('MatcherPatternQueryParam', () => {
400400 expect ( matcher . match ( { other : 'value' } ) ) . toEqual ( { missing : 'default' } )
401401 } )
402402 } )
403+
404+ describe ( 'defaultValue' , ( ) => {
405+ describe ( 'match' , ( ) => {
406+ it ( 'should fallback to PARAM_PARSER_DEFAULTS.get when parser.get is undefined' , ( ) => {
407+ const matcher = new MatcherPatternQueryParam (
408+ 'test' ,
409+ 'test_param' ,
410+ 'value' ,
411+ { }
412+ )
413+ // Should use PARAM_PARSER_DEFAULTS.get which returns value ?? null
414+ expect ( matcher . match ( { test_param : 'value' } ) ) . toEqual ( {
415+ test : 'value' ,
416+ } )
417+ expect ( matcher . match ( { test_param : null } ) ) . toEqual ( { test : null } )
418+ expect ( matcher . match ( { } ) ) . toEqual ( { test : undefined } )
419+ } )
420+
421+ it ( 'should handle array format with missing get method' , ( ) => {
422+ const matcher = new MatcherPatternQueryParam (
423+ 'test' ,
424+ 'test_param' ,
425+ 'array' ,
426+ { }
427+ )
428+ // Should use PARAM_PARSER_DEFAULTS.get which returns value ?? null
429+ expect ( matcher . match ( { test_param : [ 'a' , 'b' ] } ) ) . toEqual ( {
430+ test : [ 'a' , 'b' ] ,
431+ } )
432+ expect ( matcher . match ( { test_param : 'single' } ) ) . toEqual ( {
433+ test : [ 'single' ] ,
434+ } )
435+ } )
436+
437+ it ( 'should handle both format with missing get method' , ( ) => {
438+ const matcher = new MatcherPatternQueryParam (
439+ 'test' ,
440+ 'test_param' ,
441+ 'both' ,
442+ { }
443+ )
444+ // Should use PARAM_PARSER_DEFAULTS.get which returns value ?? null
445+ expect ( matcher . match ( { test_param : 'value' } ) ) . toEqual ( {
446+ test : 'value' ,
447+ } )
448+ expect ( matcher . match ( { test_param : [ 'a' , 'b' ] } ) ) . toEqual ( {
449+ test : [ 'a' , 'b' ] ,
450+ } )
451+ } )
452+ } )
453+
454+ describe ( 'build' , ( ) => {
455+ it ( 'should fallback to PARAM_PARSER_DEFAULTS.set when parser.set is undefined' , ( ) => {
456+ const matcher = new MatcherPatternQueryParam (
457+ 'test' ,
458+ 'test_param' ,
459+ 'value' ,
460+ { }
461+ )
462+ // Should use PARAM_PARSER_DEFAULTS.set which converts to string
463+ expect ( matcher . build ( { test : 'value' } ) ) . toEqual ( {
464+ test_param : 'value' ,
465+ } )
466+ expect ( matcher . build ( { test : 123 } ) ) . toEqual ( { test_param : '123' } )
467+ expect ( matcher . build ( { test : true } ) ) . toEqual ( { test_param : 'true' } )
468+ expect ( matcher . build ( { test : null } ) ) . toEqual ( { test_param : null } )
469+ expect ( matcher . build ( { test : undefined } ) ) . toEqual ( { } )
470+ } )
471+
472+ it ( 'should handle array values with missing set method' , ( ) => {
473+ const matcher = new MatcherPatternQueryParam (
474+ 'test' ,
475+ 'test_param' ,
476+ 'array' ,
477+ { }
478+ )
479+ // Should use PARAM_PARSER_DEFAULTS.set which handles arrays
480+ expect ( matcher . build ( { test : [ 'a' , 'b' ] } ) ) . toEqual ( {
481+ test_param : [ 'a' , 'b' ] ,
482+ } )
483+ expect ( matcher . build ( { test : [ 1 , 2 ] } ) ) . toEqual ( {
484+ test_param : [ '1' , '2' ] ,
485+ } )
486+ expect ( matcher . build ( { test : [ 1 , true ] } ) ) . toEqual ( {
487+ test_param : [ '1' , 'true' ] ,
488+ } )
489+ } )
490+
491+ it ( 'should handle both format with missing set method' , ( ) => {
492+ const matcher = new MatcherPatternQueryParam (
493+ 'test' ,
494+ 'test_param' ,
495+ 'both' ,
496+ { }
497+ )
498+ // Should use PARAM_PARSER_DEFAULTS.set
499+ expect ( matcher . build ( { test : 'value' } ) ) . toEqual ( {
500+ test_param : 'value' ,
501+ } )
502+ expect ( matcher . build ( { test : [ 'a' , 'b' ] } ) ) . toEqual ( {
503+ test_param : [ 'a' , 'b' ] ,
504+ } )
505+ } )
506+ } )
507+ } )
403508} )
0 commit comments