@@ -6,6 +6,10 @@ import {
66 validateGitHubUsername ,
77} from './validations' ;
88
9+ function parse ( params : Record < string , string > ) {
10+ return streakParamsSchema . parse ( { user : 'octocat' , ...params } ) ;
11+ }
12+
913describe ( 'streakParamsSchema — grace fallback behavior' , ( ) => {
1014 it ( 'accepts "0" as a valid grace value' , ( ) => {
1115 expect ( parse ( { grace : '0' } ) . grace ) . toBe ( 0 ) ;
@@ -43,6 +47,10 @@ describe('streakParamsSchema — grace fallback behavior', () => {
4347 it ( 'defaults to 1 when grace is omitted' , ( ) => {
4448 expect ( parse ( { } ) . grace ) . toBe ( 1 ) ;
4549 } ) ;
50+
51+ it ( 'defaults to 1 when grace is empty string' , ( ) => {
52+ expect ( parse ( { grace : '' } ) . grace ) . toBe ( 1 ) ;
53+ } ) ;
4654} ) ;
4755
4856describe ( 'validateGitHubUsername' , ( ) => {
@@ -479,49 +487,144 @@ describe('streakParamsSchema', () => {
479487 } ) ;
480488} ) ;
481489
482- it ( 'should succeed when username contains hyphens' , ( ) => {
483- const result = streakParamsSchema . safeParse ( {
484- user : 'valid-user' ,
490+ describe ( 'streakParamsSchema — user hyphen validation' , ( ) => {
491+ it ( 'should succeed when username contains hyphens' , ( ) => {
492+ const result = streakParamsSchema . safeParse ( {
493+ user : 'valid-user' ,
494+ } ) ;
495+
496+ expect ( result . success ) . toBe ( true ) ;
485497 } ) ;
486498
487- expect ( result . success ) . toBe ( true ) ;
488- } ) ;
499+ it ( 'should succeed when username contains multiple hyphens' , ( ) => {
500+ const result = streakParamsSchema . safeParse ( {
501+ user : 'valid-user-name-123' ,
502+ } ) ;
489503
490- it ( 'should succeed when username contains multiple hyphens' , ( ) => {
491- const result = streakParamsSchema . safeParse ( {
492- user : 'valid-user-name-123' ,
504+ expect ( result . success ) . toBe ( true ) ;
493505 } ) ;
494506
495- expect ( result . success ) . toBe ( true ) ;
496- } ) ;
507+ it ( 'should fail when username ends with hyphen' , ( ) => {
508+ const result = streakParamsSchema . safeParse ( {
509+ user : 'user-' ,
510+ } ) ;
497511
498- it ( 'should fail when username ends with hyphen' , ( ) => {
499- const result = streakParamsSchema . safeParse ( {
500- user : 'user-' ,
512+ expect ( result . success ) . toBe ( false ) ;
501513 } ) ;
502514
503- expect ( result . success ) . toBe ( false ) ;
504- } ) ;
515+ it ( 'should fail when username starts with hyphen' , ( ) => {
516+ const result = streakParamsSchema . safeParse ( {
517+ user : '-user' ,
518+ } ) ;
505519
506- it ( 'should fail when username starts with hyphen' , ( ) => {
507- const result = streakParamsSchema . safeParse ( {
508- user : '-user' ,
520+ expect ( result . success ) . toBe ( false ) ;
509521 } ) ;
510522
511- expect ( result . success ) . toBe ( false ) ;
523+ it ( 'should fail when username contains consecutive hyphens' , ( ) => {
524+ const result = streakParamsSchema . safeParse ( {
525+ user : 'user--name' ,
526+ } ) ;
527+
528+ expect ( result . success ) . toBe ( false ) ;
529+ } ) ;
512530} ) ;
513531
514- it ( 'should fail when username contains consecutive hyphens' , ( ) => {
515- const result = streakParamsSchema . safeParse ( {
516- user : 'user--name' ,
532+ describe ( 'streakParamsSchema — grace validation' , ( ) => {
533+ it ( 'accepts grace=0' , ( ) => {
534+ const result = streakParamsSchema . safeParse ( {
535+ user : 'octocat' ,
536+ grace : '0' ,
537+ } ) ;
538+
539+ expect ( result . success ) . toBe ( true ) ;
540+ if ( result . success ) {
541+ expect ( result . data . grace ) . toBe ( 0 ) ;
542+ }
517543 } ) ;
518544
519- expect ( result . success ) . toBe ( false ) ;
520- } ) ;
545+ it ( 'accepts grace=7' , ( ) => {
546+ const result = streakParamsSchema . safeParse ( {
547+ user : 'octocat' ,
548+ grace : '7' ,
549+ } ) ;
521550
522- function parse ( params : Record < string , string > ) {
523- return streakParamsSchema . parse ( { user : 'octocat' , ...params } ) ;
524- }
551+ expect ( result . success ) . toBe ( true ) ;
552+ if ( result . success ) {
553+ expect ( result . data . grace ) . toBe ( 7 ) ;
554+ }
555+ } ) ;
556+
557+ it ( 'accepts grace=3' , ( ) => {
558+ const result = streakParamsSchema . safeParse ( {
559+ user : 'octocat' ,
560+ grace : '3' ,
561+ } ) ;
562+
563+ expect ( result . success ) . toBe ( true ) ;
564+ if ( result . success ) {
565+ expect ( result . data . grace ) . toBe ( 3 ) ;
566+ }
567+ } ) ;
568+
569+ it ( 'defaults to 1 when grace is omitted' , ( ) => {
570+ const result = streakParamsSchema . safeParse ( {
571+ user : 'octocat' ,
572+ } ) ;
573+
574+ expect ( result . success ) . toBe ( true ) ;
575+ if ( result . success ) {
576+ expect ( result . data . grace ) . toBe ( 1 ) ;
577+ }
578+ } ) ;
579+
580+ it ( 'rejects grace=-1' , ( ) => {
581+ const result = streakParamsSchema . safeParse ( {
582+ user : 'octocat' ,
583+ grace : '-1' ,
584+ } ) ;
585+
586+ expect ( result . success ) . toBe ( false ) ;
587+ if ( ! result . success ) {
588+ expect ( result . error . issues [ 0 ] ?. message ) . toBe ( 'grace must be an integer between 0 and 7' ) ;
589+ }
590+ } ) ;
591+
592+ it ( 'rejects grace=8 (exceeds max)' , ( ) => {
593+ const result = streakParamsSchema . safeParse ( {
594+ user : 'octocat' ,
595+ grace : '8' ,
596+ } ) ;
597+
598+ expect ( result . success ) . toBe ( false ) ;
599+ if ( ! result . success ) {
600+ expect ( result . error . issues [ 0 ] ?. message ) . toBe ( 'grace must be an integer between 0 and 7' ) ;
601+ }
602+ } ) ;
603+
604+ it ( 'rejects non-numeric grace value' , ( ) => {
605+ const result = streakParamsSchema . safeParse ( {
606+ user : 'octocat' ,
607+ grace : 'abc' ,
608+ } ) ;
609+
610+ expect ( result . success ) . toBe ( false ) ;
611+ if ( ! result . success ) {
612+ expect ( result . error . issues [ 0 ] ?. message ) . toBe ( 'grace must be an integer between 0 and 7' ) ;
613+ }
614+ } ) ;
615+
616+ it ( 'rejects float grace value' , ( ) => {
617+ const result = streakParamsSchema . safeParse ( {
618+ user : 'octocat' ,
619+ grace : '5.5' ,
620+ } ) ;
621+
622+ expect ( result . success ) . toBe ( false ) ;
623+ if ( ! result . success ) {
624+ expect ( result . error . issues [ 0 ] ?. message ) . toBe ( 'grace must be an integer between 0 and 7' ) ;
625+ }
626+ } ) ;
627+ } ) ;
525628
526629describe ( 'streakParamsSchema — scale fallback behavior' , ( ) => {
527630 it ( 'accepts "log" as a valid scale value' , ( ) => {
0 commit comments