@@ -120,7 +120,7 @@ describe('resolveRecommended middleware', () => {
120120 {
121121 title : 'Test Article' ,
122122 intro : '<p>Test intro</p>' ,
123- href : '/en/ copilot/tutorials/article' ,
123+ href : '/copilot/tutorials/article' ,
124124 category : [ 'copilot' , 'tutorials' ] ,
125125 } ,
126126 ] )
@@ -195,7 +195,7 @@ describe('resolveRecommended middleware', () => {
195195 {
196196 title : 'Valid Article' ,
197197 intro : '<p>Valid intro</p>' ,
198- href : '/en/ test/valid' ,
198+ href : '/test/valid' ,
199199 category : [ 'test' ] ,
200200 } ,
201201 ] )
@@ -256,10 +256,64 @@ describe('resolveRecommended middleware', () => {
256256 {
257257 title : 'Relative Article' ,
258258 intro : '<p>Relative intro</p>' ,
259- href : '/en/ copilot/relative-article' ,
259+ href : '/copilot/relative-article' , // Updated to clean path
260260 category : [ 'copilot' ] ,
261261 } ,
262262 ] )
263263 expect ( mockNext ) . toHaveBeenCalled ( )
264264 } )
265+
266+ test ( 'returns paths without language or version prefixes' , async ( ) => {
267+ const testPage : Partial < import ( '@/types' ) . Page > = {
268+ mtime : Date . now ( ) ,
269+ title : 'Tutorial Page' ,
270+ rawTitle : 'Tutorial Page' ,
271+ intro : 'Tutorial intro' ,
272+ rawIntro : 'Tutorial intro' ,
273+ relativePath : 'copilot/tutorials/tutorial-page/index.md' ,
274+ fullPath : '/full/path/copilot/tutorials/tutorial-page/index.md' ,
275+ languageCode : 'en' ,
276+ documentType : 'article' ,
277+ markdown : 'Tutorial content' ,
278+ versions : { } ,
279+ applicableVersions : [ 'free-pro-team@latest' ] ,
280+ permalinks : [
281+ {
282+ languageCode : 'en' ,
283+ pageVersion : 'free-pro-team@latest' ,
284+ title : 'Tutorial Page' ,
285+ href : '/en/copilot/tutorials/tutorial-page' ,
286+ hrefWithoutLanguage : '/copilot/tutorials/tutorial-page' ,
287+ } ,
288+ ] ,
289+ renderProp : vi . fn ( ) . mockResolvedValue ( 'rendered' ) ,
290+ renderTitle : vi . fn ( ) . mockResolvedValue ( 'Tutorial Page' ) ,
291+ render : vi . fn ( ) . mockResolvedValue ( 'rendered content' ) ,
292+ buildRedirects : vi . fn ( ) . mockReturnValue ( { } ) ,
293+ }
294+
295+ mockFindPage . mockReturnValue ( testPage as any )
296+
297+ const req = createMockRequest ( { rawRecommended : [ '/copilot/tutorials/tutorial-page' ] } )
298+
299+ await resolveRecommended ( req , mockRes , mockNext )
300+
301+ expect ( mockFindPage ) . toHaveBeenCalledWith (
302+ '/en/copilot/tutorials/tutorial-page' ,
303+ req . context ! . pages ,
304+ req . context ! . redirects ,
305+ )
306+
307+ // Verify that the href is a clean path without language/version, that gets
308+ // added on the React side.
309+ expect ( ( req . context ! . page as any ) . recommended ) . toEqual ( [
310+ {
311+ title : 'Tutorial Page' ,
312+ intro : '<p>Tutorial intro</p>' ,
313+ href : '/copilot/tutorials/tutorial-page' ,
314+ category : [ 'copilot' , 'tutorials' , 'tutorial-page' ] ,
315+ } ,
316+ ] )
317+ expect ( mockNext ) . toHaveBeenCalled ( )
318+ } )
265319} )
0 commit comments