File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import { describe , expect , it } from 'vitest' ;
2+ import { githubParamsSchema } from './validations' ;
3+
4+ describe ( 'githubParamsSchema' , ( ) => {
5+ it ( 'should pass when username is valid' , ( ) => {
6+ const result = githubParamsSchema . safeParse ( {
7+ username : 'octocat' ,
8+ } ) ;
9+
10+ expect ( result . success ) . toBe ( true ) ;
11+ } ) ;
12+
13+ it ( 'should fail when username is omitted' , ( ) => {
14+ const result = githubParamsSchema . safeParse ( { } ) ;
15+
16+ expect ( result . success ) . toBe ( false ) ;
17+ if ( ! result . success ) {
18+ expect ( result . error . issues [ 0 ] ?. message ) . toBe ( 'Missing "username" parameter' ) ;
19+ }
20+ } ) ;
21+
22+ it ( 'should fail when username is empty' , ( ) => {
23+ const result = githubParamsSchema . safeParse ( {
24+ username : '' ,
25+ } ) ;
26+
27+ expect ( result . success ) . toBe ( false ) ;
28+ } ) ;
29+
30+ it ( 'should transform refresh true string to boolean true' , ( ) => {
31+ const result = githubParamsSchema . safeParse ( {
32+ username : 'octocat' ,
33+ refresh : 'true' ,
34+ } ) ;
35+
36+ expect ( result . success ) . toBe ( true ) ;
37+ if ( result . success ) {
38+ expect ( result . data . refresh ) . toBe ( true ) ;
39+ }
40+ } ) ;
41+
42+ it ( 'should transform refresh false string to boolean false' , ( ) => {
43+ const result = githubParamsSchema . safeParse ( {
44+ username : 'octocat' ,
45+ refresh : 'false' ,
46+ } ) ;
47+
48+ expect ( result . success ) . toBe ( true ) ;
49+ if ( result . success ) {
50+ expect ( result . data . refresh ) . toBe ( false ) ;
51+ }
52+ } ) ;
53+ } ) ;
You can’t perform that action at this time.
0 commit comments