File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -62,6 +62,12 @@ describe('Redirect Tests', () => {
6262 expect ( res . headers . location ) . toBe ( '/api/pagelist/en/free-pro-team@latest' )
6363 } )
6464
65+ test ( 'redirects a plan name without a version to English' , async ( ) => {
66+ const res = await get ( '/api/pagelist/free-pro-team' )
67+ expect ( res . statusCode ) . toBe ( 308 )
68+ expect ( res . headers . location ) . toBe ( '/api/pagelist/en/free-pro-team@latest' )
69+ } )
70+
6571 test ( 'should redirect to /pagelist/en/free-pro-team@lateset when URL does not include version' , async ( ) => {
6672 const res = await get ( '/api/pagelist/en' )
6773 expect ( res . statusCode ) . toBe ( 308 )
Original file line number Diff line number Diff line change @@ -16,7 +16,7 @@ export const getEnterpriseVersionNumber = /enterprise\/(\d+\.\d+(?:\.340)?)/
1616export const removeEnterpriseVersion = / ( e n t e r p r i s e \/ ) \d + \. \d + \/ /
1717export const guides = / g u i d e s \/ /
1818export const hasLanguageCode = / ^ \/ [ a - z ] { 2 } ( \/ | $ | \? ) /
19- export const getLanguageCode = / ^ \/ ( [ a - z ] { 2 } ) /
19+ export const getLanguageCode = / ^ \/ ( [ a - z ] { 2 } ) (? = \/ | $ | \? ) /
2020export const trailingSlash = / ^ ( .+ ?) \/ + ?$ /
2121export const searchPath = / \/ s e a r c h (?: \/ ) ? ( \? ) /
2222export const ymd = / ^ \d { 4 } - \d { 2 } - \d { 2 } $ /
Original file line number Diff line number Diff line change 11import { describe , expect , test } from 'vitest'
22
3- import { getProductStringFromPath } from '@/frame/lib/path-utils'
3+ import { getLangFromPath , getProductStringFromPath } from '@/frame/lib/path-utils'
4+
5+ describe ( 'getLangFromPath' , ( ) => {
6+ test ( 'returns null when the first segment is not a language code' , ( ) => {
7+ expect ( getLangFromPath ( '/free-pro-team' ) ) . toBeNull ( )
8+ expect ( getLangFromPath ( '/free-pro-team@latest' ) ) . toBeNull ( )
9+ expect ( getLangFromPath ( '/enterprise-cloud' ) ) . toBeNull ( )
10+ expect ( getLangFromPath ( '/enterprise-server' ) ) . toBeNull ( )
11+ expect ( getLangFromPath ( '/github/foo' ) ) . toBeNull ( )
12+ } )
13+
14+ test ( 'returns the language code from the first segment' , ( ) => {
15+ expect ( getLangFromPath ( '/en' ) ) . toBe ( 'en' )
16+ expect ( getLangFromPath ( '/fr' ) ) . toBe ( 'fr' )
17+ expect ( getLangFromPath ( '/en?x=1' ) ) . toBe ( 'en' )
18+ expect ( getLangFromPath ( '/fr/free-pro-team' ) ) . toBe ( 'fr' )
19+ expect ( getLangFromPath ( '/fr/free-pro-team@latest' ) ) . toBe ( 'fr' )
20+ expect ( getLangFromPath ( '/ja/enterprise-server@3.19' ) ) . toBe ( 'ja' )
21+ } )
22+ } )
423
524describe ( 'getProductStringFromPath' , ( ) => {
625 test ( 'returns "homepage" for root paths' , ( ) => {
You can’t perform that action at this time.
0 commit comments