@@ -40,18 +40,6 @@ describe('MatcherPatternQueryParam', () => {
4040 )
4141 expect ( matcher . match ( { user_id : null } ) ) . toEqual ( { userId : null } )
4242 } )
43-
44- it ( 'handles missing query param' , ( ) => {
45- const matcher = new MatcherPatternQueryParam (
46- 'userId' ,
47- 'user_id' ,
48- 'value' ,
49- PARAM_PARSER_DEFAULTS
50- )
51- expect ( matcher . match ( { } ) ) . toEqual ( {
52- userId : undefined ,
53- } )
54- } )
5543 } )
5644
5745 describe ( 'match() - format: array' , ( ) => {
@@ -98,50 +86,6 @@ describe('MatcherPatternQueryParam', () => {
9886 } )
9987 } )
10088
101- describe ( 'match() - format: both' , ( ) => {
102- it ( 'preserves single string value' , ( ) => {
103- const matcher = new MatcherPatternQueryParam (
104- 'data' ,
105- 'value' ,
106- 'both' ,
107- PARAM_PARSER_DEFAULTS
108- )
109- expect ( matcher . match ( { value : 'single' } ) ) . toEqual ( { data : 'single' } )
110- } )
111-
112- it ( 'preserves array value' , ( ) => {
113- const matcher = new MatcherPatternQueryParam (
114- 'data' ,
115- 'values' ,
116- 'both' ,
117- PARAM_PARSER_DEFAULTS
118- )
119- expect ( matcher . match ( { values : [ 'a' , 'b' ] } ) ) . toEqual ( {
120- data : [ 'a' , 'b' ] ,
121- } )
122- } )
123-
124- it ( 'preserves null' , ( ) => {
125- const matcher = new MatcherPatternQueryParam (
126- 'data' ,
127- 'value' ,
128- 'both' ,
129- PARAM_PARSER_DEFAULTS
130- )
131- expect ( matcher . match ( { value : null } ) ) . toEqual ( { data : null } )
132- } )
133-
134- it ( 'handles missing query param' , ( ) => {
135- const matcher = new MatcherPatternQueryParam (
136- 'data' ,
137- 'value' ,
138- 'both' ,
139- PARAM_PARSER_DEFAULTS
140- )
141- expect ( matcher . match ( { } ) ) . toEqual ( { data : undefined } )
142- } )
143- } )
144-
14589 describe ( 'build()' , ( ) => {
14690 describe ( 'format: value' , ( ) => {
14791 it ( 'builds query from single value' , ( ) => {
@@ -203,40 +147,6 @@ describe('MatcherPatternQueryParam', () => {
203147 expect ( matcher . build ( { tags : [ 'vue' ] } ) ) . toEqual ( { tag : [ 'vue' ] } )
204148 } )
205149 } )
206-
207- describe ( 'format: both' , ( ) => {
208- it ( 'builds query from single value' , ( ) => {
209- const matcher = new MatcherPatternQueryParam (
210- 'data' ,
211- 'value' ,
212- 'both' ,
213- PARAM_PARSER_DEFAULTS
214- )
215- expect ( matcher . build ( { data : 'single' } ) ) . toEqual ( { value : 'single' } )
216- } )
217-
218- it ( 'builds query from array value' , ( ) => {
219- const matcher = new MatcherPatternQueryParam (
220- 'data' ,
221- 'values' ,
222- 'both' ,
223- PARAM_PARSER_DEFAULTS
224- )
225- expect ( matcher . build ( { data : [ 'a' , 'b' ] } ) ) . toEqual ( {
226- values : [ 'a' , 'b' ] ,
227- } )
228- } )
229-
230- it ( 'builds query from null value' , ( ) => {
231- const matcher = new MatcherPatternQueryParam (
232- 'data' ,
233- 'value' ,
234- 'both' ,
235- PARAM_PARSER_DEFAULTS
236- )
237- expect ( matcher . build ( { data : null } ) ) . toEqual ( { value : null } )
238- } )
239- } )
240150 } )
241151
242152 describe ( 'default values' , ( ) => {
@@ -323,14 +233,27 @@ describe('MatcherPatternQueryParam', () => {
323233 } )
324234
325235 describe ( 'missing query parameters' , ( ) => {
326- it ( 'returns undefined when query param missing with parser and no default' , ( ) => {
236+ it ( 'handles missing query param with default' , ( ) => {
327237 const matcher = new MatcherPatternQueryParam (
328- 'count ' ,
329- 'c ' ,
238+ 'userId ' ,
239+ 'user_id ' ,
330240 'value' ,
331- PARAM_PARSER_INT
241+ PARAM_PARSER_DEFAULTS ,
242+ 'default'
332243 )
333- expect ( matcher . match ( { other : 'value' } ) ) . toEqual ( { count : undefined } )
244+ expect ( matcher . match ( { } ) ) . toEqual ( {
245+ userId : 'default' ,
246+ } )
247+ } )
248+
249+ it ( 'throws if a required param is missing and no default' , ( ) => {
250+ const matcher = new MatcherPatternQueryParam (
251+ 'userId' ,
252+ 'user_id' ,
253+ 'value' ,
254+ PARAM_PARSER_DEFAULTS
255+ )
256+ expect ( ( ) => matcher . match ( { } ) ) . toThrow ( MatchMiss )
334257 } )
335258
336259 it ( 'uses default when query param missing' , ( ) => {
@@ -419,14 +342,15 @@ describe('MatcherPatternQueryParam', () => {
419342 'test' ,
420343 'test_param' ,
421344 'value' ,
422- { }
345+ { } ,
346+ 'default'
423347 )
424348 // Should use PARAM_PARSER_DEFAULTS.get which returns value ?? null
425349 expect ( matcher . match ( { test_param : 'value' } ) ) . toEqual ( {
426350 test : 'value' ,
427351 } )
428352 expect ( matcher . match ( { test_param : null } ) ) . toEqual ( { test : null } )
429- expect ( matcher . match ( { } ) ) . toEqual ( { test : undefined } )
353+ expect ( matcher . match ( { } ) ) . toEqual ( { test : 'default' } )
430354 } )
431355
432356 it ( 'should handle array format with missing get method' , ( ) => {
@@ -444,22 +368,6 @@ describe('MatcherPatternQueryParam', () => {
444368 test : [ 'single' ] ,
445369 } )
446370 } )
447-
448- it ( 'should handle both format with missing get method' , ( ) => {
449- const matcher = new MatcherPatternQueryParam (
450- 'test' ,
451- 'test_param' ,
452- 'both' ,
453- { }
454- )
455- // Should use PARAM_PARSER_DEFAULTS.get which returns value ?? null
456- expect ( matcher . match ( { test_param : 'value' } ) ) . toEqual ( {
457- test : 'value' ,
458- } )
459- expect ( matcher . match ( { test_param : [ 'a' , 'b' ] } ) ) . toEqual ( {
460- test : [ 'a' , 'b' ] ,
461- } )
462- } )
463371 } )
464372
465373 describe ( 'build' , ( ) => {
@@ -498,22 +406,6 @@ describe('MatcherPatternQueryParam', () => {
498406 test_param : [ '1' , 'true' ] ,
499407 } )
500408 } )
501-
502- it ( 'should handle both format with missing set method' , ( ) => {
503- const matcher = new MatcherPatternQueryParam (
504- 'test' ,
505- 'test_param' ,
506- 'both' ,
507- { }
508- )
509- // Should use PARAM_PARSER_DEFAULTS.set
510- expect ( matcher . build ( { test : 'value' } ) ) . toEqual ( {
511- test_param : 'value' ,
512- } )
513- expect ( matcher . build ( { test : [ 'a' , 'b' ] } ) ) . toEqual ( {
514- test_param : [ 'a' , 'b' ] ,
515- } )
516- } )
517409 } )
518410 } )
519411} )
0 commit comments