@@ -10,8 +10,8 @@ vi.mock('@/languages/lib/languages-server', async () => {
1010 return { default : languages }
1111} )
1212
13- function run ( path : string ) {
14- const req = { path } as ExtendedRequest
13+ function run ( url : string ) {
14+ const req = { url , path : url . split ( '?' ) [ 0 ] } as ExtendedRequest
1515 const res = { hasHeader : ( ) => false , set : vi . fn ( ) , safeRedirect : vi . fn ( ) }
1616 const next = vi . fn ( )
1717 languageCodeRedirects ( req , res as unknown as Response , next as NextFunction )
@@ -22,21 +22,28 @@ describe('languageCodeRedirects', () => {
2222 test . each ( [
2323 [ '/jp' , '/ja' ] ,
2424 [ '/cn/get-started' , '/zh/get-started' ] ,
25+ [ '/cn/rest/repos' , '/zh/rest/repos' ] ,
2526 [ '/zh-CN' , '/zh' ] ,
2627 [ '/zh-TW/get-started' , '/zh/get-started' ] ,
2728 [ '/zh-Hans' , '/zh' ] ,
2829 [ '/zh-Hans/get-started' , '/zh/get-started' ] ,
2930 [ '/zh-hant/get-started' , '/zh/get-started' ] ,
3031 [ '/zh-Hans-CN/get-started' , '/zh/get-started' ] ,
32+ [ '/jp/search?query=actions' , '/ja/search?query=actions' ] ,
33+ [ '/cn/rest/repos?apiVersion=2022-11-28' , '/zh/rest/repos?apiVersion=2022-11-28' ] ,
34+ [ '/zh-TW/actions?tool=cli&platform=mac' , '/zh/actions?tool=cli&platform=mac' ] ,
3135 ] ) ( 'redirects %s to %s' , ( from , to ) => {
3236 const { res, next } = run ( from )
3337 expect ( res . safeRedirect ) . toHaveBeenCalledWith ( 301 , to )
3438 expect ( next ) . not . toHaveBeenCalled ( )
3539 } )
3640
37- test . each ( [ '/zh' , '/zh/get-started' , '/en/zh-Hans' ] ) ( 'passes %s through' , ( path ) => {
38- const { res, next } = run ( path )
39- expect ( res . safeRedirect ) . not . toHaveBeenCalled ( )
40- expect ( next ) . toHaveBeenCalled ( )
41- } )
41+ test . each ( [ '/zh' , '/zh/get-started' , '/en/zh-Hans' , '/ja/search?query=jp' ] ) (
42+ 'passes %s through' ,
43+ ( url ) => {
44+ const { res, next } = run ( url )
45+ expect ( res . safeRedirect ) . not . toHaveBeenCalled ( )
46+ expect ( next ) . toHaveBeenCalledOnce ( )
47+ } ,
48+ )
4249} )
0 commit comments