@@ -12,6 +12,10 @@ vi.mock('express', () => ({
1212 } ,
1313} ) ) ;
1414
15+ vi . mock ( 'express-rate-limit' , ( ) => ( {
16+ default : vi . fn ( ( ) => 'rate-limit-middleware' ) ,
17+ } ) ) ;
18+
1519vi . mock ( '../runtime/paths' , ( ) => ( {
1620 resolveUiDirectory : vi . fn ( ( ) => '/app/ui' ) ,
1721} ) ) ;
@@ -27,12 +31,27 @@ describe('UI Router', () => {
2731 const router = uiRouter . init ( ) ;
2832 expect ( router ) . toBeDefined ( ) ;
2933 expect ( router . use ) . toHaveBeenCalledWith ( 'static-middleware' ) ;
30- expect ( router . get ) . toHaveBeenCalledWith ( '/{*path}' , expect . any ( Function ) ) ;
34+ expect ( router . get ) . toHaveBeenCalledWith (
35+ '/{*path}' ,
36+ 'rate-limit-middleware' ,
37+ expect . any ( Function ) ,
38+ ) ;
39+ } ) ;
40+
41+ test ( 'should apply rate limiting only to SPA document fallback requests' , ( ) => {
42+ uiRouter . init ( ) ;
43+
44+ expect ( mockRouter . use ) . not . toHaveBeenCalledWith ( 'rate-limit-middleware' ) ;
45+ expect ( mockRouter . get ) . toHaveBeenCalledWith (
46+ '/{*path}' ,
47+ 'rate-limit-middleware' ,
48+ expect . any ( Function ) ,
49+ ) ;
3150 } ) ;
3251
3352 test ( 'catch-all should send index.html' , ( ) => {
3453 uiRouter . init ( ) ;
35- const catchAllHandler = mockRouter . get . mock . calls . find ( ( c ) => c [ 0 ] === '/{*path}' ) [ 1 ] ;
54+ const catchAllHandler = mockRouter . get . mock . calls . find ( ( c ) => c [ 0 ] === '/{*path}' ) [ 2 ] ;
3655
3756 const res = { sendFile : vi . fn ( ) } ;
3857 catchAllHandler ( { } , res ) ;
0 commit comments