File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -122,6 +122,24 @@ describe('POST /api/track-user', () => {
122122 expect ( data . bypassed ) . toBeUndefined ( ) ;
123123 } ) ;
124124
125+ it ( 'normalizes purely uppercase usernames to lowercase' , async ( ) => {
126+ const response = await POST ( makeRequest ( { username : 'GITHUB' } ) ) ;
127+
128+ expect ( dbConnect ) . toHaveBeenCalled ( ) ;
129+
130+ expect ( User . updateOne ) . toHaveBeenCalledWith (
131+ { username : 'github' } ,
132+ { $setOnInsert : { username : 'github' } } ,
133+ { upsert : true }
134+ ) ;
135+
136+ expect ( response . status ) . toBe ( 200 ) ;
137+
138+ const data = await response . json ( ) ;
139+
140+ expect ( data . success ) . toBe ( true ) ;
141+ } ) ;
142+
125143 it ( 'returns 500 when database connection fails' , async ( ) => {
126144 const consoleErrorSpy = vi . spyOn ( console , 'error' ) . mockImplementation ( ( ) => { } ) ;
127145 vi . mocked ( dbConnect ) . mockRejectedValueOnce ( new Error ( 'DB Down' ) ) ;
You can’t perform that action at this time.
0 commit comments