@@ -23,7 +23,17 @@ function makeRequestResponse(url, currentVersion = 'free-pro-team@latest') {
2323 req . context . currentVersion = currentVersion
2424 req . context . pages = { }
2525
26- return [ req , new http . ServerResponse ( req ) ]
26+ const res = new http . ServerResponse ( req )
27+ res . status = function ( code ) {
28+ this . _status = code
29+ return {
30+ send : function ( message ) {
31+ this . _message = message
32+ } . bind ( this ) ,
33+ }
34+ }
35+
36+ return [ req , res ]
2737}
2838
2939describe ( 'find page middleware' , ( ) => {
@@ -73,7 +83,6 @@ describe('find page middleware', () => {
7383 } )
7484 expect ( req . context . page ) . toBeInstanceOf ( Page )
7585 } )
76-
7786 test ( 'finds it for non-fpt version URLS' , async ( ) => {
7887 const [ req , res ] = makeRequestResponse ( '/en/page-with-redirects' , 'enterprise-cloud@latest' )
7988 req . context . pages = {
@@ -91,6 +100,27 @@ describe('find page middleware', () => {
91100 expect ( req . context . page ) . toBeInstanceOf ( Page )
92101 } )
93102
103+ test ( "will 404 if the request version doesn't match the page" , async ( ) => {
104+ // The 'versions:' frontmatter on 'page-with-redirects.md' does
105+ // not include ghes. So this'll eventually 404.
106+ const [ req , res ] = makeRequestResponse ( '/en/page-with-redirects' , 'enterprise-server@latest' )
107+ req . context . pages = {
108+ '/en/page-with-redirects' : await Page . init ( {
109+ relativePath : 'page-with-redirects.md' ,
110+ basePath : path . join ( __dirname , '../fixtures' ) ,
111+ languageCode : 'en' ,
112+ } ) ,
113+ }
114+
115+ await findPage ( req , res , ( ) => { } , {
116+ isDev : true ,
117+ contentRoot : path . join ( __dirname , '../fixtures' ) ,
118+ } )
119+ expect ( res . _status ) . toBe ( 404 )
120+ expect ( res . _message ) . toMatch ( '' )
121+ expect ( req . context . page ) . toBeUndefined ( )
122+ } )
123+
94124 test ( 're-reads from disk if in development mode and finds nothing' , async ( ) => {
95125 const [ req , res ] = makeRequestResponse ( '/en/never/heard/of' )
96126
0 commit comments